Skip to content

Commit

Permalink
fix: handle-duplicate-reminder
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <hamzamahjoubi221@gmail.com>
  • Loading branch information
hamza221 committed Aug 1, 2024
1 parent 6a0edef commit 83ca989
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions apps/dav/lib/CalDAV/Reminder/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public function __construct(IDBConnection $db,
*/
public function getRemindersToProcess():array {
$query = $this->db->getQueryBuilder();
$query->select(['cr.*', 'co.calendardata', 'c.displayname', 'c.principaluri'])
$query->select(['cr.*', 'co.calendardata', 'c.displayname', 'c.principaluri','cr.notification_date', 'cr.event_hash', 'cr.type'])
->from('calendar_reminders', 'cr')
->where($query->expr()->lte('cr.notification_date', $query->createNamedParameter($this->timeFactory->getTime())))
->join('cr', 'calendarobjects', 'co', $query->expr()->eq('cr.object_id', 'co.id'))
->join('cr', 'calendars', 'c', $query->expr()->eq('cr.calendar_id', 'c.id'));
->join('cr', 'calendars', 'c', $query->expr()->eq('cr.calendar_id', 'c.id'))
->groupBy('cr.event_hash', 'cr.notification_date', 'cr.type');
$stmt = $query->execute();

return array_map(
Expand Down
7 changes: 7 additions & 0 deletions apps/dav/lib/CalDAV/Reminder/ReminderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,14 @@ private function getRemindersForVAlarm(VAlarm $valarm,
* @param array $reminders
*/
private function writeRemindersToDatabase(array $reminders): void {
$uniqueReminders = [];
foreach ($reminders as $reminder) {
$key = $reminder['notification_date']. $reminder['event_hash'].$reminder['type'];
if(!isset($uniqueReminders[$key])) {
$uniqueReminders[$key] = $reminder;
}
}
foreach (array_values($uniqueReminders) as $reminder) {
$this->backend->insertReminder(
(int) $reminder['calendar_id'],
(int) $reminder['object_id'],
Expand Down
7 changes: 3 additions & 4 deletions apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function testGetRemindersToProcess(): void {
->method('getTime')
->with()
->willReturn(123457);

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

$this->assertCount(2, $rows);
Expand All @@ -127,7 +127,7 @@ public function testGetRemindersToProcess(): void {
'is_recurrence_exception' => false,
'event_hash' => 'asd123',
'alarm_hash' => 'asd567',
'type' => 'EMAIL',
'type' => 'AUDIO',
'is_relative' => true,
'notification_date' => 123456,
'is_repeat_based' => false,
Expand All @@ -144,7 +144,7 @@ public function testGetRemindersToProcess(): void {
'is_recurrence_exception' => false,
'event_hash' => 'asd123',
'alarm_hash' => 'asd567',
'type' => 'AUDIO',
'type' => 'EMAIL',
'is_relative' => true,
'notification_date' => 123456,
'is_repeat_based' => false,
Expand All @@ -153,7 +153,6 @@ public function testGetRemindersToProcess(): void {
'principaluri' => 'principals/users/user001',
]);
}

public function testGetAllScheduledRemindersForEvent(): void {
$rows = $this->reminderBackend->getAllScheduledRemindersForEvent(1);

Expand Down

0 comments on commit 83ca989

Please sign in to comment.