|
15 | 15 | use OCA\Mail\UserMigration\Service\AccountMigrationService; |
16 | 16 | use OCA\Mail\UserMigration\Service\AppConfigMigrationService; |
17 | 17 | use OCA\Mail\UserMigration\Service\InternalAddressesMigrationService; |
| 18 | +use OCA\Mail\UserMigration\Service\QuickActionsMigrationService; |
18 | 19 | use OCA\Mail\UserMigration\Service\SMIMEMigrationService; |
19 | 20 | use OCA\Mail\UserMigration\Service\TagsMigrationService; |
20 | 21 | use OCA\Mail\UserMigration\Service\TextBlocksMigrationService; |
|
30 | 31 | use Symfony\Component\Console\Output\OutputInterface; |
31 | 32 |
|
32 | 33 | class MailAccountMigrator implements IMigrator { |
33 | | - public const EXPORT_ROOT = Application::APP_ID; |
34 | | - public const FILENAME_PLACEHOLDER = '{filename}'; |
35 | | - |
36 | | - public function __construct( |
37 | | - private readonly IL10N $l10n, |
38 | | - private readonly ICrypto $crypto, |
39 | | - private readonly AccountMigrationService $accountMigrationService, |
40 | | - private readonly AppConfigMigrationService $appConfigMigrationService, |
41 | | - private readonly InternalAddressesMigrationService $internalAddressesMigrationService, |
42 | | - private readonly TrustedSendersMigrationService $trustedSendersMigrationService, |
43 | | - private readonly TextBlocksMigrationService $textBlocksMigrationService, |
44 | | - private readonly TagsMigrationService $tagsMigrationService, |
45 | | - private readonly SMIMEMigrationService $sMimeMigrationService, |
46 | | - ) { |
47 | | - } |
48 | | - |
49 | | - #[\Override] |
50 | | - public function export(IUser $user, |
51 | | - IExportDestination $exportDestination, |
52 | | - OutputInterface $output, |
53 | | - ): void { |
54 | | - $output->writeln($this->l10n->t("Exporting mail accounts for user {$user->getUID()}"), OutputInterface::VERBOSITY_VERBOSE); |
55 | | - |
56 | | - $this->appConfigMigrationService->exportAppConfiguration($user, $exportDestination, $output); |
57 | | - $this->internalAddressesMigrationService->exportInternalAddresses($user, $exportDestination, $output); |
58 | | - $this->trustedSendersMigrationService->exportTrustedSenders($user, $exportDestination, $output); |
59 | | - $this->textBlocksMigrationService->exportTextBlocks($user, $exportDestination, $output); |
60 | | - $this->tagsMigrationService->exportTags($user, $exportDestination, $output); |
61 | | - $this->sMimeMigrationService->exportCertificates($user, $exportDestination, $output); |
62 | | - $this->accountMigrationService->exportAccounts($user, $exportDestination, $output); |
63 | | - } |
64 | | - |
65 | | - #[\Override] |
66 | | - public function import(IUser $user, IImportSource $importSource, OutputInterface $output): void { |
67 | | - $output->writeln($this->l10n->t("Importing mail accounts for user {$user->getUID()}"), OutputInterface::VERBOSITY_VERBOSE); |
68 | | - |
69 | | - $this->deleteExistingData($user, $output); |
70 | | - |
71 | | - $this->appConfigMigrationService->importAppConfiguration($user, $importSource, $output); |
72 | | - $this->internalAddressesMigrationService->importInternalAddresses($user, $importSource, $output); |
73 | | - $this->trustedSendersMigrationService->importTrustedSenders($user, $importSource, $output); |
74 | | - $this->textBlocksMigrationService->importTextBlocks($user, $importSource, $output); |
75 | | - $newCertificateIds = $this->sMimeMigrationService->importCertificates($user, $importSource, $output); |
76 | | - $newAccountIds = $this->accountMigrationService->importAccounts($user, $importSource, $output, $newCertificateIds); |
77 | | - $newTagIds = $this->tagsMigrationService->importTags($user, $importSource, $output); |
78 | | - |
79 | | - $this->accountMigrationService->scheduleBackgroundJobs($user, $output); |
80 | | - } |
81 | | - |
82 | | - /** |
83 | | - * Delete all existing user data of our app to ensure |
84 | | - * the result of the import is always the same. |
85 | | - * |
86 | | - * @param IUser $user |
87 | | - * @param OutputInterface $output |
88 | | - * @throws ClientException |
89 | | - * @throws DoesNotExistException |
90 | | - * @throws ServiceException |
91 | | - */ |
92 | | - private function deleteExistingData(IUser $user, OutputInterface $output): void { |
93 | | - $output->writeln($this->l10n->t("Deleting existing mail data for user {$user->getUID()}"), OutputInterface::VERBOSITY_VERBOSE); |
94 | | - |
95 | | - $this->accountMigrationService->deleteAllAccounts($user, $output); |
96 | | - $this->appConfigMigrationService->deleteAppConfiguration($user, $output); |
97 | | - $this->internalAddressesMigrationService->removeInternalAddresses($user, $output); |
98 | | - $this->trustedSendersMigrationService->removeAllTrustedSenders($user, $output); |
99 | | - $this->textBlocksMigrationService->deleteAllTextBlocks($user, $output); |
100 | | - $this->tagsMigrationService->deleteAllTags($user, $output); |
101 | | - $this->accountMigrationService->deleteAllAccounts($user, $output); |
102 | | - $this->sMimeMigrationService->deleteAllUserCertificates($user, $output); |
103 | | - } |
104 | | - |
105 | | - #[\Override] |
106 | | - public function getId(): string { |
107 | | - return 'mail_account'; |
108 | | - } |
109 | | - |
110 | | - #[\Override] |
111 | | - public function getDisplayName(): string { |
112 | | - return $this->l10n->t('Mail'); |
113 | | - } |
114 | | - |
115 | | - #[\Override] |
116 | | - public function getDescription(): string { |
117 | | - return $this->l10n->t('Mail account parameters, aliases and preferences'); |
118 | | - } |
119 | | - |
120 | | - #[\Override] |
121 | | - public function getVersion(): int { |
122 | | - return 02_00_00; |
123 | | - } |
124 | | - |
125 | | - #[\Override] |
126 | | - public function canImport(IImportSource $importSource): bool { |
127 | | - try { |
128 | | - return $importSource->getMigratorVersion($this->getId()) <= $this->getVersion(); |
129 | | - } catch (UserMigrationException) { |
130 | | - return false; |
131 | | - } |
132 | | - } |
| 34 | + public const EXPORT_ROOT = Application::APP_ID; |
| 35 | + public const FILENAME_PLACEHOLDER = '{filename}'; |
| 36 | + |
| 37 | + public function __construct( |
| 38 | + private readonly IL10N $l10n, |
| 39 | + private readonly ICrypto $crypto, |
| 40 | + private readonly AccountMigrationService $accountMigrationService, |
| 41 | + private readonly AppConfigMigrationService $appConfigMigrationService, |
| 42 | + private readonly InternalAddressesMigrationService $internalAddressesMigrationService, |
| 43 | + private readonly TrustedSendersMigrationService $trustedSendersMigrationService, |
| 44 | + private readonly TextBlocksMigrationService $textBlocksMigrationService, |
| 45 | + private readonly TagsMigrationService $tagsMigrationService, |
| 46 | + private readonly SMIMEMigrationService $sMimeMigrationService, |
| 47 | + private readonly QuickActionsMigrationService $quickActionsMigrationService, |
| 48 | + ) { |
| 49 | + } |
| 50 | + |
| 51 | + #[\Override] |
| 52 | + public function export(IUser $user, |
| 53 | + IExportDestination $exportDestination, |
| 54 | + OutputInterface $output, |
| 55 | + ): void { |
| 56 | + $output->writeln($this->l10n->t("Exporting mail accounts for user {$user->getUID()}"), OutputInterface::VERBOSITY_VERBOSE); |
| 57 | + |
| 58 | + $this->appConfigMigrationService->exportAppConfiguration($user, $exportDestination, $output); |
| 59 | + $this->internalAddressesMigrationService->exportInternalAddresses($user, $exportDestination, $output); |
| 60 | + $this->trustedSendersMigrationService->exportTrustedSenders($user, $exportDestination, $output); |
| 61 | + $this->textBlocksMigrationService->exportTextBlocks($user, $exportDestination, $output); |
| 62 | + $this->tagsMigrationService->exportTags($user, $exportDestination, $output); |
| 63 | + $this->sMimeMigrationService->exportCertificates($user, $exportDestination, $output); |
| 64 | + $this->accountMigrationService->exportAccounts($user, $exportDestination, $output); |
| 65 | + $this->quickActionsMigrationService->exportQuickActions($user, $exportDestination, $output); |
| 66 | + } |
| 67 | + |
| 68 | + #[\Override] |
| 69 | + public function import(IUser $user, IImportSource $importSource, OutputInterface $output): void { |
| 70 | + $output->writeln($this->l10n->t("Importing mail accounts for user {$user->getUID()}"), OutputInterface::VERBOSITY_VERBOSE); |
| 71 | + |
| 72 | + $this->deleteExistingData($user, $output); |
| 73 | + |
| 74 | + $this->appConfigMigrationService->importAppConfiguration($user, $importSource, $output); |
| 75 | + $this->internalAddressesMigrationService->importInternalAddresses($user, $importSource, $output); |
| 76 | + $this->trustedSendersMigrationService->importTrustedSenders($user, $importSource, $output); |
| 77 | + $this->textBlocksMigrationService->importTextBlocks($user, $importSource, $output); |
| 78 | + $newCertificateIds = $this->sMimeMigrationService->importCertificates($user, $importSource, $output); |
| 79 | + $newAccountAndMailboxIds = $this->accountMigrationService->importAccounts($user, $importSource, $output, $newCertificateIds); |
| 80 | + $newTagIds = $this->tagsMigrationService->importTags($user, $importSource, $output); |
| 81 | + $this->quickActionsMigrationService->importQuickActions($user, $importSource, $output, $newAccountAndMailboxIds, $newTagIds); |
| 82 | + |
| 83 | + $this->accountMigrationService->scheduleBackgroundJobs($user, $output); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Delete all existing user data of our app to ensure |
| 88 | + * the result of the import is always the same. |
| 89 | + * |
| 90 | + * @param IUser $user |
| 91 | + * @param OutputInterface $output |
| 92 | + * @throws ClientException |
| 93 | + * @throws DoesNotExistException |
| 94 | + * @throws ServiceException |
| 95 | + */ |
| 96 | + private function deleteExistingData(IUser $user, OutputInterface $output): void { |
| 97 | + $output->writeln($this->l10n->t("Deleting existing mail data for user {$user->getUID()}"), OutputInterface::VERBOSITY_VERBOSE); |
| 98 | + |
| 99 | + $this->quickActionsMigrationService->deleteAllQuickActions($user, $output); |
| 100 | + $this->accountMigrationService->deleteAllAccounts($user, $output); |
| 101 | + $this->appConfigMigrationService->deleteAppConfiguration($user, $output); |
| 102 | + $this->internalAddressesMigrationService->removeInternalAddresses($user, $output); |
| 103 | + $this->trustedSendersMigrationService->removeAllTrustedSenders($user, $output); |
| 104 | + $this->textBlocksMigrationService->deleteAllTextBlocks($user, $output); |
| 105 | + $this->tagsMigrationService->deleteAllTags($user, $output); |
| 106 | + $this->accountMigrationService->deleteAllAccounts($user, $output); |
| 107 | + $this->sMimeMigrationService->deleteAllUserCertificates($user, $output); |
| 108 | + } |
| 109 | + |
| 110 | + #[\Override] |
| 111 | + public function getId(): string { |
| 112 | + return 'mail_account'; |
| 113 | + } |
| 114 | + |
| 115 | + #[\Override] |
| 116 | + public function getDisplayName(): string { |
| 117 | + return $this->l10n->t('Mail'); |
| 118 | + } |
| 119 | + |
| 120 | + #[\Override] |
| 121 | + public function getDescription(): string { |
| 122 | + return $this->l10n->t('Mail account parameters, aliases and preferences'); |
| 123 | + } |
| 124 | + |
| 125 | + #[\Override] |
| 126 | + public function getVersion(): int { |
| 127 | + return 02_00_00; |
| 128 | + } |
| 129 | + |
| 130 | + #[\Override] |
| 131 | + public function canImport(IImportSource $importSource): bool { |
| 132 | + try { |
| 133 | + return $importSource->getMigratorVersion($this->getId()) <= $this->getVersion(); |
| 134 | + } catch (UserMigrationException) { |
| 135 | + return false; |
| 136 | + } |
| 137 | + } |
133 | 138 |
|
134 | 139 | } |
0 commit comments