Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2021-09-22 13:35:56 +0300
committerDaniel Kesselberg <mail@danielkesselberg.de>2021-09-23 22:50:01 +0300
commit90b1aef5c3f0265388b653e3227f55be8b943aeb (patch)
tree8098c486e629223e3714de994232e97362f0cf44 /lib
parent2cba08a2f99e2d713c23765b96220a5f4448d75f (diff)
Set proper type for provisioning_id
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Db/MailAccountMapper.php2
-rw-r--r--lib/Migration/Version1105Date20210922104324.php63
2 files changed, 64 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;
+ }
+ }
+}