From 2349a13829f6595dd20146f0a1e723b9e1100925 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Tue, 12 Jul 2022 13:22:56 +0000
Subject: [PATCH] ensure booking is valid before updating event, fixes #1300

Closes #1300

Merge request studip/studip!798
---
 lib/models/ConsultationSlot.php | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/models/ConsultationSlot.php b/lib/models/ConsultationSlot.php
index 51d28d270f4..aac384c6677 100644
--- a/lib/models/ConsultationSlot.php
+++ b/lib/models/ConsultationSlot.php
@@ -241,11 +241,16 @@ class ConsultationSlot extends SimpleORMap
         foreach ($this->events as $event) {
             setTempLanguage($event->user_id);
 
-            if (count($this->bookings) > 0) {
+            $bookings = $this->bookings->filter(function (ConsultationBooking $booking) {
+                return !$booking->isDeleted()
+                    && $booking->user;
+            });
+
+            if (count($bookings) > 0) {
                 $event->event->category_intern = 1;
 
-                if (count($this->bookings) === 1) {
-                    $booking = $this->bookings->first();
+                if (count($bookings) === 1) {
+                    $booking = $bookings->first();
 
                     $event->event->summary = sprintf(
                         _('Termin mit %s'),
@@ -255,9 +260,9 @@ class ConsultationSlot extends SimpleORMap
                 } else {
                     $event->event->summary = sprintf(
                         _('Termin mit %u Personen'),
-                        count($this->bookings)
+                        count($bookings)
                     );
-                    $event->event->description = implode("\n\n----\n\n", $this->bookings->map(function ($booking) {
+                    $event->event->description = implode("\n\n----\n\n", $bookings->map(function ($booking) {
                         return "- {$booking->user->getFullName()}:\n{$booking->reason}";
                     }));
                 }
-- 
GitLab