-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathVersion1105Date20210922104324.php
More file actions
70 lines (58 loc) · 1.88 KB
/
Version1105Date20210922104324.php
File metadata and controls
70 lines (58 loc) · 1.88 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
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Mail\Migration;
use Closure;
use Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use Psr\Log\LoggerInterface;
/**
* @psalm-api
*/
class Version1105Date20210922104324 extends SimpleMigrationStep {
private $connection;
private $logger;
public function __construct(IDBConnection $connection, LoggerInterface $logger) {
$this->connection = $connection;
$this->logger = $logger;
}
#[\Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$qb = $this->connection->getQueryBuilder();
$qb->select('accounts.id')
->from('mail_accounts', 'accounts')
->leftJoin('accounts', 'mail_provisionings', 'provisionings', $qb->expr()->eq('accounts.provisioning_id', 'provisionings.id'))
->where($qb->expr()->isNotNull('accounts.provisioning_id'))
->andWhere($qb->expr()->isNull('provisionings.id'));
try {
$result = $qb->executeQuery();
} catch (Exception $e) {
$this->logger->info('Migration to cleanup mail accounts without valid provisioning configuration failed', [
'exception' => $e
]);
return;
}
$accountIds = array_map(static fn ($row) => (int)$row['id'], $result->fetchAll());
$result->closeCursor();
if ($accountIds === []) {
return;
}
$qb = $this->connection->getQueryBuilder();
$qb->delete('mail_accounts')
->where($qb->expr()->in('id', $qb->createNamedParameter($accountIds, IQueryBuilder::PARAM_INT_ARRAY)));
try {
$qb->executeStatement();
} catch (Exception $e) {
$this->logger->info('Migration to cleanup mail accounts without valid provisioning configuration failed', [
'exception' => $e
]);
return;
}
}
}