Skip to content
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
7 changes: 7 additions & 0 deletions lib/MailNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ public function sendEmails(int $batchSize, int $sendTime): void {
$batchTime = $defaultBatchTime;
}

if ($batchTime === 0) {
// Mails are off, so drop the user from the queue of the background job
$settings->setNextSendTime(0);
$this->settingsMapper->update($settings);
continue;
}

$userId = $settings->getUserId();
if (isset($userEnabled[$userId]) && $userEnabled[$userId] === false) {
// User is disabled, skip sending the email for them
Expand Down
30 changes: 30 additions & 0 deletions tests/Unit/MailNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,34 @@ public function testSendEmailsKeepsNextSendTimeOfDisabledUserInFuture(): void {

$this->assertSame($futureSendTime, $settings->getNextSendTime());
}

public function testSendEmailsSkipsDefaultUserWhenDefaultIsOff(): void {
$settings = new Settings();
$settings->setUserId('user1');
$settings->setBatchTime(Settings::EMAIL_SEND_DEFAULT);
$settings->setLastSendId(0);
$settings->setNextSendTime(1);

$this->settingsMapper->method('getUsersByNextSendTime')
->willReturn([$settings]);
$this->userConfig->method('getValuesByUsers')
->willReturn([]);
$this->appConfig->method('getAppValueInt')
->with('setting_batchtime')
->willReturn(Settings::EMAIL_SEND_OFF);
$this->systemConfig->method('getSystemValueString')
->willReturn('');

$this->handler->expects($this->never())
->method('getAfterId');
$this->mailer->expects($this->never())
->method('send');
$this->settingsMapper->expects($this->once())
->method('update')
->with($settings);

$this->mailNotifications->sendEmails(MailNotifications::BATCH_SIZE_WEB, 2000);

$this->assertSame(0, $settings->getNextSendTime());
}
}
Loading