Skip to content

Commit 11711a9

Browse files
committed
TASK: Adjust to copy nodes service neos/neos-development-collection#5371
1 parent 0b30301 commit 11711a9

File tree

3 files changed

+42
-39
lines changed

3 files changed

+42
-39
lines changed

Classes/Domain/Model/Changes/CopyAfter.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
*/
1414

1515
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
16-
use Neos\ContentRepository\Core\Feature\NodeDuplication\Command\CopyNodesRecursively;
16+
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
17+
use Neos\Neos\Domain\Service\NodeDuplication\NodeAggregateIdMapping;
18+
use Neos\Neos\Domain\Service\NodeDuplicationService;
19+
use Neos\Flow\Annotations as Flow;
1720

1821
/**
1922
* @internal These objects internally reflect possible operations made by the Neos.Ui.
@@ -22,6 +25,9 @@
2225
*/
2326
class CopyAfter extends AbstractStructuralChange
2427
{
28+
#[Flow\Inject()]
29+
protected NodeDuplicationService $nodeDuplicationService;
30+
2531
/**
2632
* "Subject" is the to-be-copied node; the "sibling" node is the node after which the "Subject" should be copied.
2733
*
@@ -61,23 +67,18 @@ public function apply(): void
6167
// do nothing; $succeedingSibling is null.
6268
}
6369

64-
$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);
65-
$command = CopyNodesRecursively::createFromSubgraphAndStartNode(
66-
$contentRepository->getContentSubgraph(
67-
$subject->workspaceName,
68-
$subject->dimensionSpacePoint,
69-
),
70+
$this->nodeDuplicationService->copyNodesRecursively(
71+
$subject->contentRepositoryId,
7072
$subject->workspaceName,
71-
$subject,
73+
$subject->dimensionSpacePoint,
74+
$subject->aggregateId,
7275
OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint),
7376
$parentNodeOfPreviousSibling->aggregateId,
74-
$succeedingSibling?->aggregateId
77+
$succeedingSibling?->aggregateId,
78+
NodeAggregateIdMapping::createEmpty()
79+
->withNewNodeAggregateId($subject->aggregateId, $newlyCreatedNodeId = NodeAggregateId::create())
7580
);
7681

77-
$contentRepository->handle($command);
78-
79-
$newlyCreatedNodeId = $command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId);
80-
assert($newlyCreatedNodeId !== null); // cannot happen
8182
$newlyCreatedNode = $this->contentRepositoryRegistry->subgraphForNode($parentNodeOfPreviousSibling)
8283
->findNodeById($newlyCreatedNodeId);
8384
if (!$newlyCreatedNode) {

Classes/Domain/Model/Changes/CopyBefore.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
*/
1414

1515
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
16-
use Neos\ContentRepository\Core\Feature\NodeDuplication\Command\CopyNodesRecursively;
17-
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
16+
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
17+
use Neos\Neos\Domain\Service\NodeDuplication\NodeAggregateIdMapping;
18+
use Neos\Neos\Domain\Service\NodeDuplicationService;
19+
use Neos\Flow\Annotations as Flow;
1820

1921
/**
2022
* @internal These objects internally reflect possible operations made by the Neos.Ui.
@@ -23,6 +25,9 @@
2325
*/
2426
class CopyBefore extends AbstractStructuralChange
2527
{
28+
#[Flow\Inject()]
29+
protected NodeDuplicationService $nodeDuplicationService;
30+
2631
/**
2732
* "Subject" is the to-be-copied node; the "sibling" node is the node after which the "Subject" should be copied.
2833
*/
@@ -57,23 +62,18 @@ public function apply(): void
5762
if ($this->canApply() && !is_null($succeedingSibling)
5863
&& !is_null($parentNodeOfSucceedingSibling)
5964
) {
60-
$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);
61-
$command = CopyNodesRecursively::createFromSubgraphAndStartNode(
62-
$contentRepository->getContentGraph($subject->workspaceName)->getSubgraph(
63-
$subject->dimensionSpacePoint,
64-
$subject->visibilityConstraints
65-
),
65+
$this->nodeDuplicationService->copyNodesRecursively(
66+
$subject->contentRepositoryId,
6667
$subject->workspaceName,
67-
$subject,
68+
$subject->dimensionSpacePoint,
69+
$subject->aggregateId,
6870
OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint),
6971
$parentNodeOfSucceedingSibling->aggregateId,
70-
$succeedingSibling->aggregateId
72+
$succeedingSibling->aggregateId,
73+
NodeAggregateIdMapping::createEmpty()
74+
->withNewNodeAggregateId($subject->aggregateId, $newlyCreatedNodeId = NodeAggregateId::create())
7175
);
7276

73-
$contentRepository->handle($command);
74-
75-
$newlyCreatedNodeId = $command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId);
76-
assert($newlyCreatedNodeId !== null); // cannot happen
7777
$newlyCreatedNode = $this->contentRepositoryRegistry->subgraphForNode($parentNodeOfSucceedingSibling)
7878
->findNodeById($newlyCreatedNodeId);
7979
if (!$newlyCreatedNode) {

Classes/Domain/Model/Changes/CopyInto.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
*/
1414

1515
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
16-
use Neos\ContentRepository\Core\Feature\NodeDuplication\Command\CopyNodesRecursively;
1716
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
17+
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
18+
use Neos\Neos\Domain\Service\NodeDuplication\NodeAggregateIdMapping;
19+
use Neos\Neos\Domain\Service\NodeDuplicationService;
20+
use Neos\Flow\Annotations as Flow;
1821

1922
/**
2023
* @internal These objects internally reflect possible operations made by the Neos.Ui.
@@ -23,6 +26,9 @@
2326
*/
2427
class CopyInto extends AbstractStructuralChange
2528
{
29+
#[Flow\Inject()]
30+
protected NodeDuplicationService $nodeDuplicationService;
31+
2632
protected ?string $parentContextPath;
2733

2834
protected ?Node $cachedParentNode = null;
@@ -66,22 +72,18 @@ public function apply(): void
6672
$subject = $this->getSubject();
6773
$parentNode = $this->getParentNode();
6874
if ($parentNode && $this->canApply()) {
69-
$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);
70-
$command = CopyNodesRecursively::createFromSubgraphAndStartNode(
71-
$contentRepository->getContentGraph($subject->workspaceName)->getSubgraph(
72-
$subject->dimensionSpacePoint,
73-
$subject->visibilityConstraints
74-
),
75+
$this->nodeDuplicationService->copyNodesRecursively(
76+
$subject->contentRepositoryId,
7577
$subject->workspaceName,
76-
$subject,
78+
$subject->dimensionSpacePoint,
79+
$subject->aggregateId,
7780
OriginDimensionSpacePoint::fromDimensionSpacePoint($subject->dimensionSpacePoint),
7881
$parentNode->aggregateId,
79-
null
82+
null,
83+
NodeAggregateIdMapping::createEmpty()
84+
->withNewNodeAggregateId($subject->aggregateId, $newlyCreatedNodeId = NodeAggregateId::create())
8085
);
81-
$contentRepository->handle($command);
8286

83-
$newlyCreatedNodeId = $command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId);
84-
assert($newlyCreatedNodeId !== null); // cannot happen
8587
$newlyCreatedNode = $this->contentRepositoryRegistry->subgraphForNode($parentNode)
8688
->findNodeById($newlyCreatedNodeId);
8789
if (!$newlyCreatedNode) {

0 commit comments

Comments
 (0)