Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix background email job for disabled users #1255

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

📣 Announcement center: An announcement was posted by an admin]]></description>

<version>2.13.0</version>
<version>2.13.1</version>
<licence>agpl</licence>
<author>Joas Schilling</author>

Expand Down
10 changes: 6 additions & 4 deletions lib/MailNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
56 changes: 56 additions & 0 deletions lib/Migration/Version2011Date20220826074907.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2022 Joas Schilling <[email protected]>
*
* @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');
}
}
}