diff --git a/Classes/Domain/Model/Changes/CopyAfter.php b/Classes/Domain/Model/Changes/CopyAfter.php index 5396ee4175..cffc77b23e 100644 --- a/Classes/Domain/Model/Changes/CopyAfter.php +++ b/Classes/Domain/Model/Changes/CopyAfter.php @@ -13,7 +13,10 @@ */ use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint; -use Neos\ContentRepository\Core\Feature\NodeDuplication\Command\CopyNodesRecursively; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; +use Neos\Neos\Domain\Service\NodeDuplication\NodeAggregateIdMapping; +use Neos\Neos\Domain\Service\NodeDuplicationService; +use Neos\Flow\Annotations as Flow; /** * @internal These objects internally reflect possible operations made by the Neos.Ui. @@ -22,6 +25,9 @@ */ class CopyAfter extends AbstractStructuralChange { + #[Flow\Inject()] + protected NodeDuplicationService $nodeDuplicationService; + /** * "Subject" is the to-be-copied node; the "sibling" node is the node after which the "Subject" should be copied. * @@ -61,23 +67,18 @@ public function apply(): void // do nothing; $succeedingSibling is null. } - $contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId); - $command = CopyNodesRecursively::createFromSubgraphAndStartNode( - $contentRepository->getContentSubgraph( - $subject->workspaceName, - $subject->dimensionSpacePoint, - ), + $this->nodeDuplicationService->copyNodesRecursively( + $subject->contentRepositoryId, $subject->workspaceName, - $subject, + $subject->dimensionSpacePoint, + $subject->aggregateId, OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint), $parentNodeOfPreviousSibling->aggregateId, - $succeedingSibling?->aggregateId + $succeedingSibling?->aggregateId, + NodeAggregateIdMapping::createEmpty() + ->withNewNodeAggregateId($subject->aggregateId, $newlyCreatedNodeId = NodeAggregateId::create()) ); - $contentRepository->handle($command); - - $newlyCreatedNodeId = $command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId); - assert($newlyCreatedNodeId !== null); // cannot happen $newlyCreatedNode = $this->contentRepositoryRegistry->subgraphForNode($parentNodeOfPreviousSibling) ->findNodeById($newlyCreatedNodeId); if (!$newlyCreatedNode) { diff --git a/Classes/Domain/Model/Changes/CopyBefore.php b/Classes/Domain/Model/Changes/CopyBefore.php index 87e0881b6d..7dd5191e7a 100644 --- a/Classes/Domain/Model/Changes/CopyBefore.php +++ b/Classes/Domain/Model/Changes/CopyBefore.php @@ -13,8 +13,10 @@ */ use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint; -use Neos\ContentRepository\Core\Feature\NodeDuplication\Command\CopyNodesRecursively; -use Neos\ContentRepository\Core\SharedModel\Node\NodeName; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; +use Neos\Neos\Domain\Service\NodeDuplication\NodeAggregateIdMapping; +use Neos\Neos\Domain\Service\NodeDuplicationService; +use Neos\Flow\Annotations as Flow; /** * @internal These objects internally reflect possible operations made by the Neos.Ui. @@ -23,6 +25,9 @@ */ class CopyBefore extends AbstractStructuralChange { + #[Flow\Inject()] + protected NodeDuplicationService $nodeDuplicationService; + /** * "Subject" is the to-be-copied node; the "sibling" node is the node after which the "Subject" should be copied. */ @@ -57,23 +62,18 @@ public function apply(): void if ($this->canApply() && !is_null($succeedingSibling) && !is_null($parentNodeOfSucceedingSibling) ) { - $contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId); - $command = CopyNodesRecursively::createFromSubgraphAndStartNode( - $contentRepository->getContentGraph($subject->workspaceName)->getSubgraph( - $subject->dimensionSpacePoint, - $subject->visibilityConstraints - ), + $this->nodeDuplicationService->copyNodesRecursively( + $subject->contentRepositoryId, $subject->workspaceName, - $subject, + $subject->dimensionSpacePoint, + $subject->aggregateId, OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint), $parentNodeOfSucceedingSibling->aggregateId, - $succeedingSibling->aggregateId + $succeedingSibling->aggregateId, + NodeAggregateIdMapping::createEmpty() + ->withNewNodeAggregateId($subject->aggregateId, $newlyCreatedNodeId = NodeAggregateId::create()) ); - $contentRepository->handle($command); - - $newlyCreatedNodeId = $command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId); - assert($newlyCreatedNodeId !== null); // cannot happen $newlyCreatedNode = $this->contentRepositoryRegistry->subgraphForNode($parentNodeOfSucceedingSibling) ->findNodeById($newlyCreatedNodeId); if (!$newlyCreatedNode) { diff --git a/Classes/Domain/Model/Changes/CopyInto.php b/Classes/Domain/Model/Changes/CopyInto.php index bdd1188b7a..1a1eda3f10 100644 --- a/Classes/Domain/Model/Changes/CopyInto.php +++ b/Classes/Domain/Model/Changes/CopyInto.php @@ -13,8 +13,11 @@ */ use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint; -use Neos\ContentRepository\Core\Feature\NodeDuplication\Command\CopyNodesRecursively; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; +use Neos\Neos\Domain\Service\NodeDuplication\NodeAggregateIdMapping; +use Neos\Neos\Domain\Service\NodeDuplicationService; +use Neos\Flow\Annotations as Flow; /** * @internal These objects internally reflect possible operations made by the Neos.Ui. @@ -23,6 +26,9 @@ */ class CopyInto extends AbstractStructuralChange { + #[Flow\Inject()] + protected NodeDuplicationService $nodeDuplicationService; + protected ?string $parentContextPath; protected ?Node $cachedParentNode = null; @@ -66,22 +72,18 @@ public function apply(): void $subject = $this->getSubject(); $parentNode = $this->getParentNode(); if ($parentNode && $this->canApply()) { - $contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId); - $command = CopyNodesRecursively::createFromSubgraphAndStartNode( - $contentRepository->getContentGraph($subject->workspaceName)->getSubgraph( - $subject->dimensionSpacePoint, - $subject->visibilityConstraints - ), + $this->nodeDuplicationService->copyNodesRecursively( + $subject->contentRepositoryId, $subject->workspaceName, - $subject, + $subject->dimensionSpacePoint, + $subject->aggregateId, OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint), $parentNode->aggregateId, - null + null, + NodeAggregateIdMapping::createEmpty() + ->withNewNodeAggregateId($subject->aggregateId, $newlyCreatedNodeId = NodeAggregateId::create()) ); - $contentRepository->handle($command); - $newlyCreatedNodeId = $command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId); - assert($newlyCreatedNodeId !== null); // cannot happen $newlyCreatedNode = $this->contentRepositoryRegistry->subgraphForNode($parentNode) ->findNodeById($newlyCreatedNodeId); if (!$newlyCreatedNode) {