Skip to content

Commit cee227a

Browse files
authored
Merge pull request #41740 from nextcloud/Fix/duplicate-reminders
fix(dav): Handle duplicate event reminder
2 parents 142b6e3 + 67957e9 commit cee227a

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

apps/dav/lib/CalDAV/Reminder/Backend.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ public function __construct(IDBConnection $db,
4444
*/
4545
public function getRemindersToProcess():array {
4646
$query = $this->db->getQueryBuilder();
47-
$query->select(['cr.*', 'co.calendardata', 'c.displayname', 'c.principaluri'])
47+
$query->select(['cr.*', 'co.calendardata', 'c.displayname', 'c.principaluri','cr.notification_date', 'cr.event_hash', 'cr.type'])
4848
->from('calendar_reminders', 'cr')
4949
->where($query->expr()->lte('cr.notification_date', $query->createNamedParameter($this->timeFactory->getTime())))
5050
->join('cr', 'calendarobjects', 'co', $query->expr()->eq('cr.object_id', 'co.id'))
51-
->join('cr', 'calendars', 'c', $query->expr()->eq('cr.calendar_id', 'c.id'));
51+
->join('cr', 'calendars', 'c', $query->expr()->eq('cr.calendar_id', 'c.id'))
52+
->groupBy('cr.event_hash', 'cr.notification_date', 'cr.type');
5253
$stmt = $query->execute();
5354

5455
return array_map(

apps/dav/lib/CalDAV/Reminder/ReminderService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,14 @@ private function getRemindersForVAlarm(VAlarm $valarm,
444444
* @param array $reminders
445445
*/
446446
private function writeRemindersToDatabase(array $reminders): void {
447+
$uniqueReminders = [];
447448
foreach ($reminders as $reminder) {
449+
$key = $reminder['notification_date']. $reminder['event_hash'].$reminder['type'];
450+
if(!isset($uniqueReminders[$key])) {
451+
$uniqueReminders[$key] = $reminder;
452+
}
453+
}
454+
foreach (array_values($uniqueReminders) as $reminder) {
448455
$this->backend->insertReminder(
449456
(int) $reminder['calendar_id'],
450457
(int) $reminder['object_id'],

apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function testGetRemindersToProcess(): void {
127127
'is_recurrence_exception' => false,
128128
'event_hash' => 'asd123',
129129
'alarm_hash' => 'asd567',
130-
'type' => 'EMAIL',
130+
'type' => 'AUDIO',
131131
'is_relative' => true,
132132
'notification_date' => 123456,
133133
'is_repeat_based' => false,
@@ -144,7 +144,7 @@ public function testGetRemindersToProcess(): void {
144144
'is_recurrence_exception' => false,
145145
'event_hash' => 'asd123',
146146
'alarm_hash' => 'asd567',
147-
'type' => 'AUDIO',
147+
'type' => 'EMAIL',
148148
'is_relative' => true,
149149
'notification_date' => 123456,
150150
'is_repeat_based' => false,

0 commit comments

Comments
 (0)