diff options
| author | Ron Lucke <lucke@elan-ev.de> | 2024-11-04 07:35:37 +0000 |
|---|---|---|
| committer | Ron Lucke <lucke@elan-ev.de> | 2024-11-04 07:35:37 +0000 |
| commit | bf8d6ab6796524166072d42945245a53c93999da (patch) | |
| tree | 9d3c565ff145c9ddf8832a352b728337d444046a /db | |
| parent | 0726f3d2bc32d27547bb7313bcd6b0fb3f00ee79 (diff) | |
Fix Courseware Sort issue
Closes #4766
Merge request studip/studip!3585
Diffstat (limited to 'db')
| -rw-r--r-- | db/migrations/5.3.26_fix_faulty_container_payload.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/db/migrations/5.3.26_fix_faulty_container_payload.php b/db/migrations/5.3.26_fix_faulty_container_payload.php new file mode 100644 index 0000000..a5c169b --- /dev/null +++ b/db/migrations/5.3.26_fix_faulty_container_payload.php @@ -0,0 +1,46 @@ +<?php +/** + * @see https://gitlab.studip.de/studip/studip/-/issues/4766 + */ +return new class extends Migration { + public function description() + { + return 'Fix container payload, in case an array was inserted into the block list (see BIEST#4766)'; + } + + protected function up() + { + $db = DBManager::get(); + + $query = "SELECT * FROM `cw_containers` + WHERE payload LIKE '%\"blocks\":%' + AND ( + payload LIKE '%\"blocks\":[%[%]%' + OR + payload LIKE '%\"blocks\":[%[^\"]%' + ); + "; + $containers = $db->fetchAll($query); + + $update_container = $db->prepare("UPDATE `cw_containers` SET `payload` = ? WHERE `id` = ?"); + + foreach ($containers as $container) { + $payload = json_decode($container['payload'], true); + $sections = $payload['sections']; + foreach ($sections as &$section) { + $section['blocks'] = array_map(function ($item) { + if (is_array($item)) { + return implode('', array_map('strval', $item)); + } + return strval($item); + }, $section['blocks']); + ; + } + $payload['sections'] = $sections; + $payload = json_encode($payload); + $id = $container['id']; + $update_container->execute([$payload, $id]); + } + } + +}; |
