Skip to content
Snippets Groups Projects
Commit bf8d6ab6 authored by Ron Lucke's avatar Ron Lucke
Browse files

Fix Courseware Sort issue

Closes #4766

Merge request !3585
parent 0726f3d2
No related branches found
No related tags found
No related merge requests found
<?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]);
}
}
};
...@@ -194,7 +194,7 @@ abstract class ContainerType ...@@ -194,7 +194,7 @@ abstract class ContainerType
foreach ($payload['sections'] as &$section) { foreach ($payload['sections'] as &$section) {
foreach ($section['blocks'] as &$block) { foreach ($section['blocks'] as &$block) {
$block = $block_map[$block] ?? null; $block = (is_string($block) || is_int($block)) ? ($block_map[$block] ?? null) : null;
} }
$section['blocks'] = array_values(array_filter($section['blocks'])); $section['blocks'] = array_values(array_filter($section['blocks']));
} }
......
...@@ -36,12 +36,12 @@ const containerMixin = { ...@@ -36,12 +36,12 @@ const containerMixin = {
containerUpdate: 'courseware-containers/update' containerUpdate: 'courseware-containers/update'
}), }),
dropBlock(e) { dropBlock(e) {
this.isDragging = false; // implemented bei echt container type this.isDragging = false; // implemented by each container type
let data = {}; let data = {};
data.originContainerId = e.from.__vue__.$attrs.containerId; data.originContainerId = e.from.__vue__.$attrs.containerId;
data.targetContainerId = e.to.__vue__.$attrs.containerId; data.targetContainerId = e.to.__vue__.$attrs.containerId;
if (data.originContainerId === data.targetContainerId) { if (data.originContainerId === data.targetContainerId) {
this.storeSort(); // implemented bei echt container type this.storeSort(); // implemented by each container type
} else { } else {
data.originSectionId = e.from.__vue__.$attrs.sectionId; data.originSectionId = e.from.__vue__.$attrs.sectionId;
data.originSectionBlockList = e.from.__vue__.$children.map(b => { return b.$attrs.blockId; }); data.originSectionBlockList = e.from.__vue__.$children.map(b => { return b.$attrs.blockId; });
...@@ -50,7 +50,7 @@ const containerMixin = { ...@@ -50,7 +50,7 @@ const containerMixin = {
data.blockId = e.item._underlying_vm_.id; data.blockId = e.item._underlying_vm_.id;
data.newPos = e.newIndex; data.newPos = e.newIndex;
const indexInBlockList = data.targetSectionBlockList.findIndex(b => b === data.blockId); const indexInBlockList = data.targetSectionBlockList.findIndex(b => b === data.blockId);
data.targetSectionBlockList.splice(data.newPos, 0, data.targetSectionBlockList.splice(indexInBlockList,1)); data.targetSectionBlockList.splice(data.newPos, 0, data.targetSectionBlockList.splice(indexInBlockList,1)[0]); // move block id to new position
this.storeInAnotherContainer(data); this.storeInAnotherContainer(data);
} }
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment