Skip to content

Commit

Permalink
TASK: Adjust to copy nodes service neos/neos-development-collection#5371
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Nov 18, 2024
1 parent 0b30301 commit 11711a9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
27 changes: 14 additions & 13 deletions Classes/Domain/Model/Changes/CopyAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*
Expand Down Expand Up @@ -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) {
Expand Down
28 changes: 14 additions & 14 deletions Classes/Domain/Model/Changes/CopyBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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) {
Expand Down
26 changes: 14 additions & 12 deletions Classes/Domain/Model/Changes/CopyInto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -23,6 +26,9 @@
*/
class CopyInto extends AbstractStructuralChange
{
#[Flow\Inject()]
protected NodeDuplicationService $nodeDuplicationService;

protected ?string $parentContextPath;

protected ?Node $cachedParentNode = null;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 11711a9

Please sign in to comment.