From 67a761ccb55c3ef65054bc6202cbf0a6ddd86437 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Thu, 21 Mar 2024 10:43:27 +0100
Subject: [PATCH] remove calendar date assignments when removing users from a
 date

---
 app/controllers/calendar/date.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/app/controllers/calendar/date.php b/app/controllers/calendar/date.php
index 755ef97509a..cd876ed76f4 100644
--- a/app/controllers/calendar/date.php
+++ b/app/controllers/calendar/date.php
@@ -565,6 +565,14 @@ class Calendar_DateController extends AuthenticatedController
                     $assignment->store();
                 }
             }
+            //Remove the date from calendars that are not in the $valid_assigned_calendar_ids array:
+            CalendarDateAssignment::deleteBySQL(
+                '`range_id` NOT IN ( :assigned_calendar_ids ) AND `calendar_date_id` = :calendar_date_id',
+                [
+                    'assigned_calendar_ids' => $valid_assigned_calendar_ids,
+                    'calendar_date_id'      => $this->date->id
+                ]
+            );
 
             //Clear all exceptions for the event and set them again:
             CalendarDateException::deleteByCalendar_date_id($this->date->id);
-- 
GitLab