Skip to content

Commit c25dbe9

Browse files
committed
feat(UserMigration): Overwork migration to include all settings (mail accounts w/o unit tests)
Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
1 parent 857ae69 commit c25dbe9

3 files changed

Lines changed: 460 additions & 19 deletions

File tree

lib/Service/AliasesService.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCA\Mail\Db\MailAccountMapper;
1616
use OCA\Mail\Exception\ClientException;
1717
use OCP\AppFramework\Db\DoesNotExistException;
18+
use OCP\DB\Exception;
1819

1920
class AliasesService {
2021
/** @var AliasMapper */
@@ -133,4 +134,16 @@ public function updateSignature(string $userId, int $aliasId, ?string $signature
133134
$entity->setSignature($signature);
134135
return $this->aliasMapper->update($entity);
135136
}
137+
138+
/**
139+
* Update the S/MIME certificate for an alias.
140+
*
141+
* @throws DoesNotExistException
142+
* @throws Exception
143+
*/
144+
public function updateSMIMECertificateId(string $userId, int $aliasId, ?int $sMimeCertificateId = null): Alias {
145+
$entity = $this->find($aliasId, $userId);
146+
$entity->setSmimeCertificateId($sMimeCertificateId);
147+
return $this->aliasMapper->update($entity);
148+
}
136149
}

lib/UserMigration/MailAccountMigrator.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(
4242
private readonly TrustedSendersMigrationService $trustedSendersMigrationService,
4343
private readonly TextBlocksMigrationService $textBlocksMigrationService,
4444
private readonly TagsMigrationService $tagsMigrationService,
45-
private readonly SMIMEMigrationService $smimeMigrationService,
45+
private readonly SMIMEMigrationService $sMimeMigrationService,
4646
) {
4747
}
4848

@@ -58,7 +58,8 @@ public function export(IUser $user,
5858
$this->trustedSendersMigrationService->exportTrustedSenders($user, $exportDestination, $output);
5959
$this->textBlocksMigrationService->exportTextBlocks($user, $exportDestination, $output);
6060
$this->tagsMigrationService->exportTags($user, $exportDestination, $output);
61-
$this->smimeMigrationService->exportCertificates($user, $exportDestination, $output);
61+
$this->sMimeMigrationService->exportCertificates($user, $exportDestination, $output);
62+
$this->accountMigrationService->exportAccounts($user, $exportDestination, $output);
6263
}
6364

6465
#[\Override]
@@ -71,8 +72,9 @@ public function import(IUser $user, IImportSource $importSource, OutputInterface
7172
$this->internalAddressesMigrationService->importInternalAddresses($user, $importSource, $output);
7273
$this->trustedSendersMigrationService->importTrustedSenders($user, $importSource, $output);
7374
$this->textBlocksMigrationService->importTextBlocks($user, $importSource, $output);
75+
$newCertificateIds = $this->sMimeMigrationService->importCertificates($user, $importSource, $output);
76+
$newAccountIds = $this->accountMigrationService->importAccounts($user, $importSource, $output, $newCertificateIds);
7477
$newTagIds = $this->tagsMigrationService->importTags($user, $importSource, $output);
75-
$newCertificateIds = $this->smimeMigrationService->importCertificates($user, $importSource, $output);
7678

7779
$this->accountMigrationService->scheduleBackgroundJobs($user, $output);
7880
}
@@ -90,13 +92,14 @@ public function import(IUser $user, IImportSource $importSource, OutputInterface
9092
private function deleteExistingData(IUser $user, OutputInterface $output): void {
9193
$output->writeln($this->l10n->t("Deleting existing mail data for user {$user->getUID()}"), OutputInterface::VERBOSITY_VERBOSE);
9294

95+
$this->accountMigrationService->deleteAllAccounts($user, $output);
9396
$this->appConfigMigrationService->deleteAppConfiguration($user, $output);
9497
$this->internalAddressesMigrationService->removeInternalAddresses($user, $output);
9598
$this->trustedSendersMigrationService->removeAllTrustedSenders($user, $output);
9699
$this->textBlocksMigrationService->deleteAllTextBlocks($user, $output);
97100
$this->tagsMigrationService->deleteAllTags($user, $output);
98101
$this->accountMigrationService->deleteAllAccounts($user, $output);
99-
$this->smimeMigrationService->deleteAllUserCertificates($user, $output);
102+
$this->sMimeMigrationService->deleteAllUserCertificates($user, $output);
100103
}
101104

102105
#[\Override]

0 commit comments

Comments
 (0)