-
Notifications
You must be signed in to change notification settings - Fork 906
Feat: forward migration at accounts config(issue #9037) #9070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,3 @@ | ||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||
| * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors | ||||||||||||||||||||||||||
| * SPDX-FileCopyrightText: 2015 ownCloud GmbH | ||||||||||||||||||||||||||
|
|
@@ -6,7 +6,7 @@ | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #pragma once | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #include "account.h" | ||||||||||||||||||||||||||
| #include "accountstate.h" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| namespace OCC { | ||||||||||||||||||||||||||
|
|
@@ -31,6 +31,21 @@ | |||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| Q_ENUM (AccountsRestoreResult); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| enum class AccountsVersion { | ||||||||||||||||||||||||||
| V13 = 13, | ||||||||||||||||||||||||||
| Min = V13, | ||||||||||||||||||||||||||
| Max = V13 | ||||||||||||||||||||||||||
|
Comment on lines
+36
to
+37
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am really not a fan of those special enum values
Suggested change
you no longer can rely on static code checker to see if you handle all existing values
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I too think these enum classes don't have much benefit. A struct could be used better for this. I have 2 issues with this solution:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's shortcuts for more readablity and incapsulation of changes. With new version we need to change values only here, not over every depending logic. For example, in "switch-default" section of migration function. Or in other possible cases with checks.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need special handling for
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really didn't find any notice of versions 1 till 12 in the code. The only thing mentioned is 13. I set it as the first known for the new workflow. |
||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| Q_ENUM (AccountsVersion); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| enum class AccountVersion { | ||||||||||||||||||||||||||
| V13 = 13, | ||||||||||||||||||||||||||
| V14, | ||||||||||||||||||||||||||
| Min = V13, | ||||||||||||||||||||||||||
| Max = V14 | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
Comment on lines
+41
to
+46
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same
Suggested change
|
||||||||||||||||||||||||||
| Q_ENUM (AccountVersion); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| static AccountManager *instance(); | ||||||||||||||||||||||||||
| ~AccountManager() override = default; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -83,6 +98,12 @@ | |||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| static void backwardMigrationSettingsKeys(QStringList *deleteKeys, QStringList *ignoreKeys); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Checks the versions of account groups and each account individually | ||||||||||||||||||||||||||
| * then attempts a soft migration. | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| static void migrateToActualVersion(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public slots: | ||||||||||||||||||||||||||
| /// Saves account data when adding user, when updating e.g. dav user, not including the credentials | ||||||||||||||||||||||||||
| void saveAccount(const OCC::AccountPtr &newAccountData); | ||||||||||||||||||||||||||
|
|
@@ -110,6 +131,9 @@ | |||||||||||||||||||||||||
| void capabilitiesChanged(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||
| static void migrateAccountsSettings(const std::unique_ptr<QSettings> &settings); | ||||||||||||||||||||||||||
| static void migrateAccountSettings(const std::unique_ptr<QSettings> &settings); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // saving and loading Account to settings | ||||||||||||||||||||||||||
| void saveAccountHelper(const AccountPtr &account, QSettings &settings, bool saveCredentials = true); | ||||||||||||||||||||||||||
| AccountPtr loadAccountHelper(QSettings &settings); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,14 +141,6 @@ bool Application::configVersionMigration() | |
| return true; | ||
| } | ||
|
|
||
| // 'Launch on system startup' defaults to true > 3.11.x | ||
| const auto theme = Theme::instance(); | ||
| configFile.setLaunchOnSystemStartup(configFile.launchOnSystemStartup()); | ||
| Utility::setLaunchOnStartup(theme->appName(), theme->appNameGUI(), configFile.launchOnSystemStartup()); | ||
|
|
||
| // default is now off to displaying dialog warning user of too many files deletion | ||
| configFile.setPromptDeleteFiles(false); | ||
|
|
||
| // back up all old config files | ||
| QStringList backupFilesList; | ||
| QDir configDir(configFile.configPath()); | ||
|
|
@@ -190,15 +182,27 @@ bool Application::configVersionMigration() | |
| } | ||
| } | ||
|
|
||
| if (!deleteKeys.isEmpty()) { | ||
| auto settings = ConfigFile::settingsWithGroup("foo"); | ||
| settings->endGroup(); | ||
| if (downgrading) { | ||
| // 'Launch on system startup' defaults to true > 3.11.x | ||
| const auto theme = Theme::instance(); | ||
| configFile.setLaunchOnSystemStartup(configFile.launchOnSystemStartup()); | ||
| Utility::setLaunchOnStartup(theme->appName(), theme->appNameGUI(), configFile.launchOnSystemStartup()); | ||
|
|
||
| // default is now off to displaying dialog warning user of too many files deletion | ||
| configFile.setPromptDeleteFiles(false); | ||
|
|
||
| // Wipe confusing keys from the future, ignore the others | ||
| for (const auto &badKey : std::as_const(deleteKeys)) { | ||
| settings->remove(badKey); | ||
| qCInfo(lcApplication) << "Migration: removed" << badKey << "key from settings."; | ||
| if (!deleteKeys.isEmpty()) { | ||
| auto settings = ConfigFile::settingsWithGroup("foo"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you mean by
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't my code. I tried not to change the existing logic.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I missed that this was copied over from existing code
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original function(with the common name |
||
| settings->endGroup(); | ||
|
|
||
| // Wipe confusing keys from the future, ignore the others | ||
| for (const auto &badKey : std::as_const(deleteKeys)) { | ||
| settings->remove(badKey); | ||
| qCInfo(lcApplication) << "Migration: removed" << badKey << "key from settings."; | ||
| } | ||
| } | ||
| } else { // upgrading | ||
| AccountManager::migrateToActualVersion(); | ||
| } | ||
|
|
||
| configFile.setClientVersionString(MIRALL_VERSION_STRING); | ||
|
|
@@ -323,6 +327,8 @@ Application::Application(int &argc, char **argv) | |
| // only copy the settings and check what should be skipped | ||
| if (!configVersionMigration()) { | ||
| qCWarning(lcApplication) << "Config version migration was not possible."; | ||
| } else { | ||
| AccountManager::instance()->save(); | ||
| } | ||
|
|
||
| ConfigFile cfg; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,36 +198,40 @@ | |
|
|
||
| void NetworkSettings::saveBWLimitSettings() | ||
| { | ||
| using NetworkTransferLimitSetting = Account::AccountNetworkTransferLimitSetting; | ||
|
|
||
| const auto downloadLimit = _ui->downloadSpinBox->value(); | ||
| const auto uploadLimit = _ui->uploadSpinBox->value(); | ||
|
|
||
| auto useDownloadLimit = 0; | ||
| auto useUploadLimit = 0; | ||
| auto useDownloadLimit = NetworkTransferLimitSetting::NoLimit; | ||
| auto useUploadLimit = NetworkTransferLimitSetting::NoLimit; | ||
|
|
||
| if (_ui->downloadLimitRadioButton->isChecked()) { | ||
| useDownloadLimit = 1; | ||
| useDownloadLimit = NetworkTransferLimitSetting::ManualLimit; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice touch to use the enum values here! |
||
| } else if (_ui->noDownloadLimitRadioButton->isChecked()) { | ||
| useDownloadLimit = 0; | ||
| useDownloadLimit = NetworkTransferLimitSetting::NoLimit; | ||
| } else if (_ui->autoDownloadLimitRadioButton->isChecked()) { | ||
| useDownloadLimit = -1; | ||
| useDownloadLimit = NetworkTransferLimitSetting::AutoLimit; | ||
| } else if (_account) { | ||
| useDownloadLimit = -2; | ||
| // Legacy global. See Account::AccountNetworkTransferLimitSetting::LegacyGlobalLimit | ||
| useDownloadLimit = NetworkTransferLimitSetting::NoLimit; | ||
| } | ||
|
|
||
| if (_ui->uploadLimitRadioButton->isChecked()) { | ||
| useUploadLimit = 1; | ||
| useUploadLimit = NetworkTransferLimitSetting::ManualLimit; | ||
| } else if (_ui->noUploadLimitRadioButton->isChecked()) { | ||
| useUploadLimit = 0; | ||
| useUploadLimit = NetworkTransferLimitSetting::NoLimit; | ||
| } else if (_ui->autoUploadLimitRadioButton->isChecked()) { | ||
| useUploadLimit = -1; | ||
| useUploadLimit = NetworkTransferLimitSetting::AutoLimit; | ||
| } else if (_account) { | ||
| useUploadLimit = -2; | ||
| // Legacy global. See Account::AccountNetworkTransferLimitSetting::LegacyGlobalLimit | ||
| useUploadLimit = NetworkTransferLimitSetting::NoLimit; | ||
| } | ||
|
|
||
| if (_account) { | ||
| _account->setDownloadLimitSetting(static_cast<Account::AccountNetworkTransferLimitSetting>(useDownloadLimit)); | ||
| _account->setDownloadLimitSetting(useDownloadLimit); | ||
| _account->setDownloadLimit(downloadLimit); | ||
| _account->setUploadLimitSetting(static_cast<Account::AccountNetworkTransferLimitSetting>(useUploadLimit)); | ||
| _account->setUploadLimitSetting(useUploadLimit); | ||
| _account->setUploadLimit(uploadLimit); | ||
| AccountManager::instance()->saveAccount(_account); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given this method is now empty, I fail to see the point of creating it
sounds way too much complicated
current design is that the current version is supposed to find out from past settings the config keys it knows about and can migrate
what are you trying to achieve ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just code for future usability. If a new version appears, it will just be necessary to add its own “case” section.