From 7fa9d327ef55a955de444f315e99801da6e3e234 Mon Sep 17 00:00:00 2001 From: iszmais Date: Fri, 9 Oct 2026 13:00:48 +0200 Subject: [PATCH] migrate dc multiselect value to string arrays --- ...lDataCollectionSelectionFieldMigration.php | 92 +++++++++++++++++++ .../class.ilDataCollectionSetupAgent.php | 3 +- 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSelectionFieldMigration.php diff --git a/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSelectionFieldMigration.php b/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSelectionFieldMigration.php new file mode 100644 index 000000000000..5cb1957f42aa --- /dev/null +++ b/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSelectionFieldMigration.php @@ -0,0 +1,92 @@ +db = $environment->getResource(Environment::RESOURCE_DATABASE); + } + + public function step(Environment $environment): void + { + $stmt = $this->db->queryF( + 'SELECT il_dcl_stloc1_value.* FROM il_dcl_stloc1_value ' . + 'INNER JOIN il_dcl_record_field on il_dcl_record_field.id = il_dcl_stloc1_value.record_field_id ' . + 'INNER JOIN il_dcl_field ON il_dcl_field.id = il_dcl_record_field.field_id ' . + 'WHERE (datatype_id = %s OR datatype_id = %s) AND value LIKE %s AND value NOT LIKE %s AND value != "[]"', + [ilDBConstants::T_INTEGER, ilDBConstants::T_INTEGER, ilDBConstants::T_TEXT, ilDBConstants::T_TEXT], + [ilDclDatatype::INPUTFORMAT_TEXT_SELECTION, ilDclDatatype::INPUTFORMAT_DATE_SELECTION, '[%', '["%'] + ); + + while ($row = $this->db->fetchAssoc($stmt)) { + $old_values = json_decode($row['value']); + $new_values = []; + foreach ($old_values as $old_value) { + $new_values[] = (string) $old_value; + } + $this->db->update( + 'il_dcl_stloc1_value', + ['value' => [ilDBConstants::T_TEXT, json_encode($new_values)]], + ['id' => [ilDBConstants::T_INTEGER, $row['id']]] + ); + } + } + + public function getRemainingAmountOfSteps(): int + { + $legacy_file_field_amount = $this->db->fetchObject( + $this->db->queryF( + 'SELECT COUNT(il_dcl_stloc1_value.id) AS amount FROM il_dcl_stloc1_value ' . + 'INNER JOIN il_dcl_record_field on il_dcl_record_field.id = il_dcl_stloc1_value.record_field_id ' . + 'INNER JOIN il_dcl_field ON il_dcl_field.id = il_dcl_record_field.field_id ' . + 'WHERE (datatype_id = %s OR datatype_id = %s) AND value LIKE %s AND value NOT LIKE %s AND value != "[]"', + [ilDBConstants::T_INTEGER, ilDBConstants::T_INTEGER, ilDBConstants::T_TEXT, ilDBConstants::T_TEXT], + [ilDclDatatype::INPUTFORMAT_TEXT_SELECTION, ilDclDatatype::INPUTFORMAT_DATE_SELECTION, '[%', '["%'] + ) + ); + + return (int) $legacy_file_field_amount?->amount; + } +} diff --git a/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSetupAgent.php b/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSetupAgent.php index b8250930c405..27b05cf98344 100755 --- a/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSetupAgent.php +++ b/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSetupAgent.php @@ -42,7 +42,8 @@ public function getMigrations(): array { return [ new ilDataCollectionStorageMigration(), - new ilDataCollectionInitLOMMigration() + new ilDataCollectionInitLOMMigration(), + new ilDataCollectionSelectionFieldMigration() ]; }