From a148e75113caa71a94deb106f2e902d15fd98b81 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Mon, 20 May 2024 20:06:15 +0200 Subject: [PATCH] TASK: Remove now obsolete `ProjectedNodeIterator` and expose $contentGraph directly $this->projectedNodeIterator->nodeAggregatesOfType has been rewritten to $this->contentGraph->findNodeAggregatesByType The `ProjectedNodeIterator` was before https://github.com/neos/neos-development-collection/pull/5028 required to encapsulate `findNodeAggregatesByType` to only work on the live workspace. --- .../src/Adjustment/DimensionAdjustment.php | 7 ++-- .../DisallowedChildNodeAdjustment.php | 13 +++--- .../src/Adjustment/ProjectedNodeIterator.php | 40 ------------------- .../src/Adjustment/PropertyAdjustment.php | 5 ++- .../Adjustment/TetheredNodeAdjustments.php | 21 +++++----- .../Adjustment/UnknownNodeTypeAdjustment.php | 7 ++-- .../src/StructureAdjustmentService.php | 29 +++++++++----- 7 files changed, 47 insertions(+), 75 deletions(-) delete mode 100644 Neos.ContentRepository.StructureAdjustment/src/Adjustment/ProjectedNodeIterator.php diff --git a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/DimensionAdjustment.php b/Neos.ContentRepository.StructureAdjustment/src/Adjustment/DimensionAdjustment.php index b65827c9697..36fb459efb4 100644 --- a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/DimensionAdjustment.php +++ b/Neos.ContentRepository.StructureAdjustment/src/Adjustment/DimensionAdjustment.php @@ -9,12 +9,13 @@ use Neos\ContentRepository\Core\DimensionSpace\VariantType; use Neos\ContentRepository\Core\NodeType\NodeTypeManager; use Neos\ContentRepository\Core\NodeType\NodeTypeName; +use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeNotFound; class DimensionAdjustment { public function __construct( - protected ProjectedNodeIterator $projectedNodeIterator, + protected ContentGraphInterface $contentGraph, protected InterDimensionalVariationGraph $interDimensionalVariationGraph, protected NodeTypeManager $nodeTypeManager, ) { @@ -30,7 +31,7 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): iterable return []; } if ($nodeType->isOfType(NodeTypeName::ROOT_NODE_TYPE_NAME)) { - foreach ($this->projectedNodeIterator->nodeAggregatesOfType($nodeTypeName) as $nodeAggregate) { + foreach ($this->contentGraph->findNodeAggregatesByType($nodeTypeName) as $nodeAggregate) { if ( !$nodeAggregate->coveredDimensionSpacePoints->equals($this->interDimensionalVariationGraph->getDimensionSpacePoints()) ) { @@ -42,7 +43,7 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): iterable } return []; } - foreach ($this->projectedNodeIterator->nodeAggregatesOfType($nodeTypeName) as $nodeAggregate) { + foreach ($this->contentGraph->findNodeAggregatesByType($nodeTypeName) as $nodeAggregate) { foreach ($nodeAggregate->getNodes() as $node) { foreach ( $nodeAggregate->getCoverageByOccupant( diff --git a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/DisallowedChildNodeAdjustment.php b/Neos.ContentRepository.StructureAdjustment/src/Adjustment/DisallowedChildNodeAdjustment.php index ebef353c445..82a57da378c 100644 --- a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/DisallowedChildNodeAdjustment.php +++ b/Neos.ContentRepository.StructureAdjustment/src/Adjustment/DisallowedChildNodeAdjustment.php @@ -15,6 +15,7 @@ use Neos\ContentRepository\Core\Feature\NodeRemoval\Event\NodeAggregateWasRemoved; use Neos\ContentRepository\Core\NodeType\NodeTypeManager; use Neos\ContentRepository\Core\NodeType\NodeTypeName; +use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate; use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; @@ -25,7 +26,7 @@ class DisallowedChildNodeAdjustment use RemoveNodeAggregateTrait; public function __construct( - private readonly ProjectedNodeIterator $projectedNodeIterator, + private readonly ContentGraphInterface $contentGraph, private readonly NodeTypeManager $nodeTypeManager, ) { } @@ -40,7 +41,7 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat return; } - foreach ($this->projectedNodeIterator->nodeAggregatesOfType($nodeTypeName) as $nodeAggregate) { + foreach ($this->contentGraph->findNodeAggregatesByType($nodeTypeName) as $nodeAggregate) { $nodeType = $this->nodeTypeManager->getNodeType($nodeAggregate->nodeTypeName); if (!$nodeType) { // unknown child node type, so we skip this test as we won't be able to find out node type constraints @@ -51,7 +52,7 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat // as it can happen that the constraint is only violated in e.g. "AT", but not in "DE". // Then, we only want to remove the single edge. foreach ($nodeAggregate->coveredDimensionSpacePoints as $coveredDimensionSpacePoint) { - $subgraph = $this->projectedNodeIterator->contentGraph->getSubgraph( + $subgraph = $this->contentGraph->getSubgraph( $coveredDimensionSpacePoint, VisibilityConstraints::withoutRestrictions() ); @@ -127,8 +128,8 @@ private function removeNodeInSingleDimensionSpacePoint( $referenceOrigin = OriginDimensionSpacePoint::fromDimensionSpacePoint($dimensionSpacePoint); $events = Events::with( new NodeAggregateWasRemoved( - $this->projectedNodeIterator->contentGraph->getWorkspaceName(), - $this->projectedNodeIterator->contentGraph->getContentStreamId(), + $this->contentGraph->getWorkspaceName(), + $this->contentGraph->getContentStreamId(), $nodeAggregate->nodeAggregateId, $nodeAggregate->occupiesDimensionSpacePoint($referenceOrigin) ? new OriginDimensionSpacePointSet([$referenceOrigin]) @@ -138,7 +139,7 @@ private function removeNodeInSingleDimensionSpacePoint( ); $streamName = ContentStreamEventStreamName::fromContentStreamId( - $this->projectedNodeIterator->contentGraph->getContentStreamId() + $this->contentGraph->getContentStreamId() ); return new EventsToPublish( diff --git a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/ProjectedNodeIterator.php b/Neos.ContentRepository.StructureAdjustment/src/Adjustment/ProjectedNodeIterator.php deleted file mode 100644 index 69e50487315..00000000000 --- a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/ProjectedNodeIterator.php +++ /dev/null @@ -1,40 +0,0 @@ -contentGraph->findNodeAggregatesByType($nodeTypeName); - foreach ($nodeAggregates as $nodeAggregate) { - yield $nodeAggregate; - } - } -} diff --git a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/PropertyAdjustment.php b/Neos.ContentRepository.StructureAdjustment/src/Adjustment/PropertyAdjustment.php index f74c3e77bbd..15613865d14 100644 --- a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/PropertyAdjustment.php +++ b/Neos.ContentRepository.StructureAdjustment/src/Adjustment/PropertyAdjustment.php @@ -12,6 +12,7 @@ use Neos\ContentRepository\Core\Feature\NodeModification\Event\NodePropertiesWereSet; use Neos\ContentRepository\Core\NodeType\NodeTypeManager; use Neos\ContentRepository\Core\NodeType\NodeTypeName; +use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate; use Neos\ContentRepository\Core\SharedModel\Node\PropertyNames; @@ -21,7 +22,7 @@ class PropertyAdjustment { public function __construct( - private readonly ProjectedNodeIterator $projectedNodeIterator, + private readonly ContentGraphInterface $contentGraph, private readonly NodeTypeManager $nodeTypeManager ) { } @@ -39,7 +40,7 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat $expectedPropertiesFromNodeType = array_filter($nodeType->getProperties(), fn ($value) => $value !== null); - foreach ($this->projectedNodeIterator->nodeAggregatesOfType($nodeTypeName) as $nodeAggregate) { + foreach ($this->contentGraph->findNodeAggregatesByType($nodeTypeName) as $nodeAggregate) { foreach ($nodeAggregate->getNodes() as $node) { $propertyKeysInNode = []; diff --git a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/TetheredNodeAdjustments.php b/Neos.ContentRepository.StructureAdjustment/src/Adjustment/TetheredNodeAdjustments.php index bf70a89f2c2..95a7e5336a5 100644 --- a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/TetheredNodeAdjustments.php +++ b/Neos.ContentRepository.StructureAdjustment/src/Adjustment/TetheredNodeAdjustments.php @@ -16,6 +16,7 @@ use Neos\ContentRepository\Core\Infrastructure\Property\PropertyConverter; use Neos\ContentRepository\Core\NodeType\NodeTypeManager; use Neos\ContentRepository\Core\NodeType\NodeTypeName; +use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindChildNodesFilter; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints; @@ -30,7 +31,7 @@ class TetheredNodeAdjustments use TetheredNodeInternals; public function __construct( - private readonly ProjectedNodeIterator $projectedNodeIterator, + private readonly ContentGraphInterface $contentGraph, private readonly NodeTypeManager $nodeTypeManager, private readonly DimensionSpace\InterDimensionalVariationGraph $interDimensionalVariationGraph, private readonly PropertyConverter $propertyConverter @@ -47,7 +48,7 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat // In case we cannot find the expected tethered nodes, this fix cannot do anything. return; } - foreach ($this->projectedNodeIterator->nodeAggregatesOfType($nodeTypeName) as $nodeAggregate) { + foreach ($this->contentGraph->findNodeAggregatesByType($nodeTypeName) as $nodeAggregate) { // find missing tethered nodes $foundMissingOrDisallowedTetheredNodes = false; $originDimensionSpacePoints = $nodeType->isOfType(NodeTypeName::ROOT_NODE_TYPE_NAME) @@ -58,7 +59,7 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat foreach ($originDimensionSpacePoints as $originDimensionSpacePoint) { foreach ($nodeType->tetheredNodeTypeDefinitions as $tetheredNodeTypeDefinition) { - $tetheredNode = $this->projectedNodeIterator->contentGraph->getSubgraph( + $tetheredNode = $this->contentGraph->getSubgraph( $originDimensionSpacePoint->toDimensionSpacePoint(), VisibilityConstraints::withoutRestrictions() )->findNodeByPath( @@ -77,7 +78,7 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat 'The tethered child node "' . $tetheredNodeTypeDefinition->name->value . '" is missing.', function () use ($nodeAggregate, $originDimensionSpacePoint, $tetheredNodeTypeDefinition) { $events = $this->createEventsForMissingTetheredNode( - $this->projectedNodeIterator->contentGraph, + $this->contentGraph, $nodeAggregate, $originDimensionSpacePoint, $tetheredNodeTypeDefinition, @@ -85,7 +86,7 @@ function () use ($nodeAggregate, $originDimensionSpacePoint, $tetheredNodeTypeDe ); $streamName = ContentStreamEventStreamName::fromContentStreamId( - $this->projectedNodeIterator->contentGraph->getContentStreamId() + $this->contentGraph->getContentStreamId() ); return new EventsToPublish( $streamName->getEventStreamName(), @@ -102,7 +103,7 @@ function () use ($nodeAggregate, $originDimensionSpacePoint, $tetheredNodeTypeDe } // find disallowed tethered nodes - $tetheredNodeAggregates = $this->projectedNodeIterator->contentGraph->findTetheredChildNodeAggregates( + $tetheredNodeAggregates = $this->contentGraph->findTetheredChildNodeAggregates( $nodeAggregate->nodeAggregateId ); foreach ($tetheredNodeAggregates as $tetheredNodeAggregate) { @@ -115,7 +116,7 @@ function () use ($nodeAggregate, $originDimensionSpacePoint, $tetheredNodeTypeDe 'The tethered child node "' . $tetheredNodeAggregate->nodeName->value . '" should be removed.', function () use ($tetheredNodeAggregate) { - return $this->removeNodeAggregate($this->projectedNodeIterator->contentGraph, $tetheredNodeAggregate); + return $this->removeNodeAggregate($this->contentGraph, $tetheredNodeAggregate); } ); } @@ -124,7 +125,7 @@ function () use ($tetheredNodeAggregate) { // find wrongly ordered tethered nodes if ($foundMissingOrDisallowedTetheredNodes === false) { foreach ($originDimensionSpacePoints as $originDimensionSpacePoint) { - $childNodes = $this->projectedNodeIterator->contentGraph->getSubgraph($originDimensionSpacePoint->toDimensionSpacePoint(), VisibilityConstraints::withoutRestrictions())->findChildNodes($nodeAggregate->nodeAggregateId, FindChildNodesFilter::create()); + $childNodes = $this->contentGraph->getSubgraph($originDimensionSpacePoint->toDimensionSpacePoint(), VisibilityConstraints::withoutRestrictions())->findChildNodes($nodeAggregate->nodeAggregateId, FindChildNodesFilter::create()); /** is indexed by node name, and the value is the tethered node itself */ $actualTetheredChildNodes = []; @@ -147,8 +148,8 @@ function () use ($tetheredNodeAggregate) { . ' - actual: ' . implode(', ', array_keys($actualTetheredChildNodes)), fn () => $this->reorderNodes( - $this->projectedNodeIterator->contentGraph->getWorkspaceName(), - $this->projectedNodeIterator->contentGraph->getContentStreamId(), + $this->contentGraph->getWorkspaceName(), + $this->contentGraph->getContentStreamId(), $nodeAggregate->getCoverageByOccupant($originDimensionSpacePoint), $actualTetheredChildNodes, array_keys($nodeType->tetheredNodeTypeDefinitions->toArray()) diff --git a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/UnknownNodeTypeAdjustment.php b/Neos.ContentRepository.StructureAdjustment/src/Adjustment/UnknownNodeTypeAdjustment.php index e2ca74e21f2..5d4c444f924 100644 --- a/Neos.ContentRepository.StructureAdjustment/src/Adjustment/UnknownNodeTypeAdjustment.php +++ b/Neos.ContentRepository.StructureAdjustment/src/Adjustment/UnknownNodeTypeAdjustment.php @@ -6,13 +6,14 @@ use Neos\ContentRepository\Core\NodeType\NodeTypeManager; use Neos\ContentRepository\Core\NodeType\NodeTypeName; +use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; class UnknownNodeTypeAdjustment { use RemoveNodeAggregateTrait; public function __construct( - private readonly ProjectedNodeIterator $projectedNodeIterator, + private readonly ContentGraphInterface $contentGraph, private readonly NodeTypeManager $nodeTypeManager ) { } @@ -33,14 +34,14 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat */ private function removeAllNodesOfType(NodeTypeName $nodeTypeName): \Generator { - foreach ($this->projectedNodeIterator->nodeAggregatesOfType($nodeTypeName) as $nodeAggregate) { + foreach ($this->contentGraph->findNodeAggregatesByType($nodeTypeName) as $nodeAggregate) { yield StructureAdjustment::createForNodeAggregate( $nodeAggregate, StructureAdjustment::NODE_TYPE_MISSING, 'The node type "' . $nodeTypeName->value . '" is not found; so the node should be removed (or converted)', function () use ($nodeAggregate) { - return $this->removeNodeAggregate($this->projectedNodeIterator->contentGraph, $nodeAggregate); + return $this->removeNodeAggregate($this->contentGraph, $nodeAggregate); } ); } diff --git a/Neos.ContentRepository.StructureAdjustment/src/StructureAdjustmentService.php b/Neos.ContentRepository.StructureAdjustment/src/StructureAdjustmentService.php index 9d2e39975ad..6012fe31428 100644 --- a/Neos.ContentRepository.StructureAdjustment/src/StructureAdjustmentService.php +++ b/Neos.ContentRepository.StructureAdjustment/src/StructureAdjustmentService.php @@ -12,10 +12,10 @@ use Neos\ContentRepository\Core\Infrastructure\Property\PropertyConverter; use Neos\ContentRepository\Core\NodeType\NodeTypeManager; use Neos\ContentRepository\Core\NodeType\NodeTypeName; +use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepository\StructureAdjustment\Adjustment\DimensionAdjustment; use Neos\ContentRepository\StructureAdjustment\Adjustment\DisallowedChildNodeAdjustment; -use Neos\ContentRepository\StructureAdjustment\Adjustment\ProjectedNodeIterator; use Neos\ContentRepository\StructureAdjustment\Adjustment\PropertyAdjustment; use Neos\ContentRepository\StructureAdjustment\Adjustment\StructureAdjustment; use Neos\ContentRepository\StructureAdjustment\Adjustment\TetheredNodeAdjustments; @@ -29,38 +29,45 @@ class StructureAdjustmentService implements ContentRepositoryServiceInterface protected PropertyAdjustment $propertyAdjustment; protected DimensionAdjustment $dimensionAdjustment; + /** + * Content graph bound to the live workspace to iterate over the "real" Nodes; that is, the nodes, + * which have an entry in the Graph Projection's "node" table. + * + * @var ContentGraphInterface + */ + private readonly ContentGraphInterface $liveContentGraph; + public function __construct( - private readonly ContentRepository $contentRepository, + ContentRepository $contentRepository, private readonly EventPersister $eventPersister, NodeTypeManager $nodeTypeManager, InterDimensionalVariationGraph $interDimensionalVariationGraph, PropertyConverter $propertyConverter, ) { - $projectedNodeIterator = new ProjectedNodeIterator( - $contentRepository->getContentGraph(WorkspaceName::forLive()), - ); + + $this->liveContentGraph = $contentRepository->getContentGraph(WorkspaceName::forLive()); $this->tetheredNodeAdjustments = new TetheredNodeAdjustments( - $projectedNodeIterator, + $this->liveContentGraph, $nodeTypeManager, $interDimensionalVariationGraph, $propertyConverter ); $this->unknownNodeTypeAdjustment = new UnknownNodeTypeAdjustment( - $projectedNodeIterator, + $this->liveContentGraph, $nodeTypeManager ); $this->disallowedChildNodeAdjustment = new DisallowedChildNodeAdjustment( - $projectedNodeIterator, + $this->liveContentGraph, $nodeTypeManager ); $this->propertyAdjustment = new PropertyAdjustment( - $projectedNodeIterator, + $this->liveContentGraph, $nodeTypeManager ); $this->dimensionAdjustment = new DimensionAdjustment( - $projectedNodeIterator, + $this->liveContentGraph, $interDimensionalVariationGraph, $nodeTypeManager ); @@ -71,7 +78,7 @@ public function __construct( */ public function findAllAdjustments(): \Generator { - foreach ($this->contentRepository->getContentGraph(WorkspaceName::forLive())->findUsedNodeTypeNames() as $nodeTypeName) { + foreach ($this->liveContentGraph->findUsedNodeTypeNames() as $nodeTypeName) { yield from $this->findAdjustmentsForNodeType($nodeTypeName); } }