-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathMailAccountMigrator.php
More file actions
115 lines (96 loc) · 3.93 KB
/
MailAccountMigrator.php
File metadata and controls
115 lines (96 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Mail\UserMigration;
use OCA\Mail\AppInfo\Application;
use OCA\Mail\Exception\ClientException;
use OCA\Mail\Exception\ServiceException;
use OCA\Mail\UserMigration\Service\AccountMigrationService;
use OCA\Mail\UserMigration\Service\AppConfigMigrationService;
use OCA\Mail\UserMigration\Service\TextBlocksMigrationService;
use OCA\Mail\UserMigration\Service\TrustedSendersMigrationService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IL10N;
use OCP\IUser;
use OCP\Security\ICrypto;
use OCP\UserMigration\IExportDestination;
use OCP\UserMigration\IImportSource;
use OCP\UserMigration\IMigrator;
use OCP\UserMigration\UserMigrationException;
use Symfony\Component\Console\Output\OutputInterface;
class MailAccountMigrator implements IMigrator {
public const EXPORT_ROOT = Application::APP_ID;
public const FILENAME_PLACEHOLDER = '{filename}';
public function __construct(
private readonly IL10N $l10n,
private readonly ICrypto $crypto,
private readonly AccountMigrationService $accountMigrationService,
private readonly AppConfigMigrationService $appConfigMigrationService,
private readonly TrustedSendersMigrationService $trustedSendersMigrationService,
private readonly TextBlocksMigrationService $textBlocksMigrationService,
) {
}
#[\Override]
public function export(IUser $user,
IExportDestination $exportDestination,
OutputInterface $output,
): void {
$output->writeln($this->l10n->t("Exporting mail accounts for user {$user->getUID()}"), OutputInterface::VERBOSITY_VERBOSE);
$this->appConfigMigrationService->exportAppConfiguration($user, $exportDestination, $output);
$this->trustedSendersMigrationService->exportTrustedSenders($user, $exportDestination, $output);
$this->textBlocksMigrationService->exportTextBlocks($user, $exportDestination, $output);
}
#[\Override]
public function import(IUser $user, IImportSource $importSource, OutputInterface $output): void {
$output->writeln($this->l10n->t("Importing mail accounts for user {$user->getUID()}"), OutputInterface::VERBOSITY_VERBOSE);
$this->deleteExistingData($user, $output);
$this->appConfigMigrationService->importAppConfiguration($user, $importSource, $output);
$this->trustedSendersMigrationService->importTrustedSenders($user, $importSource, $output);
$this->textBlocksMigrationService->importTextBlocks($user, $importSource, $output);
$this->accountMigrationService->scheduleBackgroundJobs($user, $output);
}
/**
* Delete all existing user data of our app to ensure
* the result of the import is always the same.
*
* @param IUser $user
* @param OutputInterface $output
* @throws ClientException
* @throws DoesNotExistException
* @throws ServiceException
*/
private function deleteExistingData(IUser $user, OutputInterface $output): void {
$output->writeln($this->l10n->t("Deleting existing mail data for user {$user->getUID()}"), OutputInterface::VERBOSITY_VERBOSE);
$this->appConfigMigrationService->deleteAppConfiguration($user, $output);
$this->trustedSendersMigrationService->removeAllTrustedSenders($user, $output);
$this->textBlocksMigrationService->deleteAllTextBlocks($user, $output);
$this->accountMigrationService->deleteAllAccounts($user, $output);
}
#[\Override]
public function getId(): string {
return 'mail_account';
}
#[\Override]
public function getDisplayName(): string {
return $this->l10n->t('Mail');
}
#[\Override]
public function getDescription(): string {
return $this->l10n->t('Mail account parameters, aliases and preferences');
}
#[\Override]
public function getVersion(): int {
return 02_00_00;
}
#[\Override]
public function canImport(IImportSource $importSource): bool {
try {
return $importSource->getMigratorVersion($this->getId()) <= $this->getVersion();
} catch (UserMigrationException) {
return false;
}
}
}