From f50ce7dbefeab812f1a297923a55c13b373cfe6b Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Thu, 17 Feb 2022 12:48:13 +0100
Subject: [PATCH] SingleCalendar::deleteEventWithConsultation: count other
 consultation events before cancelling all bookings

---
 lib/classes/calendar/SingleCalendar.php | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/classes/calendar/SingleCalendar.php b/lib/classes/calendar/SingleCalendar.php
index ee467fb7989..8aa0ac69fd5 100644
--- a/lib/classes/calendar/SingleCalendar.php
+++ b/lib/classes/calendar/SingleCalendar.php
@@ -579,7 +579,15 @@ class SingleCalendar
             if ($consultation_event) {
                 //Check if the slot is empty and delete it, if so.
                 if ($consultation_event->slot) {
-                    if (empty($consultation_event->slot->events)) {
+                    //Count other consultation events:
+                    $other_event_c = ConsultationEvent::countBySql(
+                        'slot_id = :slot_id AND event_id <> :event_id',
+                        [
+                            'slot_id' => $consultation_event->slot->id,
+                            'event_id' => $consultation_event->event_id
+                        ]
+                    );
+                    if ($other_event_c == 0) {
                         foreach ($consultation_event->slot->bookings as $booking) {
                             $booking->cancel();
                         }
-- 
GitLab