Skip to content
Snippets Groups Projects
Commit 2faca060 authored by Elmar Ludwig's avatar Elmar Ludwig Committed by Jan-Hendrik Willms
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 c375e827
No related branches found
No related tags found
No related merge requests found
......@@ -120,7 +120,7 @@ class Container extends \SimpleORMap
$container->store();
$blockMap = self::copyBlocks($user, $container, $this);
$blockMap = $this->copyBlocks($user, $container);
$container['payload'] = $container->type->copyPayload($blockMap);
......@@ -129,13 +129,11 @@ class Container extends \SimpleORMap
return $container;
}
private function copyBlocks(User $user, Container $newContainer, Container $remoteContainer): array
private function copyBlocks(User $user, Container $newContainer): array
{
$blockMap = [];
$blocks = Block::findBySQL('container_id = ?', [$remoteContainer->id]);
foreach ($blocks as $block) {
foreach ($this->blocks as $block) {
$newBlock = $block->copy($user, $newContainer);
$blockMap[$block->id] = $newBlock->id;
}
......
......@@ -668,7 +668,7 @@ SQL;
*/
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([
'parent_id' => $parent->id,
......@@ -686,9 +686,9 @@ SQL;
$element->store();
self::copyContainers($user, $element);
$this->copyContainers($user, $element);
self::copyChildren($user, $element, $purpose);
$this->copyChildren($user, $element, $purpose);
return $element;
}
......@@ -714,7 +714,7 @@ SQL;
{
// merge with target
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') {
......@@ -752,29 +752,24 @@ SQL;
$target->store();
// add Containers to target
self::copyContainers($user, $target);
$this->copyContainers($user, $target);
// copy Children
self::copyChildren($user, $target);
$this->copyChildren($user, $target);
return $this;
}
private function copyContainers(User $user, StructuralElement $newElement): void
{
$containers = \Courseware\Container::findBySQL('structural_element_id = ?', [$this->id]);
foreach ($containers as $container) {
foreach ($this->containers as $container) {
$container->copy($user, $newElement);
}
}
private function copyChildren(User $user, StructuralElement $newElement, string $purpose = ''): void
{
$children = self::findBySQL('parent_id = ?', [$this->id]);
foreach ($children as $child) {
foreach ($this->children as $child) {
$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