Skip to content

Commit 29a9d79

Browse files
fixup! feat: support user migration
Signed-off-by: Christoph Wurst <[email protected]>
1 parent 1ab8e38 commit 29a9d79

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

lib/Controller/AccountsController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class AccountsController extends Controller {
5353
private IRemoteHostValidator $hostValidator;
5454
private MailboxSync $mailboxSync;
5555

56-
public function __construct(string $appName,
56+
public function __construct(
57+
string $appName,
5758
IRequest $request,
5859
AccountService $accountService,
5960
$UserId,

lib/Db/MailAccount.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public function toJson() {
302302
'name' => $this->getName(),
303303
'order' => $this->getOrder(),
304304
'emailAddress' => $this->getEmail(),
305-
'authMethod' => $this->authMethod,
305+
'authMethod' => $this->getAuthMethod() ?? 'password',
306306
'imapHost' => $this->getInboundHost(),
307307
'imapPort' => $this->getInboundPort(),
308308
'imapUser' => $this->getInboundUser(),

lib/Service/AccountService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
namespace OCA\Mail\Service;
1212

1313
use OCA\Mail\Account;
14-
use OCA\Mail\AppInfo\Application;
1514
use OCA\Mail\BackgroundJob\PreviewEnhancementProcessingJob;
1615
use OCA\Mail\BackgroundJob\QuotaJob;
1716
use OCA\Mail\BackgroundJob\RepairSyncJob;

lib/UserMigration/MailAccountMigrator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function export(IUser $user,
6363
$output->writeln("Can not decrypt outbound password of account {$account->getId()}: " . $e->getMessage());
6464
}
6565
}
66-
} else if ($account->getMailAccount()->getAuthMethod() === 'xoauth2') {
66+
} elseif ($account->getMailAccount()->getAuthMethod() === 'xoauth2') {
6767
$encryptedRefreshToken = $account->getMailAccount()->getOauthRefreshToken();
6868
$encryptedAccessToken = $account->getMailAccount()->getOauthAccessToken();
6969
if ($encryptedRefreshToken !== null) {
@@ -117,7 +117,7 @@ public function export(IUser $user,
117117
$exportDestination->addFileContents('mail/accounts/index.json', json_encode($index));
118118
}
119119

120-
public function import(IUser $user, IImportSource $importSource, OutputInterface $output,): void {
120+
public function import(IUser $user, IImportSource $importSource, OutputInterface $output): void {
121121
$index = json_decode($importSource->getFileContents('mail/accounts/index.json'), true);
122122
foreach ($index as $accountFilePath) {
123123
$accountData = json_decode($importSource->getFileContents($accountFilePath), true);
@@ -189,7 +189,7 @@ public function getVersion(): int {
189189
return 01_00_00;
190190
}
191191

192-
public function canImport(IImportSource $importSource,): bool {
192+
public function canImport(IImportSource $importSource): bool {
193193
try {
194194
return $importSource->getMigratorVersion($this->getId()) <= $this->getVersion();
195195
} catch (UserMigrationException) {

tests/Integration/Db/MailAccountTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function testToAPI() {
7272
'outOfOfficeFollowsSystem' => true,
7373
'debug' => false,
7474
'classificationEnabled' => true,
75+
'authMethod' => 'password',
7576
], $a->toJson());
7677
}
7778

@@ -111,6 +112,7 @@ public function testMailAccountConstruct() {
111112
'outOfOfficeFollowsSystem' => false,
112113
'debug' => false,
113114
'classificationEnabled' => true,
115+
'authMethod' => 'password',
114116
];
115117
$a = new MailAccount($expected);
116118
// TODO: fix inconsistency

tests/Unit/UserMigration/MailAccountMigratorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function testExportBasicAccountInfo(): void {
136136
]);
137137
$exportDestination = $this->createMock(IExportDestination::class);
138138
$exportDestination->method('addFileContents')
139-
->willReturnCallback(function(string $path, string $content) {
139+
->willReturnCallback(function (string $path, string $content) {
140140
if ($path === 'mail/accounts/index.json') {
141141
self::assertSame(
142142
[
@@ -145,11 +145,11 @@ public function testExportBasicAccountInfo(): void {
145145
],
146146
json_decode($content, true)
147147
);
148-
} else if ($path === 'mail/accounts/101.json') {
148+
} elseif ($path === 'mail/accounts/101.json') {
149149
$accountData = json_decode($content, true);
150150
self::assertArrayHasKey('id', $accountData);
151151
self::assertSame(101, $accountData['id']);
152-
} else if ($path === 'mail/accounts/102.json') {
152+
} elseif ($path === 'mail/accounts/102.json') {
153153
$accountData = json_decode($content, true);
154154
self::assertArrayHasKey('id', $accountData);
155155
self::assertSame(102, $accountData['id']);

0 commit comments

Comments
 (0)