aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorhamza221 <hamzamahjoubi221@gmail.com>2023-11-24 17:45:32 +0100
committerHamza Mahjoubi <hamzamahjoubi221@gmail.com>2024-08-13 11:47:03 +0200
commit67957e98b97ba89905de168aab477ae476ed3b52 (patch)
tree1581cfc902fa14451148c7f2fe019a20beedeb4a /apps
parent6d19c48413c932c24d14c201aca9f05fd1b304ad (diff)
downloadnextcloud-server-67957e98b97ba89905de168aab477ae476ed3b52.tar.gz
nextcloud-server-67957e98b97ba89905de168aab477ae476ed3b52.zip
fix: handle-duplicate-reminder
Signed-off-by: hamza221 <hamzamahjoubi221@gmail.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/CalDAV/Reminder/Backend.php5
-rw-r--r--apps/dav/lib/CalDAV/Reminder/ReminderService.php7
-rw-r--r--apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php4
3 files changed, 12 insertions, 4 deletions
diff --git a/apps/dav/lib/CalDAV/Reminder/Backend.php b/apps/dav/lib/CalDAV/Reminder/Backend.php
index ce4469228d3..a4f3c7c6e12 100644
--- a/apps/dav/lib/CalDAV/Reminder/Backend.php
+++ b/apps/dav/lib/CalDAV/Reminder/Backend.php
@@ -44,11 +44,12 @@ class Backend {
*/
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(
diff --git a/apps/dav/lib/CalDAV/Reminder/ReminderService.php b/apps/dav/lib/CalDAV/Reminder/ReminderService.php
index 617e71d6d26..be81e534dd3 100644
--- a/apps/dav/lib/CalDAV/Reminder/ReminderService.php
+++ b/apps/dav/lib/CalDAV/Reminder/ReminderService.php
@@ -444,7 +444,14 @@ class ReminderService {
* @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'],
diff --git a/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php b/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php
index ffba1a2fc96..9900c77bf54 100644
--- a/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php
@@ -127,7 +127,7 @@ class BackendTest extends TestCase {
'is_recurrence_exception' => false,
'event_hash' => 'asd123',
'alarm_hash' => 'asd567',
- 'type' => 'EMAIL',
+ 'type' => 'AUDIO',
'is_relative' => true,
'notification_date' => 123456,
'is_repeat_based' => false,
@@ -144,7 +144,7 @@ class BackendTest extends TestCase {
'is_recurrence_exception' => false,
'event_hash' => 'asd123',
'alarm_hash' => 'asd567',
- 'type' => 'AUDIO',
+ 'type' => 'EMAIL',
'is_relative' => true,
'notification_date' => 123456,
'is_repeat_based' => false,