From 89c22235d164ba99b5a7ec68161bb9b9d4e97634 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 | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/models/ConsultationSlot.php b/lib/models/ConsultationSlot.php index 63c730aa9cd..546f72f4f57 100644 --- a/lib/models/ConsultationSlot.php +++ b/lib/models/ConsultationSlot.php @@ -204,11 +204,19 @@ class ConsultationSlot extends SimpleORMap // If no range is associated, remove the event if (!$this->block->range) { - return $this->removeEvent(); + $this->removeEvent(); + return; } - if (count($this->bookings) === 0 && !$this->block->calendar_events) { - return $this->removeEvent(); + $bookings = $this->bookings->filter(function (ConsultationBooking $booking) { + return !$booking->isDeleted() + && $booking->user; + }); + + + if (count($bookings) === 0 && !$this->block->calendar_events) { + $this->removeEvent(); + return; } $event = $this->event; @@ -221,11 +229,11 @@ class ConsultationSlot extends SimpleORMap setTempLanguage($this->block->range_id); - if (count($this->bookings) > 0) { + if (count($bookings) > 0) { $event->category_intern = 1; - if (count($this->bookings) === 1) { - $booking = $this->bookings->first(); + if (count($bookings) === 1) { + $booking = $bookings->first(); $event->summary = sprintf( _('Termin mit %s'), @@ -235,9 +243,9 @@ class ConsultationSlot extends SimpleORMap } else { $event->summary = sprintf( _('Termin mit %u Personen'), - count($this->bookings) + count($bookings) ); - $event->description = implode("\n\n----\n\n", $this->bookings->map(function ($booking) { + $event->description = implode("\n\n----\n\n", $bookings->map(function ($booking) { return "- {$booking->user->getFullName()}:\n{$booking->reason}"; })); } -- GitLab