Skip to content

Commit 2df2fb3

Browse files
committed
Fix/handle-duplicate-reminder
Signed-off-by: hamza221 <hamzamahjoubi221@gmail.com>
1 parent 6a0edef commit 2df2fb3

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
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'])
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');
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'];
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: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ public function testGetRemindersToProcess(): void {
114114

115115
$rows = $this->reminderBackend->getRemindersToProcess();
116116

117-
$this->assertCount(2, $rows);
117+
$this->assertCount(1, $rows);
118118
unset($rows[0]['id']);
119-
unset($rows[1]['id']);
120119

121120
$this->assertEquals($rows[0], [
122121
'calendar_id' => 1,
@@ -135,25 +134,7 @@ public function testGetRemindersToProcess(): void {
135134
'displayname' => 'Displayname 123',
136135
'principaluri' => 'principals/users/user001',
137136
]);
138-
$this->assertEquals($rows[1], [
139-
'calendar_id' => 1,
140-
'object_id' => 1,
141-
'uid' => 'asd',
142-
'is_recurring' => false,
143-
'recurrence_id' => 123458,
144-
'is_recurrence_exception' => false,
145-
'event_hash' => 'asd123',
146-
'alarm_hash' => 'asd567',
147-
'type' => 'AUDIO',
148-
'is_relative' => true,
149-
'notification_date' => 123456,
150-
'is_repeat_based' => false,
151-
'calendardata' => 'Calendar data 123',
152-
'displayname' => 'Displayname 123',
153-
'principaluri' => 'principals/users/user001',
154-
]);
155137
}
156-
157138
public function testGetAllScheduledRemindersForEvent(): void {
158139
$rows = $this->reminderBackend->getAllScheduledRemindersForEvent(1);
159140

0 commit comments

Comments
 (0)