diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2024-04-30 12:09:43 +0000 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2024-04-30 15:13:42 +0200 |
| commit | b2f3bad52dd6dec973bef54d2f10986015848702 (patch) | |
| tree | d00f76496f5be59061ba6ec24ba4226016c59970 /db/migrations | |
| parent | ab9f954c3e304ec1c970ac8220f318b84e65f2d1 (diff) | |
cleanup blubber and delete correctly, fixes #4097
Closes #4097
Merge request studip/studip!2943
Diffstat (limited to 'db/migrations')
| -rw-r--r-- | db/migrations/5.1.56_cleanup_blubber.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/db/migrations/5.1.56_cleanup_blubber.php b/db/migrations/5.1.56_cleanup_blubber.php new file mode 100644 index 0000000..86348bc --- /dev/null +++ b/db/migrations/5.1.56_cleanup_blubber.php @@ -0,0 +1,46 @@ +<?php +/** + * @see https://gitlab.studip.de/studip/studip/-/issues/4097 + */ +return new class extends Migration +{ + public function description() + { + return 'Removes orhpaned blubber entries'; + } + + protected function up() + { + $query = "DELETE bt, ouv + FROM `blubber_threads` AS bt + LEFT JOIN `object_user_visits` AS ouv + ON (bt.`thread_id` = ouv.`object_id`) + WHERE bt.`external_contact` = 0 + AND bt.`user_id` NOT IN ( + SELECT `user_id` FROM `auth_user_md5` + )"; + DBManager::get()->exec($query); + + $query = "DELETE FROM `blubber_comments` + WHERE ( + `external_contact` = 0 + AND `user_id` NOT IN ( + SELECT `user_id` FROM `auth_user_md5` + ) + ) OR `thread_id` NOT IN ( + SELECT `thread_id` FROM `blubber_threads` + )"; + DBManager::get()->exec($query); + + $query = "DELETE FROM `blubber_mentions` + WHERE ( + `external_contact` = 0 + AND `user_id` NOT IN ( + SELECT `user_id` FROM `auth_user_md5` + ) + ) OR `thread_id` NOT IN ( + SELECT `thread_id` FROM `blubber_threads` + )"; + DBManager::get()->exec($query); + } +}; |
