Skip to content

Commit

Permalink
Merge pull request #5153 from mhsdesign/task/streamlineNodeReferences…
Browse files Browse the repository at this point in the history
…WereSet

!!! TASK: streamline `NodeReferencesWereSet::$nodeAggregateId`
  • Loading branch information
mhsdesign authored Jul 8, 2024
2 parents 38cdd4c + f127233 commit 78bdd81
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ private function whenNodeReferencesWereSet(NodeReferencesWereSet $event, EventEn
foreach ($event->affectedSourceOriginDimensionSpacePoints as $originDimensionSpacePoint) {
$nodeAnchorPoint = $this->projectionContentGraph
->getAnchorPointForNodeAndOriginDimensionSpacePointAndContentStream(
$event->sourceNodeAggregateId,
$event->nodeAggregateId,
$originDimensionSpacePoint,
$event->contentStreamId
);
Expand Down Expand Up @@ -514,7 +514,7 @@ function (NodeRecord $node) use ($eventEnvelope) {

$nodeAnchorPoint = $this->projectionContentGraph
->getAnchorPointForNodeAndOriginDimensionSpacePointAndContentStream(
$event->sourceNodeAggregateId,
$event->nodeAggregateId,
$originDimensionSpacePoint,
$event->contentStreamId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private function whenNodeReferencesWereSet(NodeReferencesWereSet $event): void
$nodeRecord = $this->getProjectionHypergraph()->findNodeRecordByOrigin(
$event->contentStreamId,
$originDimensionSpacePoint,
$event->sourceNodeAggregateId
$event->nodeAggregateId
);

if ($nodeRecord) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public function __construct(
public WorkspaceName $workspaceName,
public ContentStreamId $contentStreamId,
public NodeAggregateId $sourceNodeAggregateId,
public NodeAggregateId $nodeAggregateId,
/**
* While only one origin dimension space point is selected when initializing the command,
* a whole set of origin dimension space points might be affected depending on the
Expand All @@ -47,23 +47,17 @@ public function getContentStreamId(): ContentStreamId
return $this->contentStreamId;
}

/**
* this method is implemented for fulfilling the {@see EmbedsContentStreamAndNodeAggregateId} interface,
* needed for proper content cache flushing in Neos.
*
* @return NodeAggregateId
*/
public function getNodeAggregateId(): NodeAggregateId
{
return $this->sourceNodeAggregateId;
return $this->nodeAggregateId;
}

public function withWorkspaceNameAndContentStreamId(WorkspaceName $targetWorkspaceName, ContentStreamId $contentStreamId): self
{
return new self(
$targetWorkspaceName,
$contentStreamId,
$this->sourceNodeAggregateId,
$this->nodeAggregateId,
$this->affectedSourceOriginDimensionSpacePoints,
$this->referenceName,
$this->references,
Expand All @@ -75,7 +69,9 @@ public static function fromArray(array $values): self
return new self(
WorkspaceName::fromString($values['workspaceName']),
ContentStreamId::fromString($values['contentStreamId']),
NodeAggregateId::fromString($values['sourceNodeAggregateId']),
array_key_exists('sourceNodeAggregateId', $values)
? NodeAggregateId::fromString($values['sourceNodeAggregateId'])
: NodeAggregateId::fromString($values['nodeAggregateId']),
OriginDimensionSpacePointSet::fromArray($values['affectedSourceOriginDimensionSpacePoints']),
ReferenceName::fromString($values['referenceName']),
SerializedNodeReferences::fromArray($values['references']),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

/*
* This file is part of the Neos.ContentRepository.Core package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

declare(strict_types=1);

namespace Neos\ContentRepository\Core\Tests\Unit\Feature\NodeCreation\Event;

use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\Common\InterdimensionalSibling;
use Neos\ContentRepository\Core\Feature\Common\InterdimensionalSiblings;
use Neos\ContentRepository\Core\Feature\NodeCreation\Event\NodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use PHPUnit\Framework\TestCase;

class NodeAggregateWithNodeWasCreatedTest extends TestCase
{
/**
* @param array<string,mixed> $payload
* @dataProvider eventPayloadProviderWithLegacySucceedingNodeAggregateIdFormat
*/
public function testFromArray(array $payload, NodeAggregateWithNodeWasCreated $expectedEvent): void
{
self::assertEquals($expectedEvent, NodeAggregateWithNodeWasCreated::fromArray($payload));
}

/**
* The coveredDimensionSpacePoints and succeedingNodeAggregateId were replaced with `InterdimensionalSiblings`.
* A runtime migration was added to {@see NodeAggregateWithNodeWasCreated::fromArray()} to handle the legacy format.
*
* Via #4961: https://github.com/neos/neos-development-collection/pull/4961
*
* Included in April 2024
*
* @return iterable<mixed>
*/
public static function eventPayloadProviderWithLegacySucceedingNodeAggregateIdFormat(): iterable
{
yield 'legacy coveredDimensionSpacePoints succeedingNodeAggregateId fields are transformed' => [
[
'contentStreamId' => 'd1afafaf-e078-4b44-a9a2-077094e8e45b',
'nodeAggregateId' => '872344d1-7da5-4b17-a1f0-0138987431a9',
'nodeTypeName' => 'Vendor.Site:Document.Page',
'originDimensionSpacePoint' =>
[
'language' => 'pl',
],
'coveredDimensionSpacePoints' =>
[
[
'language' => 'pl',
],
],
'parentNodeAggregateId' => '6b6e1251-4346-494f-ac56-526a30a5741d',
'nodeName' => null,
'initialPropertyValues' => [],
'nodeAggregateClassification' => 'regular',
'succeedingNodeAggregateId' => '30ef3082-e37f-4346-83cf-45ed0249381f',
'workspaceName' => 'user-soee',
],
new NodeAggregateWithNodeWasCreated(
WorkspaceName::fromString('user-soee'),
ContentStreamId::fromString('d1afafaf-e078-4b44-a9a2-077094e8e45b'),
NodeAggregateId::fromString('872344d1-7da5-4b17-a1f0-0138987431a9'),
NodeTypeName::fromString('Vendor.Site:Document.Page'),
OriginDimensionSpacePoint::fromArray(['language' => 'pl']),
new InterdimensionalSiblings(
new InterdimensionalSibling(
DimensionSpacePoint::fromArray(['language' => 'pl']),
NodeAggregateId::fromString('30ef3082-e37f-4346-83cf-45ed0249381f')
)
),
NodeAggregateId::fromString('6b6e1251-4346-494f-ac56-526a30a5741d'),
null,
SerializedPropertyValues::createEmpty(),
NodeAggregateClassification::CLASSIFICATION_REGULAR
)
];

yield 'legacy succeedingNodeAggregateId field is null' => [
[
'contentStreamId' => 'd1afafaf-e078-4b44-a9a2-077094e8e45b',
'nodeAggregateId' => '872344d1-7da5-4b17-a1f0-0138987431a9',
'nodeTypeName' => 'Vendor.Site:Document.Page',
'originDimensionSpacePoint' =>
[
'language' => 'pl',
],
'coveredDimensionSpacePoints' =>
[
[
'language' => 'pl',
],
],
'parentNodeAggregateId' => '6b6e1251-4346-494f-ac56-526a30a5741d',
'nodeName' => null,
'initialPropertyValues' => [],
'nodeAggregateClassification' => 'regular',
'succeedingNodeAggregateId' => null,
'workspaceName' => 'user-soee',
],
new NodeAggregateWithNodeWasCreated(
WorkspaceName::fromString('user-soee'),
ContentStreamId::fromString('d1afafaf-e078-4b44-a9a2-077094e8e45b'),
NodeAggregateId::fromString('872344d1-7da5-4b17-a1f0-0138987431a9'),
NodeTypeName::fromString('Vendor.Site:Document.Page'),
OriginDimensionSpacePoint::fromArray(['language' => 'pl']),
new InterdimensionalSiblings(
new InterdimensionalSibling(
DimensionSpacePoint::fromArray(['language' => 'pl']),
null
)
),
NodeAggregateId::fromString('6b6e1251-4346-494f-ac56-526a30a5741d'),
null,
SerializedPropertyValues::createEmpty(),
NodeAggregateClassification::CLASSIFICATION_REGULAR
)
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,24 @@ class NodeAggregateWasMovedTest extends TestCase
{
/**
* @param array<string,mixed> $payload
* @dataProvider eventPayloadProvider
* @dataProvider eventPayloadProviderWithLegacyNodeMoveMappingsFormat
*/
public function testFromArray(array $payload, NodeAggregateWasMoved $expectedEvent): void
{
self::assertEquals($expectedEvent, NodeAggregateWasMoved::fromArray($payload));
}

/**
* @return \Traversable<string,array<string,mixed>>
* The `MoveNodeMappings` were replaced with `InterdimensionalSiblings`.
* A runtime migration was added to {@see NodeAggregateWasMoved::fromArray()} to handle the legacy format.
*
* Via #4993: https://github.com/neos/neos-development-collection/pull/4993
*
* Included in April 2024
*
* @return iterable<mixed>
*/
public static function eventPayloadProvider(): \Traversable
public static function eventPayloadProviderWithLegacyNodeMoveMappingsFormat(): iterable
{
yield 'singleNodeMoveMappingWithSibling' => [
'payload' => [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/*
* This file is part of the Neos.ContentRepository.Core package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

declare(strict_types=1);

namespace Neos\ContentRepository\Core\Tests\Unit\Feature\NodeReferencing\Event;

use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePointSet;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Dto\SerializedNodeReferences;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Event\NodeReferencesWereSet;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use PHPUnit\Framework\TestCase;

class NodeReferencesWereSetTest extends TestCase
{
/**
* @param array<string,mixed> $payload
* @dataProvider eventPayloadProviderWithLegacySourceNodeAggregateIdFormat
*/
public function testFromArray(array $payload, NodeReferencesWereSet $expectedEvent): void
{
self::assertEquals($expectedEvent, NodeReferencesWereSet::fromArray($payload));
}

/**
* The property sourceNodeAggregateId was renamed to nodeAggregateId.
* A runtime migration was added to {@see NodeReferencesWereSet::fromArray()} to handle the legacy format.
*
* Via #5153: https://github.com/neos/neos-development-collection/pull/5153
*
* Included in Juni 2024
*
* @return iterable<mixed>
*/
public static function eventPayloadProviderWithLegacySourceNodeAggregateIdFormat(): iterable
{
yield 'legacy coveredDimensionSpacePoints succeedingNodeAggregateId fields are transformed' => [
[
'contentStreamId' => 'e542b7d2-a7c1-4bd8-b02a-3e8450829965',
'sourceNodeAggregateId' => '3b4ecdc0-8115-41ed-805d-fb98ced2276a',
'affectedSourceOriginDimensionSpacePoints' =>
[
[
'language' => 'en_US',
],
],
'referenceName' => 'blogs',
'references' => [],
'workspaceName' => 'user-admin',
],
new NodeReferencesWereSet(
WorkspaceName::fromString('user-admin'),
ContentStreamId::fromString('e542b7d2-a7c1-4bd8-b02a-3e8450829965'),
NodeAggregateId::fromString('3b4ecdc0-8115-41ed-805d-fb98ced2276a'),
OriginDimensionSpacePointSet::fromArray([
[
'language' => 'en_US',
],
]),
ReferenceName::fromString('blogs'),
SerializedNodeReferences::fromArray([])
)
];
}
}
Loading

0 comments on commit 78bdd81

Please sign in to comment.