Skip to content

Commit 370051d

Browse files
authored
Merge pull request #8978 from nextcloud/backport/8973/stable-4.0
[stable-4.0] fix: make sure migration is skipped when setting DISABLE_ACCOUNT_MIGRATION
2 parents 4bfdb01 + c0b4ec1 commit 370051d

4 files changed

Lines changed: 47 additions & 37 deletions

File tree

src/gui/accountmanager.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ AccountManager::AccountsRestoreResult AccountManager::restore(const bool alsoRes
118118
}
119119
#endif
120120

121+
if (settings->childGroups().isEmpty()) {
122+
return AccountsNotFound;
123+
}
124+
121125
auto result = AccountsRestoreSuccess;
122126
const auto settingsChildGroups = settings->childGroups();
123127
for (const auto &accountId : settingsChildGroups) {
@@ -735,7 +739,7 @@ void AccountManager::shutdown()
735739

736740
QList<AccountStatePtr> AccountManager::accounts() const
737741
{
738-
return _accounts;
742+
return _accounts;
739743
}
740744

741745
bool AccountManager::isAccountIdAvailable(const QString &id) const

src/gui/accountmanager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class AccountManager : public QObject
2424
public:
2525
enum AccountsRestoreResult {
2626
AccountsRestoreFailure = 0,
27+
AccountsNotFound,
2728
AccountsRestoreSuccess,
2829
AccountsRestoreSuccessFromLegacyVersion,
2930
AccountsRestoreSuccessWithSkipped

src/gui/application.cpp

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,15 @@ void Application::setupAccountsAndFolders()
486486
_folderManager.reset(new FolderMan);
487487

488488
const auto accountsRestoreResult = restoreLegacyAccount();
489+
const auto accounts = AccountManager::instance()->accounts();
490+
if (accountsRestoreResult != AccountManager::AccountsRestoreSuccessFromLegacyVersion
491+
&& accounts.empty()) {
492+
qCWarning(lcApplication) << "Migration result: " << accountsRestoreResult;
493+
qCDebug(lcApplication) << "is migration disabled?" << DISABLE_ACCOUNT_MIGRATION;
494+
qCWarning(lcApplication) << "No accounts were migrated, prompting user to set up accounts and folders from scratch.";
495+
496+
return;
497+
}
489498

490499
const auto foldersListSize = FolderMan::instance()->setupFolders();
491500
FolderMan::instance()->setSyncEnabled(true);
@@ -498,39 +507,31 @@ void Application::setupAccountsAndFolders()
498507
return list.join("\n");
499508
};
500509

501-
if (const auto accounts = AccountManager::instance()->accounts();
502-
accountsRestoreResult == AccountManager::AccountsRestoreSuccessFromLegacyVersion
503-
&& !accounts.isEmpty()) {
504-
505-
const auto accountsListSize = accounts.size();
506-
if (Theme::instance()->displayLegacyImportDialog()) {
507-
const auto accountsRestoreMessage = accountsListSize > 1
508-
? tr("%1 accounts", "number of accounts imported").arg(QString::number(accountsListSize))
509-
: tr("1 account");
510-
const auto foldersRestoreMessage = foldersListSize > 1
511-
? tr("%1 folders", "number of folders imported").arg(QString::number(foldersListSize))
512-
: tr("1 folder");
513-
const auto messageBox = new QMessageBox(QMessageBox::Information,
514-
tr("Legacy import"),
515-
tr("Imported %1 and %2 from a legacy desktop client.\n%3",
516-
"number of accounts and folders imported. list of users.")
517-
.arg(accountsRestoreMessage,
518-
foldersRestoreMessage,
519-
prettyNamesList(accounts))
520-
);
521-
messageBox->setWindowModality(Qt::NonModal);
522-
messageBox->open();
523-
}
524-
525-
qCWarning(lcApplication) << "Migration result AccountManager::AccountsRestoreResult:" << accountsRestoreResult;
526-
qCWarning(lcApplication) << "Folders migrated: " << foldersListSize;
527-
qCWarning(lcApplication) << accountsListSize << "account(s) were migrated:" << prettyNamesList(accounts);
528-
529-
} else {
530-
qCWarning(lcApplication) << "Migration result AccountManager::AccountsRestoreResult: " << accountsRestoreResult;
531-
qCWarning(lcApplication) << "Folders migrated: " << foldersListSize;
532-
qCWarning(lcApplication) << "No accounts were migrated, prompting user to set up accounts and folders from scratch.";
510+
const auto accountsListSize = accounts.size();
511+
if (accountsRestoreResult == AccountManager::AccountsRestoreSuccessFromLegacyVersion
512+
&& Theme::instance()->displayLegacyImportDialog()
513+
&& !AccountManager::instance()->forceLegacyImport()) {
514+
const auto accountsRestoreMessage = accountsListSize > 1
515+
? tr("%1 accounts", "number of accounts imported").arg(QString::number(accountsListSize))
516+
: tr("1 account");
517+
const auto foldersRestoreMessage = foldersListSize > 1
518+
? tr("%1 folders", "number of folders imported").arg(QString::number(foldersListSize))
519+
: tr("1 folder");
520+
const auto messageBox = new QMessageBox(QMessageBox::Information,
521+
tr("Legacy import"),
522+
tr("Imported %1 and %2 from a legacy desktop client.\n%3",
523+
"number of accounts and folders imported. list of users.")
524+
.arg(accountsRestoreMessage,
525+
foldersRestoreMessage,
526+
prettyNamesList(accounts))
527+
);
528+
messageBox->setWindowModality(Qt::NonModal);
529+
messageBox->open();
533530
}
531+
532+
qCWarning(lcApplication) << "Account(s) setup result:" << accountsRestoreResult;
533+
qCWarning(lcApplication) << foldersListSize << "folder(s) migrated";
534+
qCWarning(lcApplication) << accountsListSize << "account(s) migrated:" << prettyNamesList(accounts);
534535
}
535536

536537
void Application::setupConfigFile()

src/gui/folderman.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,15 @@ int FolderMan::setupFoldersMigration()
348348
ConfigFile cfg;
349349
QDir storageDir(cfg.configPath());
350350
_folderConfigPath = cfg.configPath();
351+
auto configPath = _folderConfigPath;
351352

352-
const auto legacyConfigPath = ConfigFile::discoveredLegacyConfigPath();
353-
const auto configPath = legacyConfigPath.isEmpty() ? _folderConfigPath : legacyConfigPath;
354-
355-
qCInfo(lcFolderMan) << "Setup folders from " << configPath << "(migration)";
353+
#if !DISABLE_ACCOUNT_MIGRATION
354+
if (const auto legacyConfigPath = ConfigFile::discoveredLegacyConfigPath();!legacyConfigPath.isEmpty()) {
355+
configPath = legacyConfigPath;
356+
qCInfo(lcFolderMan) << "Starting folder migration from legacy path:" << legacyConfigPath;
357+
}
358+
#endif
359+
qCInfo(lcFolderMan) << "Setup folders from" << configPath;
356360

357361
QDir dir(configPath);
358362
// We need to include hidden files just in case the alias starts with '.'

0 commit comments

Comments
 (0)