diff options
-rw-r--r-- | lib/Db/MailAccountMapper.php | 2 | ||||
-rw-r--r-- | lib/Migration/Version1105Date20210922104324.php | 63 | ||||
-rw-r--r-- | tests/psalm-baseline.xml | 5 |
3 files changed, 69 insertions, 1 deletions
diff --git a/lib/Db/MailAccountMapper.php b/lib/Db/MailAccountMapper.php index 8d6586fcd..d2b378375 100644 --- a/lib/Db/MailAccountMapper.php +++ b/lib/Db/MailAccountMapper.php @@ -135,7 +135,7 @@ class MailAccountMapper extends QBMapper { $qb = $this->db->getQueryBuilder(); $delete = $qb->delete($this->getTableName()) - ->where($qb->expr()->eq('provisioning_id', $qb->createNamedParameter($provisioningId, IQueryBuilder::PARAM_BOOL))); + ->where($qb->expr()->eq('provisioning_id', $qb->createNamedParameter($provisioningId, IQueryBuilder::PARAM_INT))); $delete->execute(); } diff --git a/lib/Migration/Version1105Date20210922104324.php b/lib/Migration/Version1105Date20210922104324.php new file mode 100644 index 000000000..0982d9e6c --- /dev/null +++ b/lib/Migration/Version1105Date20210922104324.php @@ -0,0 +1,63 @@ +<?php + +declare(strict_types=1); + +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; + +class Version1105Date20210922104324 extends SimpleMigrationStep { + private $connection; + private $logger; + + public function __construct(IDBConnection $connection, LoggerInterface $logger) { + $this->connection = $connection; + $this->logger = $logger; + } + + 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->execute(); + } catch (Exception $e) { + $this->logger->info('Migration to cleanup mail accounts without valid provisioning configuration failed', [ + 'exception' => $e + ]); + return; + } + + $accountIds = array_map(static function ($row) { + return (int)$row['id']; + }, $result->fetchAll()); + $result->closeCursor(); + + if (count($accountIds) === 0) { + return; + } + + $qb = $this->connection->getQueryBuilder(); + $qb->delete('mail_accounts') + ->where($qb->expr()->in('id', $qb->createNamedParameter($accountIds, IQueryBuilder::PARAM_INT_ARRAY))); + + try { + $qb->execute(); + } catch (Exception $e) { + $this->logger->info('Migration to cleanup mail accounts without valid provisioning configuration failed', [ + 'exception' => $e + ]); + return; + } + } +} diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index da9f432f9..6f8bd46ec 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -283,6 +283,11 @@ <code>UserDeletedListener</code> </MissingDependency> </file> + <file src="lib/Migration/Version1105Date20210922104324.php"> + <ImplicitToStringCast occurrences="1"> + <code>$qb->createNamedParameter($accountIds, IQueryBuilder::PARAM_INT_ARRAY)</code> + </ImplicitToStringCast> + </file> <file src="lib/Service/Classification/ImportanceClassifier.php"> <InvalidScalarArgument occurrences="1"> <code>$predictedValidationLabel</code> |