From 218fd2a4452e1214f0254ac6fbf1dca1c6f78118 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Thu, 9 Feb 2023 16:32:38 +0000
Subject: [PATCH] remove course notifications as well when deleting user and
 cleanup table via migration, fixes #2141

Closes #2141

Merge request studip/studip!1389
---
 ....41_cleanup_seminar_user_notifications.php | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 db/migrations/5.1.41_cleanup_seminar_user_notifications.php

diff --git a/db/migrations/5.1.41_cleanup_seminar_user_notifications.php b/db/migrations/5.1.41_cleanup_seminar_user_notifications.php
new file mode 100644
index 00000000000..6279ac7b29f
--- /dev/null
+++ b/db/migrations/5.1.41_cleanup_seminar_user_notifications.php
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * @see https://gitlab.studip.de/studip/studip/-/issues/2141
+ */
+final class CleanupSeminarUserNotifications extends Migration
+{
+    public function description()
+    {
+        return "Removes all entries from `seminar_user_notifications` that are not in `seminar_user` as well";
+    }
+
+    protected function up()
+    {
+        $query = "DELETE `seminar_user_notifications`
+                          FROM `seminar_user_notifications`
+                          LEFT JOIN `seminar_user` USING(`user_id`, `Seminar_id`)
+                          WHERE `seminar_user`.`user_id` IS NULL";
+        DBManager::get()->exec($query);
+    }
+}
-- 
GitLab