Skip to content

Commit

Permalink
BUGFIX: Prevent copy nodes across dimensions
Browse files Browse the repository at this point in the history
see neos/neos-development-collection#5054 (comment)

Previously the `$targetDimensionSpacePoint` was also wrongly chosen, and it was attempted to paste the node into the subjects home dimension
  • Loading branch information
mhsdesign committed Dec 7, 2024
1 parent 81c28b0 commit d9f4851
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 5 additions & 3 deletions Classes/Domain/Model/Changes/CopyAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion Classes/Domain/Model/Changes/CopyBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion Classes/Domain/Model/Changes/CopyInto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d9f4851

Please sign in to comment.