From 7f62272a741437a22af4de89c10f9087b7e39d15 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Thu, 21 Mar 2024 16:07:04 +0000
Subject: [PATCH] remove calendar date assignments when removing users from a
 date, fixes #3854

Closes #3854

Merge request studip/studip!2724
---
 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