diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2022-08-26 10:18:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-26 10:18:44 +0300 |
commit | 5b1b9cd17eda532ddf81ad05a87b2689935c7436 (patch) | |
tree | e473fba404c38e05c230b18abe7c8f3b6ff14cdf | |
parent | b7d822b38d7420a41d62be7017fe20218480bb1a (diff) | |
parent | b083eb233a5fa3a5378a4a20568bfe1ed1af630f (diff) |
Merge pull request #1257 from nextcloud/backport/1255/stable23
[stable23] Fix background email job for disabled users
-rw-r--r-- | appinfo/info.xml | 2 | ||||
-rw-r--r-- | lib/MailNotifications.php | 10 | ||||
-rw-r--r-- | lib/Migration/Version2011Date20220826074907.php | 56 |
3 files changed, 63 insertions, 5 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml index c57cac7..75e0eac 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -15,7 +15,7 @@ 📣 Announcement center: An announcement was posted by an admin]]></description> - <version>2.11.1</version> + <version>2.11.2</version> <licence>agpl</licence> <author>Joas Schilling</author> diff --git a/lib/MailNotifications.php b/lib/MailNotifications.php index 5f5ea1e..990ec6b 100644 --- a/lib/MailNotifications.php +++ b/lib/MailNotifications.php @@ -144,10 +144,12 @@ class MailNotifications { 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; } diff --git a/lib/Migration/Version2011Date20220826074907.php b/lib/Migration/Version2011Date20220826074907.php new file mode 100644 index 0000000..60119a7 --- /dev/null +++ b/lib/Migration/Version2011Date20220826074907.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +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'); + } + } +} |