From d205fc6aaee6d3d8173efb15c8d364f410a02a41 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Wed, 22 Mar 2023 16:04:54 +0000
Subject: [PATCH] remove obsolete old configuration entries, fixes #2423

Closes #2423

Merge request studip/studip!1618
---
 app/routes/Events.php                         |  6 +--
 .../1.271_room_management_migration.php       | 32 ---------------
 ...44_cleanup_old_resource_configurations.php | 40 +++++++++++++++++++
 3 files changed, 41 insertions(+), 37 deletions(-)
 create mode 100644 db/migrations/5.1.44_cleanup_old_resource_configurations.php

diff --git a/app/routes/Events.php b/app/routes/Events.php
index 38caa14bcb3..03028268046 100644
--- a/app/routes/Events.php
+++ b/app/routes/Events.php
@@ -165,11 +165,7 @@ class Events extends \RESTAPI\RouteMap
                     }
                 }
             } else {
-                if (Config::get()->RESOURCES_SHOW_ROOM_NOT_BOOKED_HINT) {
-                    $room = '('._("kein gebuchter Raum").')';
-                } else {
-                    $room = _("keine Raumangabe");
-                }
+                $room = _("keine Raumangabe");
 
                 if ($val->isExTermin()) {
                     if ($name = $val->isHoliday()) {
diff --git a/db/migrations/1.271_room_management_migration.php b/db/migrations/1.271_room_management_migration.php
index 8edb1903a09..725360dad7d 100644
--- a/db/migrations/1.271_room_management_migration.php
+++ b/db/migrations/1.271_room_management_migration.php
@@ -1106,38 +1106,6 @@ class RoomManagementMigration extends Migration
         );
     }
 
-
-    public function removeObsoleteConfigEntries(PDO $db)
-    {
-        $entries = [
-            'RESOURCES_ALLOW_CREATE_ROOMS',
-            'RESOURCES_ALLOW_CREATE_TOP_LEVEL',
-            'RESOURCES_ALLOW_DELETE_REQUESTS',
-            'RESOURCES_ALLOW_REQUESTABLE_ROOM_REQUESTS',
-            'RESOURCES_ALLOW_ROOM_REQUESTS_ALL_ROOMS',
-            'RESOURCES_ENABLE_GROUPING',
-            'RESOURCES_ENABLE_ORGA_CLASSIFY',
-            'RESOURCES_ENABLE_SEM_SCHEDULE',
-            'RESOURCES_ENABLE_VIRTUAL_ROOM_GROUPS',
-            'RESOURCES_HIDE_PAST_SINGLE_DATES',
-            'RESOURCES_INHERITANCE_PERMS',
-            'RESOURCES_INHERITANCE_PERMS_ROOMS',
-            'RESOURCES_LOCKING_ACTIVE',
-            'RESOURCES_ROOM_REQUEST_DEFAULT_ACTION',
-            'RESOURCES_SCHEDULE_EXPLAIN_USER_NAME',
-            'RESOURCES_SEARCH_ONLY_REQUESTABLE_PROPERTY',
-            'RESOURCES_SHOW_ROOM_NOT_BOOKED_HINT',
-            'RESOURCES_ENABLE_ORGA_ADMIN_NOTICE'
-        ];
-
-        $stmt = $db->prepare(
-            'DELETE FROM config WHERE field IN ( :entries );'
-        );
-
-        $stmt->execute(['entries' => $entries]);
-    }
-
-
     public function createPropertyGroups(PDO $db)
     {
         $get_group_id_stmt = $db->prepare(
diff --git a/db/migrations/5.1.44_cleanup_old_resource_configurations.php b/db/migrations/5.1.44_cleanup_old_resource_configurations.php
new file mode 100644
index 00000000000..1a12cf3f09e
--- /dev/null
+++ b/db/migrations/5.1.44_cleanup_old_resource_configurations.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * @see https://gitlab.studip.de/studip/studip/-/issues/2423
+ */
+final class CleanupOldResourceConfigurations extends Migration
+{
+    public function description()
+    {
+        return 'Removes obsolete configuration entries from old resource management';
+    }
+
+    protected function up()
+    {
+        $query = "DELETE `config`, `config_values`
+                  FROM `config`
+                  LEFT JOIN `config_values` USING (`field`)
+                  WHERE `field` IN (
+                      'RESOURCES_ALLOW_CREATE_ROOMS',
+                      'RESOURCES_ALLOW_CREATE_TOP_LEVEL',
+                      'RESOURCES_ALLOW_DELETE_REQUESTS',
+                      'RESOURCES_ALLOW_REQUESTABLE_ROOM_REQUESTS',
+                      'RESOURCES_ALLOW_ROOM_REQUESTS_ALL_ROOMS',
+                      'RESOURCES_ENABLE_GROUPING',
+                      'RESOURCES_ENABLE_ORGA_CLASSIFY',
+                      'RESOURCES_ENABLE_SEM_SCHEDULE',
+                      'RESOURCES_ENABLE_VIRTUAL_ROOM_GROUPS',
+                      'RESOURCES_HIDE_PAST_SINGLE_DATES',
+                      'RESOURCES_INHERITANCE_PERMS',
+                      'RESOURCES_INHERITANCE_PERMS_ROOMS',
+                      'RESOURCES_LOCKING_ACTIVE',
+                      'RESOURCES_ROOM_REQUEST_DEFAULT_ACTION',
+                      'RESOURCES_SCHEDULE_EXPLAIN_USER_NAME',
+                      'RESOURCES_SEARCH_ONLY_REQUESTABLE_PROPERTY',
+                      'RESOURCES_SHOW_ROOM_NOT_BOOKED_HINT',
+                      'RESOURCES_ENABLE_ORGA_ADMIN_NOTICE'
+                  )";
+        DBManager::get()->exec($query);
+    }
+}
-- 
GitLab