From 899e312e3b56124c249e43236e266213cc7a0c59 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Fri, 15 Jul 2022 10:24:41 +0000
Subject: [PATCH] migration 1.271: convert all num attributes (except "seats")
 to text, closes #269

Closes #269

Merge request studip/studip!799
---
 .../1.271_room_management_migration.php        | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/db/migrations/1.271_room_management_migration.php b/db/migrations/1.271_room_management_migration.php
index 8fd748b06b7..8edb1903a09 100644
--- a/db/migrations/1.271_room_management_migration.php
+++ b/db/migrations/1.271_room_management_migration.php
@@ -618,6 +618,8 @@ class RoomManagementMigration extends Migration
             WHERE property_id = :property_id;"
         );
 
+        $changed_property_ids = [];
+
         $properties_to_be_modified = $GLOBALS['RESOURCE_PROPERTIES_TO_BE_MODIFIED'];
         foreach ($properties_to_be_modified as $old_name => $data) {
             //Check if the old property exists:
@@ -740,6 +742,8 @@ class RoomManagementMigration extends Migration
                 }
             }
 
+            $changed_property_ids[] = $final_property_id;
+
             if ($duplicate_ids) {
                 $this->write(
                     sprintf(
@@ -815,6 +819,20 @@ class RoomManagementMigration extends Migration
             );
         }
 
+        //All old properties of type "num" that have not been modified yet
+        //and which are not the "seats" property will be converted to the
+        //type "text" so that they continue to be represented in a text input
+        //instead of being represented in a number input:
+        $num_to_text_stmt = $db->prepare(
+            "UPDATE `resource_property_definitions`
+            SET `type` = 'text'
+            WHERE
+            `type` = 'num'
+            AND `name` <> 'seats'
+            AND `property_id` NOT IN ( :changed_property_ids )"
+        );
+        $num_to_text_stmt->execute(['changed_property_ids' => $changed_property_ids]);
+
         $this->write(
             'Finished migrating existing properties.'
         );
-- 
GitLab