From d9f4851b5259dcf8113f4f2e526da850a0e2a768 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sat, 7 Dec 2024 16:52:53 +0100 Subject: [PATCH] BUGFIX: Prevent copy nodes across dimensions see https://github.com/neos/neos-development-collection/issues/5054#issuecomment-2523060805 Previously the `$targetDimensionSpacePoint` was also wrongly chosen, and it was attempted to paste the node into the subjects home dimension --- Classes/Domain/Model/Changes/CopyAfter.php | 8 +++++--- Classes/Domain/Model/Changes/CopyBefore.php | 5 ++++- Classes/Domain/Model/Changes/CopyInto.php | 5 ++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Classes/Domain/Model/Changes/CopyAfter.php b/Classes/Domain/Model/Changes/CopyAfter.php index cffc77b23e..c3e8307719 100644 --- a/Classes/Domain/Model/Changes/CopyAfter.php +++ b/Classes/Domain/Model/Changes/CopyAfter.php @@ -64,15 +64,17 @@ public function apply(): void try { $succeedingSibling = $this->findChildNodes($parentNodeOfPreviousSibling)->next($previousSibling); } catch (\InvalidArgumentException $e) { - // do nothing; $succeedingSibling is null. + // do nothing; $succeedingSibling is null. Todo add Nodes::contain() + } + if (!$subject->dimensionSpacePoint->equals($parentNodeOfPreviousSibling->dimensionSpacePoint)) { + throw new \RuntimeException('Copying across dimensions is not supported yet (https://github.com/neos/neos-development-collection/issues/5054)', 1733586265); } - $this->nodeDuplicationService->copyNodesRecursively( $subject->contentRepositoryId, $subject->workspaceName, $subject->dimensionSpacePoint, $subject->aggregateId, - OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint), + OriginDimensionSpacePoint::fromDimensionSpacePoint($parentNodeOfPreviousSibling->dimensionSpacePoint), $parentNodeOfPreviousSibling->aggregateId, $succeedingSibling?->aggregateId, NodeAggregateIdMapping::createEmpty() diff --git a/Classes/Domain/Model/Changes/CopyBefore.php b/Classes/Domain/Model/Changes/CopyBefore.php index 7dd5191e7a..764a03a3cc 100644 --- a/Classes/Domain/Model/Changes/CopyBefore.php +++ b/Classes/Domain/Model/Changes/CopyBefore.php @@ -62,12 +62,15 @@ public function apply(): void if ($this->canApply() && !is_null($succeedingSibling) && !is_null($parentNodeOfSucceedingSibling) ) { + if (!$subject->dimensionSpacePoint->equals($succeedingSibling->dimensionSpacePoint)) { + throw new \RuntimeException('Copying across dimensions is not supported yet (https://github.com/neos/neos-development-collection/issues/5054)', 1733586265); + } $this->nodeDuplicationService->copyNodesRecursively( $subject->contentRepositoryId, $subject->workspaceName, $subject->dimensionSpacePoint, $subject->aggregateId, - OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint), + OriginDimensionSpacePoint::fromDimensionSpacePoint($succeedingSibling->dimensionSpacePoint), $parentNodeOfSucceedingSibling->aggregateId, $succeedingSibling->aggregateId, NodeAggregateIdMapping::createEmpty() diff --git a/Classes/Domain/Model/Changes/CopyInto.php b/Classes/Domain/Model/Changes/CopyInto.php index 1a1eda3f10..6e5c0eb2a9 100644 --- a/Classes/Domain/Model/Changes/CopyInto.php +++ b/Classes/Domain/Model/Changes/CopyInto.php @@ -72,12 +72,15 @@ public function apply(): void $subject = $this->getSubject(); $parentNode = $this->getParentNode(); if ($parentNode && $this->canApply()) { + if (!$subject->dimensionSpacePoint->equals($parentNode->dimensionSpacePoint)) { + throw new \RuntimeException('Copying across dimensions is not supported yet (https://github.com/neos/neos-development-collection/issues/5054)', 1733586265); + } $this->nodeDuplicationService->copyNodesRecursively( $subject->contentRepositoryId, $subject->workspaceName, $subject->dimensionSpacePoint, $subject->aggregateId, - OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint), + OriginDimensionSpacePoint::fromDimensionSpacePoint($parentNode->dimensionSpacePoint), $parentNode->aggregateId, null, NodeAggregateIdMapping::createEmpty()