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-03 12:34:39 +0100
commit1b834cacadf469b50afdba197b7fec502e1fd93d (patch)
treef2aa337786d9dc4596fdafe987a2ea8f0e35fbb3
parent599d79f0424dcf66b95a54ae958191037b60ffdb (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 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',