From d24324b9b53cc8e4d29a81c6c139cca470264a74 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Thu, 14 Mar 2024 09:52:40 +0100 Subject: [PATCH] TASK: Pass ContentStreamId to NodeFactory --- .../src/Domain/Repository/ContentGraph.php | 17 ++++++++++------- .../src/Domain/Repository/ContentSubgraph.php | 11 +++++++---- .../src/Domain/Repository/NodeFactory.php | 13 ++++++++++--- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentGraph.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentGraph.php index 3ce6f4b36ac..b31c8e424ee 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentGraph.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentGraph.php @@ -152,7 +152,7 @@ public function findRootNodeAggregates( ->andWhere('n.nodetypename = :nodeTypeName') ->setParameter('nodeTypeName', $filter->nodeTypeName->value); } - return NodeAggregates::fromArray(iterator_to_array($this->mapQueryBuilderToNodeAggregates($queryBuilder))); + return NodeAggregates::fromArray(iterator_to_array($this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId))); } public function findNodeAggregatesByType( @@ -169,7 +169,7 @@ public function findNodeAggregatesByType( 'contentStreamId' => $contentStreamId->value, 'nodeTypeName' => $nodeTypeName->value, ]); - return $this->mapQueryBuilderToNodeAggregates($queryBuilder); + return $this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId); } public function findNodeAggregateById( @@ -189,6 +189,7 @@ public function findNodeAggregateById( return $this->nodeFactory->mapNodeRowsToNodeAggregate( $this->fetchRows($queryBuilder), + $contentStreamId, VisibilityConstraints::withoutRestrictions() ); } @@ -214,7 +215,7 @@ public function findParentNodeAggregates( 'contentStreamId' => $contentStreamId->value ]); - return $this->mapQueryBuilderToNodeAggregates($queryBuilder); + return $this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId); } public function findParentNodeAggregateByChildOriginDimensionSpacePoint( @@ -246,6 +247,7 @@ public function findParentNodeAggregateByChildOriginDimensionSpacePoint( return $this->nodeFactory->mapNodeRowsToNodeAggregate( $this->fetchRows($queryBuilder), + $contentStreamId, VisibilityConstraints::withoutRestrictions() ); } @@ -258,7 +260,7 @@ public function findChildNodeAggregates( NodeAggregateId $parentNodeAggregateId ): iterable { $queryBuilder = $this->buildChildNodeAggregateQuery($parentNodeAggregateId, $contentStreamId); - return $this->mapQueryBuilderToNodeAggregates($queryBuilder); + return $this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId); } /** @@ -272,7 +274,7 @@ public function findChildNodeAggregatesByName( $queryBuilder = $this->buildChildNodeAggregateQuery($parentNodeAggregateId, $contentStreamId) ->andWhere('ch.name = :relationName') ->setParameter('relationName', $name->value); - return $this->mapQueryBuilderToNodeAggregates($queryBuilder); + return $this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId); } /** @@ -285,7 +287,7 @@ public function findTetheredChildNodeAggregates( $queryBuilder = $this->buildChildNodeAggregateQuery($parentNodeAggregateId, $contentStreamId) ->andWhere('cn.classification = :tetheredClassification') ->setParameter('tetheredClassification', NodeAggregateClassification::CLASSIFICATION_TETHERED->value); - return $this->mapQueryBuilderToNodeAggregates($queryBuilder); + return $this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId); } /** @@ -390,10 +392,11 @@ private function createQueryBuilder(): QueryBuilder * @param QueryBuilder $queryBuilder * @return iterable */ - private function mapQueryBuilderToNodeAggregates(QueryBuilder $queryBuilder): iterable + private function mapQueryBuilderToNodeAggregates(QueryBuilder $queryBuilder, ContentStreamId $contentStreamId): iterable { return $this->nodeFactory->mapNodeRowsToNodeAggregates( $this->fetchRows($queryBuilder), + $contentStreamId, VisibilityConstraints::withoutRestrictions() ); } diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentSubgraph.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentSubgraph.php index 420e8e4a43a..f503f676211 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentSubgraph.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentSubgraph.php @@ -328,7 +328,7 @@ public function findSubtree(NodeAggregateId $entryNodeAggregateId, FindSubtreeFi foreach (array_reverse($result) as $nodeData) { $nodeAggregateId = $nodeData['nodeaggregateid']; $parentNodeAggregateId = $nodeData['parentNodeAggregateId']; - $node = $this->nodeFactory->mapNodeRowToNode($nodeData, $this->dimensionSpacePoint, $this->visibilityConstraints); + $node = $this->nodeFactory->mapNodeRowToNode($nodeData, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints); $subtree = new Subtree((int)$nodeData['level'], $node, array_key_exists($nodeAggregateId, $subtreesByParentNodeId) ? array_reverse($subtreesByParentNodeId[$nodeAggregateId]) : []); if ($subtree->level === 0) { return $subtree; @@ -357,6 +357,7 @@ public function findAncestorNodes(NodeAggregateId $entryNodeAggregateId, FindAnc return $this->nodeFactory->mapNodeRowsToNodes( $nodeRows, + $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints ); @@ -417,6 +418,7 @@ public function findClosestNode(NodeAggregateId $entryNodeAggregateId, FindClose ); return $this->nodeFactory->mapNodeRowsToNodes( $nodeRows, + $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints )->first(); @@ -433,7 +435,7 @@ public function findDescendantNodes(NodeAggregateId $entryNodeAggregateId, FindD } $queryBuilderCte->addOrderBy('level')->addOrderBy('position'); $nodeRows = $this->fetchCteResults($queryBuilderInitial, $queryBuilderRecursive, $queryBuilderCte, 'tree'); - return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->dimensionSpacePoint, $this->visibilityConstraints); + return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints); } public function countDescendantNodes(NodeAggregateId $entryNodeAggregateId, CountDescendantNodesFilter $filter): int @@ -861,6 +863,7 @@ private function fetchNode(QueryBuilder $queryBuilder): ?Node } return $this->nodeFactory->mapNodeRowToNode( $nodeRow, + $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints ); @@ -873,7 +876,7 @@ private function fetchNodes(QueryBuilder $queryBuilder): Nodes } catch (DbalDriverException | DbalException $e) { throw new \RuntimeException(sprintf('Failed to fetch nodes: %s', $e->getMessage()), 1678292896, $e); } - return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->dimensionSpacePoint, $this->visibilityConstraints); + return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints); } private function fetchCount(QueryBuilder $queryBuilder): int @@ -892,7 +895,7 @@ private function fetchReferences(QueryBuilder $queryBuilder): References } catch (DbalDriverException | DbalException $e) { throw new \RuntimeException(sprintf('Failed to fetch references: %s', $e->getMessage()), 1678364944, $e); } - return $this->nodeFactory->mapReferenceRowsToReferences($referenceRows, $this->dimensionSpacePoint, $this->visibilityConstraints); + return $this->nodeFactory->mapReferenceRowsToReferences($referenceRows, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints); } /** diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php index 86d5a2c663b..ff629bc8732 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php @@ -64,6 +64,7 @@ public function __construct( */ public function mapNodeRowToNode( array $nodeRow, + ContentStreamId $contentStreamId, DimensionSpacePoint $dimensionSpacePoint, VisibilityConstraints $visibilityConstraints ): Node { @@ -74,7 +75,7 @@ public function mapNodeRowToNode( return Node::create( ContentSubgraphIdentity::create( $this->contentRepositoryId, - ContentStreamId::fromString($nodeRow['contentstreamid']), + $contentStreamId, $dimensionSpacePoint, $visibilityConstraints ), @@ -98,10 +99,10 @@ public function mapNodeRowToNode( /** * @param array> $nodeRows */ - public function mapNodeRowsToNodes(array $nodeRows, DimensionSpacePoint $dimensionSpacePoint, VisibilityConstraints $visibilityConstraints): Nodes + public function mapNodeRowsToNodes(array $nodeRows, ContentStreamId $contentStreamId, DimensionSpacePoint $dimensionSpacePoint, VisibilityConstraints $visibilityConstraints): Nodes { return Nodes::fromArray( - array_map(fn (array $nodeRow) => $this->mapNodeRowToNode($nodeRow, $dimensionSpacePoint, $visibilityConstraints), $nodeRows) + array_map(fn (array $nodeRow) => $this->mapNodeRowToNode($nodeRow, $contentStreamId, $dimensionSpacePoint, $visibilityConstraints), $nodeRows) ); } @@ -118,6 +119,7 @@ public function createPropertyCollectionFromJsonString(string $jsonString): Prop */ public function mapReferenceRowsToReferences( array $nodeRows, + ContentStreamId $contentStreamId, DimensionSpacePoint $dimensionSpacePoint, VisibilityConstraints $visibilityConstraints ): References { @@ -125,6 +127,7 @@ public function mapReferenceRowsToReferences( foreach ($nodeRows as $nodeRow) { $node = $this->mapNodeRowToNode( $nodeRow, + $contentStreamId, $dimensionSpacePoint, $visibilityConstraints ); @@ -146,6 +149,7 @@ public function mapReferenceRowsToReferences( */ public function mapNodeRowsToNodeAggregate( array $nodeRows, + ContentStreamId $contentStreamId, VisibilityConstraints $visibilityConstraints ): ?NodeAggregate { if (empty($nodeRows)) { @@ -173,6 +177,7 @@ public function mapNodeRowsToNodeAggregate( // ... so we handle occupation exactly once ... $nodesByOccupiedDimensionSpacePoints[$occupiedDimensionSpacePoint->hash] = $this->mapNodeRowToNode( $nodeRow, + $contentStreamId, $occupiedDimensionSpacePoint->toDimensionSpacePoint(), $visibilityConstraints ); @@ -227,6 +232,7 @@ public function mapNodeRowsToNodeAggregate( */ public function mapNodeRowsToNodeAggregates( iterable $nodeRows, + ContentStreamId $contentStreamId, VisibilityConstraints $visibilityConstraints ): iterable { $nodeTypeNames = []; @@ -254,6 +260,7 @@ public function mapNodeRowsToNodeAggregates( $nodesByOccupiedDimensionSpacePointsByNodeAggregate [$rawNodeAggregateId][$occupiedDimensionSpacePoint->hash] = $this->mapNodeRowToNode( $nodeRow, + $contentStreamId, $occupiedDimensionSpacePoint->toDimensionSpacePoint(), $visibilityConstraints );