Skip to content

Commit e5a3d97

Browse files
Merge pull request #3118 from nextcloud/backport/3078/stable32
[stable32] fix(email): Correctly initialize next_send_time field
2 parents 1ffc913 + 1803ba0 commit e5a3d97

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

lib/BackgroundJob/GenerateUserSettings.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use OCA\Notifications\Model\Settings;
1212
use OCA\Notifications\Model\SettingsMapper;
13+
use OCP\AppFramework\Services\IAppConfig;
1314
use OCP\AppFramework\Utility\ITimeFactory;
1415
use OCP\BackgroundJob\TimedJob;
1516
use OCP\IDBConnection;
@@ -22,6 +23,7 @@ public function __construct(
2223
private IDBConnection $connection,
2324
private IUserManager $userManager,
2425
private SettingsMapper $settingsMapper,
26+
private IAppConfig $appConfig,
2527
) {
2628
parent::__construct($time);
2729

@@ -31,6 +33,18 @@ public function __construct(
3133

3234
#[\Override]
3335
protected function run($argument): void {
36+
$update = $this->connection->getQueryBuilder();
37+
$update->update('notifications_settings')
38+
->set('next_send_time', $update->createNamedParameter(1))
39+
->where($update->expr()->eq('next_send_time', $update->createNamedParameter(0)))
40+
->andWhere($update->expr()->neq('batch_time', $update->createNamedParameter(Settings::EMAIL_SEND_OFF)));
41+
42+
$batchTime = $this->appConfig->getAppValueInt('setting_batchtime');
43+
if ($batchTime === Settings::EMAIL_SEND_OFF) {
44+
$update->andWhere($update->expr()->neq('batch_time', $update->createNamedParameter(Settings::EMAIL_SEND_DEFAULT)));
45+
}
46+
$update->executeStatement();
47+
3448
$query = $this->connection->getQueryBuilder();
3549
$query->select('notification_id')
3650
->from('notifications')
@@ -42,7 +56,7 @@ protected function run($argument): void {
4256
$result->closeCursor();
4357

4458
$this->userManager->callForSeenUsers(function (IUser $user) use ($maxId): void {
45-
if ($user->isEnabled()) {
59+
if (!$user->isEnabled()) {
4660
return;
4761
}
4862

lib/Model/SettingsMapper.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use OCP\AppFramework\Db\DoesNotExistException;
1212
use OCP\AppFramework\Db\QBMapper;
13+
use OCP\AppFramework\Services\IAppConfig;
1314
use OCP\DB\Exception as DBException;
1415
use OCP\DB\QueryBuilder\IQueryBuilder;
1516
use OCP\IDBConnection;
@@ -22,7 +23,10 @@
2223
* @method list<Settings> findEntities(IQueryBuilder $query)
2324
*/
2425
class SettingsMapper extends QBMapper {
25-
public function __construct(IDBConnection $db) {
26+
public function __construct(
27+
IDBConnection $db,
28+
protected readonly IAppConfig $appConfig,
29+
) {
2630
parent::__construct($db, 'notifications_settings', Settings::class);
2731
}
2832

@@ -43,6 +47,10 @@ public function getSettingsByUser(string $userId): Settings {
4347
$settings = new Settings();
4448
$settings->setUserId($userId);
4549
$settings->setBatchTime(Settings::EMAIL_SEND_DEFAULT);
50+
$batchTime = $this->appConfig->getAppValueInt('setting_batchtime');
51+
if ($batchTime !== Settings::EMAIL_SEND_OFF) {
52+
$settings->setNextSendTime(1);
53+
}
4654
/** @var Settings $settings */
4755
$settings = $this->insert($settings);
4856

lib/Settings/Personal.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ public function getForm(): TemplateResponse {
4848
$settingBatchTime = $this->appConfig->getAppValueInt('setting_batchtime');
4949
}
5050
} catch (DoesNotExistException) {
51+
$settingBatchTime = $this->appConfig->getAppValueInt('setting_batchtime');
52+
5153
$settings = new Settings();
5254
$settings->setUserId($user->getUID());
5355
$settings->setBatchTime(Settings::EMAIL_SEND_DEFAULT);
54-
$settings->setNextSendTime(1);
56+
if ($settingBatchTime !== Settings::EMAIL_SEND_OFF) {
57+
$settings->setNextSendTime(1);
58+
}
5559
$this->settingsMapper->insert($settings);
56-
57-
$settingBatchTime = $this->appConfig->getAppValueInt('setting_batchtime');
5860
}
5961

6062
$defaultSoundNotification = $this->appConfig->getAppValueBool('sound_notification') ? 'yes' : 'no';

0 commit comments

Comments
 (0)