From 417f15761e9d2f0b44f5b0c87ac98e79ef6b4f2a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Aug 2022 07:48:06 +0200 Subject: [PATCH 1/3] Only update the next_send_time for disabled users when the time was reached Signed-off-by: Joas Schilling --- lib/MailNotifications.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/MailNotifications.php b/lib/MailNotifications.php index 5f5ea1ec9..990ec6b16 100644 --- a/lib/MailNotifications.php +++ b/lib/MailNotifications.php @@ -144,10 +144,12 @@ public function sendEmails(int $batchSize, int $sendTime): void { foreach ($userSettings as $settings) { if (isset($userEnabled[$settings->getUserId()]) && $userEnabled[$settings->getUserId()] === 'false') { // User is disabled, skip sending the email for them - $settings->setNextSendTime( - $settings->getNextSendTime() + $settings->getBatchTime() - ); - $this->settingsMapper->update($settings); + if ($settings->getNextSendTime() <= $sendTime) { + $settings->setNextSendTime( + $sendTime + $settings->getBatchTime() + ); + $this->settingsMapper->update($settings); + } continue; } From 4140e5138acb521f5d339dc064f1b7dc5cbde192 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Aug 2022 08:00:51 +0200 Subject: [PATCH 2/3] Add a migration to reset the next send for disabled users Signed-off-by: Joas Schilling --- .../Version2011Date20220826074907.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 lib/Migration/Version2011Date20220826074907.php diff --git a/lib/Migration/Version2011Date20220826074907.php b/lib/Migration/Version2011Date20220826074907.php new file mode 100644 index 000000000..60119a7b3 --- /dev/null +++ b/lib/Migration/Version2011Date20220826074907.php @@ -0,0 +1,56 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Notifications\Migration; + +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +class Version2011Date20220826074907 extends SimpleMigrationStep { + /** @var IDBConnection */ + protected $connection; + + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { + $query = $this->connection->getQueryBuilder(); + + // The maximum valid value is NOW + 7 days, but since updating is fixed + // and you only run into the bug at the year 2038, we can also count up 8 days. + $time = time() + 3600 * 24 * 8; + + $query->update('notifications_settings') + ->set('next_send_time', $query->createNamedParameter(1, IQueryBuilder::PARAM_INT)) + ->where($query->expr()->gt('next_send_time', $query->createNamedParameter($time, IQueryBuilder::PARAM_INT))); + $count = $query->executeStatement(); + + if ($count > 0) { + $output->info('Fixed next send of ' . $count . ' disabled users'); + } + } +} From b083eb233a5fa3a5378a4a20568bfe1ed1af630f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Aug 2022 08:51:21 +0200 Subject: [PATCH 3/3] Bump version Signed-off-by: Joas Schilling --- appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index c57cac770..75e0eac10 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -15,7 +15,7 @@ 📣 Announcement center: An announcement was posted by an admin]]> - 2.11.1 + 2.11.2 agpl Joas Schilling