Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Adjust to copy nodes service #3887

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading