Skip to content

Commit 2a21520

Browse files
committed
refactor: rename Migration class members.
Signed-off-by: Camila Ayres <hello@camilasan.com>
1 parent 3e9c761 commit 2a21520

6 files changed

Lines changed: 63 additions & 75 deletions

File tree

src/gui/accountmanager.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,18 @@ bool AccountManager::restoreFromLegacySettings()
201201
auto wasLegacyImportDialogDisplayed = false;
202202
QStringList selectedAccountIds;
203203
Migration migration;
204-
if (const auto legacyData = migration.legacyData(); !legacyData.configFile.isEmpty()) {
204+
if (const auto legacyData = migration.legacyData(); !legacyData.isNull()) {
205205

206206
const auto displayLegacyImportDialog = Theme::instance()->displayLegacyImportDialog();
207207

208-
const auto configFile = legacyData.configFile;
209-
auto oCSettings = std::move(legacyData.settings);
208+
auto oCSettings = std::move(legacyData);
210209

211210
oCSettings->beginGroup(QLatin1String(accountsC));
212211
const auto childGroups = oCSettings->childGroups();
213212
const auto accountsListSize = childGroups.size();
214213
oCSettings->endGroup(); // accountsC
215214

216-
qCInfo(lcAccountManager) << "Migrate: checking old config " << configFile;
215+
qCInfo(lcAccountManager) << "Migrate: checking old config";
217216
if (!forceLegacyImport() && displayLegacyImportDialog && accountsListSize > 0) {
218217
wasLegacyImportDialogDisplayed = true;
219218
if (childGroups.size() == 1) {
@@ -300,7 +299,7 @@ bool AccountManager::restoreFromLegacySettings()
300299
configFile.setDownloadLimit(settings->value(ConfigFile::downloadLimitC, configFile.downloadLimit()).toInt());
301300

302301
// Try to load the single account.
303-
migration.setMigrationPhase(Migration::MigrationPhase::SetupUsers);
302+
migration.setPhase(Migration::Phase::SetupUsers);
304303
if (!settings->childKeys().isEmpty()) {
305304
settings->beginGroup(accountsC);
306305
const auto childGroups = selectedAccountIds.isEmpty() ? settings->childGroups() : selectedAccountIds;

src/gui/accountstate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ void AccountState::checkConnectivity()
301301
Migration migration;
302302
const auto shouldTryUnbrandedToBrandedMigration = migration.shouldTryUnbrandedToBrandedMigration();
303303
qCDebug(lcAccountState) << "shouldTryUnbrandedToBrandedMigration?" << shouldTryUnbrandedToBrandedMigration;
304-
qCDebug(lcAccountState) << "migrationPhase?" << migration.migrationPhase();
304+
qCDebug(lcAccountState) << "migration Phase?" << migration.phase();
305305
const auto appName = shouldTryUnbrandedToBrandedMigration ? configFile.unbrandedAppName : "";
306306
account()->credentials()->fetchFromKeychain(appName);
307307
return;
@@ -502,7 +502,7 @@ void AccountState::slotCredentialsFetched(AbstractCredentials *)
502502
ConfigFile configFile;
503503
Migration migration;
504504
if (migration.isInProgress()) {
505-
migration.setMigrationPhase(Migration::MigrationPhase::Done);
505+
migration.setPhase(Migration::Phase::Done);
506506
}
507507
checkConnectivity();
508508
}

src/gui/application.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ bool Application::configVersionMigration()
126126
const auto shouldTryToMigrate = migration.shouldTryToMigrate();
127127
if (!shouldTryToMigrate) {
128128
qCInfo(lcApplication) << "This is not an upgrade/downgrade/migration. Proceed to read current application config file.";
129-
migration.setMigrationPhase(Migration::MigrationPhase::Done);
129+
migration.setPhase(Migration::Phase::Done);
130130
return false;
131131
}
132132

133-
migration.setMigrationPhase(Migration::MigrationPhase::SetupConfigFile);
133+
migration.setPhase(Migration::Phase::SetupConfigFile);
134134
QStringList deleteKeys, ignoreKeys;
135135
AccountManager::backwardMigrationSettingsKeys(&deleteKeys, &ignoreKeys);
136136
FolderMan::backwardMigrationSettingsKeys(&deleteKeys, &ignoreKeys);
@@ -480,17 +480,17 @@ void Application::setupAccountsAndFolders()
480480
_folderManager.reset(new FolderMan);
481481
ConfigFile configFile;
482482
Migration migration;
483-
migration.setMigrationPhase(Migration::MigrationPhase::SetupUsers);
483+
migration.setPhase(Migration::Phase::SetupUsers);
484484
const auto accountsRestoreResult = restoreLegacyAccount();
485485
if (accountsRestoreResult == AccountManager::AccountsNotFound || accountsRestoreResult == AccountManager::AccountsRestoreFailure) {
486486
qCWarning(lcApplication) << "Migration result: " << accountsRestoreResult;
487487
qCDebug(lcApplication) << "is migration disabled?" << DISABLE_ACCOUNT_MIGRATION;
488488
qCWarning(lcApplication) << "No accounts were migrated, prompting user to set up accounts and folders from scratch.";
489-
migration.setMigrationPhase(Migration::MigrationPhase::Done);
489+
migration.setPhase(Migration::Phase::Done);
490490
return;
491491
}
492492

493-
migration.setMigrationPhase(Migration::MigrationPhase::SetupFolders);
493+
migration.setPhase(Migration::Phase::SetupFolders);
494494
const auto foldersListSize = FolderMan::instance()->setupFolders();
495495
FolderMan::instance()->setSyncEnabled(true);
496496

src/libsync/settings/migration.cpp

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ namespace OCC {
2727

2828
Q_LOGGING_CATEGORY(lcMigration, "nextcloud.settings.migration", QtInfoMsg)
2929

30-
Migration::MigrationPhase Migration::_migrationPhase = MigrationPhase::NotStarted;;
31-
Migration::MigrationType Migration::_migrationType = MigrationType::UnbrandedToUnbranded;
32-
Migration::VersionChangeType Migration::_versionChangeType = VersionChangeType::NoVersionChange;
30+
Migration::Phase Migration::_phase = Phase::NotStarted;;
31+
Migration::BrandingType Migration::_brandingType = BrandingType::UnbrandedToUnbranded;
32+
Migration::UpgradeType Migration::_upgradeType = UpgradeType::NoChange;
3333
QString Migration::_discoveredLegacyConfigPath = {};
34-
Migration::LegacyData Migration::_configSettings = {};
34+
Migration::LegacyData Migration::_legacyData = {};
3535

3636
QVersionNumber Migration::currentVersion() const
3737
{
@@ -48,77 +48,77 @@ QVersionNumber Migration::configVersion() const
4848
return QVersionNumber::fromString(ConfigFile().clientVersionString());
4949
}
5050

51-
void Migration::setMigrationPhase(const MigrationPhase phase)
51+
void Migration::setPhase(const Phase phase)
5252
{
5353
// do not rollback
54-
if (phase > _migrationPhase) {
55-
_migrationPhase = phase;
54+
if (phase > _phase) {
55+
_phase = phase;
5656
}
5757
}
5858

59-
Migration::MigrationPhase Migration::migrationPhase() const
59+
Migration::Phase Migration::phase() const
6060
{
61-
return _migrationPhase;
61+
return _phase;
6262
}
6363

64-
void Migration::setMigrationType(const MigrationType type)
64+
void Migration::setBrandingType(const BrandingType type)
6565
{
66-
_migrationType = type;
66+
_brandingType = type;
6767
}
6868

69-
Migration::MigrationType Migration::migrationType() const
69+
Migration::BrandingType Migration::brandingType() const
7070
{
71-
return _migrationType;
71+
return _brandingType;
7272
}
7373

74-
Migration::VersionChangeType Migration::versionChangeType() const
74+
Migration::UpgradeType Migration::upgradeType() const
7575
{
76-
return _versionChangeType;
76+
return _upgradeType;
7777
}
7878

79-
void Migration::setVersionChangeType(const VersionChangeType type)
79+
void Migration::setUpgradeType(const UpgradeType type)
8080
{
81-
_versionChangeType = type;
81+
_upgradeType = type;
8282
}
8383

8484
bool Migration::isUpgrade()
8585
{
8686
const auto isUpgrade = currentVersion() > previousVersion();
8787
if (isUpgrade) {
88-
setVersionChangeType(VersionChangeType::Upgrade);
88+
setUpgradeType(UpgradeType::Upgrade);
8989
}
90-
return versionChangeType() == VersionChangeType::Upgrade;
90+
return _upgradeType == UpgradeType::Upgrade;
9191
}
9292

9393
bool Migration::isDowngrade()
9494
{
9595
const auto isDowngrade = previousVersion() > currentVersion();
9696
if (isDowngrade) {
97-
setVersionChangeType(VersionChangeType::Downgrade);
97+
setUpgradeType(UpgradeType::Downgrade);
9898
}
99-
return versionChangeType() == VersionChangeType::Downgrade;
99+
return _upgradeType == UpgradeType::Downgrade;
100100
}
101101

102102
bool Migration::versionChanged()
103103
{
104104
return isUpgrade() || isDowngrade();
105105
}
106106

107-
bool Migration::shouldTryUnbrandedToBrandedMigration() const
107+
bool Migration::shouldTryUnbrandedToBrandedMigration()
108108
{
109-
const auto isUnbrandedToBranded = migrationPhase() == Migration::MigrationPhase::SetupFolders
109+
const auto isUnbrandedToBranded = phase() == Migration::Phase::SetupFolders
110110
&& Theme::instance()->appName() != ConfigFile::unbrandedAppName
111111
&& !_discoveredLegacyConfigPath.isEmpty();
112112

113113
if (isUnbrandedToBranded) {
114-
Migration().setMigrationType(MigrationType::UnbrandedToBranded);
114+
setBrandingType(BrandingType::UnbrandedToBranded);
115115
}
116-
return migrationType() == MigrationType::UnbrandedToBranded;
116+
return _brandingType == BrandingType::UnbrandedToBranded;
117117
}
118118

119119
bool Migration::isUnbrandedToBrandedMigration() const
120120
{
121-
return isInProgress() && migrationType() == MigrationType::UnbrandedToBranded;
121+
return isInProgress() && brandingType() == BrandingType::UnbrandedToBranded;
122122
}
123123

124124
bool Migration::shouldTryToMigrate()
@@ -136,9 +136,9 @@ bool Migration::isClientVersionSet() const
136136

137137
bool Migration::isInProgress() const
138138
{
139-
const auto currentPhase = migrationPhase();
140-
return currentPhase != MigrationPhase::NotStarted
141-
&& currentPhase != MigrationPhase::Done;
139+
const auto currentPhase = phase();
140+
return currentPhase != Phase::NotStarted
141+
&& currentPhase != Phase::Done;
142142
}
143143

144144
Migration::LegacyData Migration::legacyData() const
@@ -195,8 +195,7 @@ Migration::LegacyData Migration::legacyData() const
195195
qCInfo(lcMigration) << "Copy settings" << oCSettings->allKeys().join(", ");
196196
Migration migration;
197197
migration.setDiscoveredLegacyConfigPath(configFileInfo.canonicalPath());
198-
legacyData.configFile = configFileString;
199-
legacyData.settings.create(oCSettings.release());
198+
legacyData.reset(oCSettings.get());
200199
migration.setLegacyData(legacyData);
201200
break;
202201
} else {
@@ -222,10 +221,9 @@ void Migration::setDiscoveredLegacyConfigPath(const QString &discoveredLegacyCon
222221
_discoveredLegacyConfigPath = discoveredLegacyConfigPath;
223222
}
224223

225-
void Migration::setLegacyData(const LegacyData &LegacyData)
224+
void Migration::setLegacyData(const LegacyData legacyData)
226225
{
227-
_configSettings.configFile = LegacyData.configFile;
228-
_configSettings.settings = LegacyData.settings;
226+
_legacyData = legacyData;
229227
}
230228

231229
}

src/libsync/settings/migration.h

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,44 @@ class OWNCLOUDSYNC_EXPORT Migration
1818
public:
1919
Migration() { };
2020

21-
enum MigrationPhase {
21+
enum Phase {
2222
NotStarted,
2323
SetupConfigFile,
2424
SetupUsers,
2525
SetupFolders,
2626
Done
2727
};
2828

29-
enum MigrationType {
29+
enum BrandingType {
3030
UnbrandedToUnbranded,
3131
UnbrandedToBranded,
3232
LegacyToUnbranded,
3333
LegacyToBranded
3434
};
3535

36-
enum VersionChangeType {
37-
NoVersionChange,
36+
enum UpgradeType {
37+
NoChange,
3838
Upgrade,
3939
Downgrade
4040
};
4141

42-
struct LegacyData {
43-
QString configFile;
44-
QSharedPointer<QSettings> settings;
45-
};
42+
using LegacyData = QSharedPointer<QSettings>;
4643

4744
[[nodiscard]] QVersionNumber previousVersion() const;
4845
[[nodiscard]] QVersionNumber currentVersion() const;
4946
[[nodiscard]] QVersionNumber configVersion() const;
5047

51-
[[nodiscard]] MigrationPhase migrationPhase() const;
52-
void setMigrationPhase(const MigrationPhase phase);
48+
[[nodiscard]] Phase phase() const;
49+
void setPhase(const Phase phase);
5350

54-
[[nodiscard]] MigrationType migrationType() const;
55-
void setMigrationType(const MigrationType type);
51+
[[nodiscard]] BrandingType brandingType() const;
52+
void setBrandingType(const BrandingType type);
5653

57-
[[nodiscard]] VersionChangeType versionChangeType() const;
58-
void setVersionChangeType(const VersionChangeType type);
54+
[[nodiscard]] UpgradeType upgradeType() const;
55+
void setUpgradeType(const UpgradeType type);
5956

6057
[[nodiscard]] LegacyData legacyData() const;
61-
void setLegacyData(const LegacyData &legacyData);
58+
void setLegacyData(const LegacyData legacyData);
6259

6360
/// Set during first time migration of legacy accounts in AccountManager
6461
[[nodiscard]] QString discoveredLegacyConfigPath() const;
@@ -67,18 +64,18 @@ class OWNCLOUDSYNC_EXPORT Migration
6764
[[nodiscard]] bool isUpgrade();
6865
[[nodiscard]] bool isDowngrade();
6966
[[nodiscard]] bool versionChanged();
70-
[[nodiscard]] bool shouldTryUnbrandedToBrandedMigration() const;
67+
[[nodiscard]] bool shouldTryUnbrandedToBrandedMigration();
7168
[[nodiscard]] bool isUnbrandedToBrandedMigration() const;
7269
[[nodiscard]] bool shouldTryToMigrate();
7370
[[nodiscard]] bool isClientVersionSet() const;
7471
[[nodiscard]] bool isInProgress() const;
7572

7673
private:
77-
static MigrationPhase _migrationPhase;
78-
static MigrationType _migrationType;
79-
static VersionChangeType _versionChangeType;
74+
static Phase _phase;
75+
static BrandingType _brandingType;
76+
static UpgradeType _upgradeType;
8077
static QString _discoveredLegacyConfigPath;
81-
static LegacyData _configSettings;
78+
static LegacyData _legacyData;
8279
};
8380
}
8481
#endif // MIGRATION_H

test/testmigration.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ private slots:
204204
// owncloud config files exists
205205
Migration migration;
206206
const auto legacyData = migration.legacyData();
207-
const auto legacyConfigFile = legacyData.configFile;
208-
QVERIFY(!legacyConfigFile.isEmpty());
209-
QCOMPARE(legacyConfigFile, ocConfig);
207+
QVERIFY(!legacyData.isNull());
210208

211209
// TODO: add accounts and folders to AccountManager and FolderMan without UI interference
212210
//_folderMan.reset({});
@@ -255,9 +253,7 @@ private slots:
255253
// branded owncloud config files exists
256254
Migration migration;
257255
const auto legacyData = migration.legacyData();
258-
const auto legacyConfigFile = legacyData.configFile;
259-
QVERIFY(!legacyConfigFile.isEmpty());
260-
QCOMPARE(legacyConfigFile, ocBrandedConfig);
256+
QVERIFY(!legacyData.isNull());
261257
}
262258

263259

@@ -283,9 +279,7 @@ private slots:
283279
// owncloud config files exists
284280
Migration migration;
285281
const auto legacyData = migration.legacyData();
286-
const auto legacyConfigFile = legacyData.configFile;
287-
QVERIFY(!legacyConfigFile.isEmpty());
288-
QCOMPARE(legacyConfigFile, brandedConfig);
282+
QVERIFY(!legacyData.isNull());
289283
}
290284

291285
// TODO: Downgrade

0 commit comments

Comments
 (0)