From 1b834cacadf469b50afdba197b7fec502e1fd93d Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms Date: Mon, 3 Nov 2025 12:34:39 +0100 Subject: prevent fatal error when booking user is missing, fixes #6012 Closes #6012 Merge request studip/studip!4588 --- db/migrations/5.4.21_cleanup_consultation_bookings.php | 17 +++++++++++++++++ lib/models/ConsultationBooking.php | 12 ++++++++++++ lib/models/ConsultationSlot.php | 1 + 3 files changed, 30 insertions(+) create mode 100644 db/migrations/5.4.21_cleanup_consultation_bookings.php diff --git a/db/migrations/5.4.21_cleanup_consultation_bookings.php b/db/migrations/5.4.21_cleanup_consultation_bookings.php new file mode 100644 index 0000000..3c7d9f7 --- /dev/null +++ b/db/migrations/5.4.21_cleanup_consultation_bookings.php @@ -0,0 +1,17 @@ +exec($query); + } +} diff --git a/lib/models/ConsultationBooking.php b/lib/models/ConsultationBooking.php index 026e727..4f77c7c 100644 --- a/lib/models/ConsultationBooking.php +++ b/lib/models/ConsultationBooking.php @@ -113,6 +113,18 @@ class ConsultationBooking extends SimpleORMap implements PrivacyObject } /** + * @return self[] + */ + public static function findValidBySlot_id(int $slot_id): array + { + return self::findBySQL( + 'JOIN auth_user_md5 USING (user_id) + WHERE slot_id = ?', + [$slot_id] + ); + } + + /** * Returns whether a user may create a booking for the given range. * * @param User $user diff --git a/lib/models/ConsultationSlot.php b/lib/models/ConsultationSlot.php index c7aa78e..fe8c21b 100644 --- a/lib/models/ConsultationSlot.php +++ b/lib/models/ConsultationSlot.php @@ -41,6 +41,7 @@ class ConsultationSlot extends SimpleORMap ]; $config['has_many']['bookings'] = [ 'class_name' => ConsultationBooking::class, + 'assoc_func' => 'findValidBySlot_id', 'assoc_foreign_key' => 'slot_id', 'on_store' => 'store', 'on_delete' => 'delete', -- cgit v1.0