aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2025-11-03 12:34:39 +0100
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2025-11-20 16:09:43 +0100
commitf7efb1ff6d659118acec92d92bb363675d71ec48 (patch)
tree46efd68d79266d30361ac38987e4af61c00df653
parent72a65f6b341ccb5ce1bc751bc25c4650aaccddff (diff)
prevent fatal error when booking user is missing, fixes #6012
Closes #6012 Merge request studip/studip!4588
-rw-r--r--db/migrations/5.4.21_cleanup_consultation_bookings.php17
-rw-r--r--lib/models/ConsultationBooking.php12
-rw-r--r--lib/models/ConsultationSlot.php1
3 files changed, 30 insertions, 0 deletions
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 @@
+<?php
+final class CleanupConsultationBookings extends Migration
+{
+ public function description()
+ {
+ return 'Removes orphaned entries from consultation_bookings';
+ }
+
+ protected function up()
+ {
+ $query = "DELETE `consultation_bookings`
+ FROM `consultation_bookings`
+ LEFT JOIN `auth_user_md5` USING (`user_id`)
+ WHERE `auth_user_md5`.`user_id` IS NULL";
+ DBManager::get()->exec($query);
+ }
+}
diff --git a/lib/models/ConsultationBooking.php b/lib/models/ConsultationBooking.php
index 1903249..d93a372 100644
--- a/lib/models/ConsultationBooking.php
+++ b/lib/models/ConsultationBooking.php
@@ -95,6 +95,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 ab1dfa7..30b3a95 100644
--- a/lib/models/ConsultationSlot.php
+++ b/lib/models/ConsultationSlot.php
@@ -31,6 +31,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',