Move old migration code from 'K9' to storage module
This commit is contained in:
parent
fb426b4008
commit
dc93335100
2 changed files with 21 additions and 24 deletions
|
@ -21,8 +21,6 @@ object K9 : EarlyInit {
|
|||
@JvmField
|
||||
val DEVELOPER_MODE = BuildConfig.DEBUG
|
||||
|
||||
private const val VERSION_MIGRATE_OPENPGP_TO_ACCOUNTS = 63
|
||||
|
||||
/**
|
||||
* Name of the [SharedPreferences] file used to store the last known version of the
|
||||
* accounts' databases.
|
||||
|
@ -105,28 +103,6 @@ object K9 : EarlyInit {
|
|||
if (cachedVersion >= LocalStore.getDbVersion()) {
|
||||
setDatabasesUpToDate(false)
|
||||
}
|
||||
|
||||
if (cachedVersion < VERSION_MIGRATE_OPENPGP_TO_ACCOUNTS) {
|
||||
migrateOpenPgpGlobalToAccountSettings()
|
||||
}
|
||||
}
|
||||
|
||||
private fun migrateOpenPgpGlobalToAccountSettings() {
|
||||
val storage = preferences.storage
|
||||
|
||||
val openPgpProvider = storage.getString("openPgpProvider", null)
|
||||
val openPgpSupportSignOnly = storage.getBoolean("openPgpSupportSignOnly", false)
|
||||
|
||||
for (account in preferences.accounts) {
|
||||
account.openPgpProvider = openPgpProvider
|
||||
account.isOpenPgpHideSignOnly = !openPgpSupportSignOnly
|
||||
preferences.saveAccount(account)
|
||||
}
|
||||
|
||||
preferences.createStorageEditor()
|
||||
.remove("openPgpProvider")
|
||||
.remove("openPgpSupportSignOnly")
|
||||
.commit()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
|
|
@ -12,6 +12,7 @@ class StorageMigrationTo6(
|
|||
fun performLegacyMigrations() {
|
||||
rewriteKeyguardPrivacy()
|
||||
rewriteTheme()
|
||||
migrateOpenPgpGlobalToAccountSettings()
|
||||
}
|
||||
|
||||
private fun rewriteKeyguardPrivacy() {
|
||||
|
@ -39,6 +40,26 @@ class StorageMigrationTo6(
|
|||
migrationsHelper.writeValue(db, "theme", newTheme.toString())
|
||||
}
|
||||
|
||||
private fun migrateOpenPgpGlobalToAccountSettings() {
|
||||
val accountUuidsListValue = migrationsHelper.readValue(db, "accountUuids")
|
||||
if (accountUuidsListValue == null || accountUuidsListValue.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
val openPgpProvider = migrationsHelper.readValue(db, "openPgpProvider") ?: ""
|
||||
val openPgpSupportSignOnly = migrationsHelper.readValue(db, "openPgpSupportSignOnly")?.toBoolean() ?: false
|
||||
val openPgpHideSignOnly = (!openPgpSupportSignOnly).toString()
|
||||
|
||||
val accountUuids = accountUuidsListValue.split(",")
|
||||
for (accountUuid in accountUuids) {
|
||||
migrationsHelper.writeValue(db, "$accountUuid.openPgpProvider", openPgpProvider)
|
||||
migrationsHelper.writeValue(db, "$accountUuid.openPgpHideSignOnly", openPgpHideSignOnly)
|
||||
}
|
||||
|
||||
migrationsHelper.writeValue(db, "openPgpProvider", null)
|
||||
migrationsHelper.writeValue(db, "openPgpSupportSignOnly", null)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val THEME_ORDINAL_LIGHT = 0
|
||||
private const val THEME_ORDINAL_DARK = 1
|
||||
|
|
Loading…
Reference in a new issue