database bug fix

This commit is contained in:
nuclearfog 2023-12-03 16:29:41 +01:00
parent 31badd586b
commit 01dc245f2d
No known key found for this signature in database
GPG Key ID: 43E45B82006BC9D5
2 changed files with 23 additions and 1 deletions

View File

@ -40,6 +40,7 @@ public class AccountAction extends AsyncExecutor<AccountAction.Param, AccountAct
} else {
settings.setPushEnabled(false);
}
database.resetDatabase();
return new Result(Result.SELECT, param.account);
case Param.REMOVE:

View File

@ -1102,21 +1102,42 @@ public class AppDatabase {
}
/**
* remove database tables except account table
* reset database tables
* re-create database tables and keep all login and web push subscriptions
*/
public void resetDatabase() {
synchronized (adapter) {
// save logins first
List<Account> logins = getLogins();
List<WebPush> webPushs = getWebPushs();
// reset database
adapter.resetDatabase();
// restore saved logins
for (Account login : logins) {
saveLogin(login);
}
// restore web push subscription
for (WebPush webPush : webPushs) {
savePushSubscription(webPush);
}
}
}
/**
* get all web push subscriptions
*/
private List<WebPush> getWebPushs() {
List<WebPush> result = new LinkedList<>();
SQLiteDatabase db = adapter.getDbRead();
Cursor c = db.query(PushTable.TABLE, DatabasePush.COLUMNS, null, null, null, null, null);
if (c.moveToFirst()) {
result.add(new DatabasePush(c));
}
c.close();
return result;
}
/**
* get status information from database
*