Skip to content
Snippets Groups Projects
Commit df0a0f6a authored by Elmar Ludwig's avatar Elmar Ludwig Committed by David Siegfried
Browse files

fix order during copy, don't use self to access methods on $this, fixes #1361

Closes #1361

Merge request studip/studip!892
parent 0f5785a8
No related branches found
No related tags found
No related merge requests found
...@@ -120,7 +120,7 @@ class Container extends \SimpleORMap ...@@ -120,7 +120,7 @@ class Container extends \SimpleORMap
$container->store(); $container->store();
$blockMap = self::copyBlocks($user, $container, $this); $blockMap = $this->copyBlocks($user, $container);
$container['payload'] = $container->type->copyPayload($blockMap); $container['payload'] = $container->type->copyPayload($blockMap);
...@@ -129,13 +129,11 @@ class Container extends \SimpleORMap ...@@ -129,13 +129,11 @@ class Container extends \SimpleORMap
return $container; return $container;
} }
private function copyBlocks(User $user, Container $newContainer, Container $remoteContainer): array private function copyBlocks(User $user, Container $newContainer): array
{ {
$blockMap = []; $blockMap = [];
$blocks = Block::findBySQL('container_id = ?', [$remoteContainer->id]); foreach ($this->blocks as $block) {
foreach ($blocks as $block) {
$newBlock = $block->copy($user, $newContainer); $newBlock = $block->copy($user, $newContainer);
$blockMap[$block->id] = $newBlock->id; $blockMap[$block->id] = $newBlock->id;
} }
......
...@@ -678,7 +678,7 @@ SQL; ...@@ -678,7 +678,7 @@ SQL;
*/ */
public function copy(User $user, StructuralElement $parent, string $purpose = ''): StructuralElement public function copy(User $user, StructuralElement $parent, string $purpose = ''): StructuralElement
{ {
$file_ref_id = self::copyImage($user, $parent); $file_ref_id = $this->copyImage($user, $parent);
$element = self::build([ $element = self::build([
'parent_id' => $parent->id, 'parent_id' => $parent->id,
...@@ -696,9 +696,9 @@ SQL; ...@@ -696,9 +696,9 @@ SQL;
$element->store(); $element->store();
self::copyContainers($user, $element); $this->copyContainers($user, $element);
self::copyChildren($user, $element, $purpose); $this->copyChildren($user, $element, $purpose);
return $element; return $element;
} }
...@@ -724,7 +724,7 @@ SQL; ...@@ -724,7 +724,7 @@ SQL;
{ {
// merge with target // merge with target
if (!$target->image_id) { if (!$target->image_id) {
$target->image_id = self::copyImage($user, $target); $target->image_id = $this->copyImage($user, $target);
} }
if ($target->title === 'neue Seite' || $target->title === 'New page') { if ($target->title === 'neue Seite' || $target->title === 'New page') {
...@@ -762,29 +762,24 @@ SQL; ...@@ -762,29 +762,24 @@ SQL;
$target->store(); $target->store();
// add Containers to target // add Containers to target
self::copyContainers($user, $target); $this->copyContainers($user, $target);
// copy Children // copy Children
$this->copyChildren($user, $target);
self::copyChildren($user, $target);
return $this; return $this;
} }
private function copyContainers(User $user, StructuralElement $newElement): void private function copyContainers(User $user, StructuralElement $newElement): void
{ {
$containers = \Courseware\Container::findBySQL('structural_element_id = ?', [$this->id]); foreach ($this->containers as $container) {
foreach ($containers as $container) {
$container->copy($user, $newElement); $container->copy($user, $newElement);
} }
} }
private function copyChildren(User $user, StructuralElement $newElement, string $purpose = ''): void private function copyChildren(User $user, StructuralElement $newElement, string $purpose = ''): void
{ {
$children = self::findBySQL('parent_id = ?', [$this->id]); foreach ($this->children as $child) {
foreach ($children as $child) {
$child->copy($user, $newElement, $purpose); $child->copy($user, $newElement, $purpose);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment