From c9feaca27ea99199b2aac4de263efd73a87d29d1 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Tue, 19 Mar 2024 00:10:03 +0100 Subject: [PATCH] WIP: Prepare node factory to build nodes with node identity --- .../src/Domain/Repository/ContentGraph.php | 3 +++ .../src/Domain/Repository/ContentSubgraph.php | 17 +++++++----- .../src/Domain/Repository/NodeFactory.php | 26 ++++++++++++++----- .../src/Domain/Repository/NodeFactory.php | 11 +++++++- .../Classes/Projection/ContentGraph/Node.php | 9 +++++-- .../Projection/ContentGraph/NodeAggregate.php | 1 + .../Classes/Unit/NodeSubjectProvider.php | 10 ++++++- 7 files changed, 60 insertions(+), 17 deletions(-) diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentGraph.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentGraph.php index 93381ed2fe5..ad9d221e80a 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentGraph.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentGraph.php @@ -40,6 +40,7 @@ use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; use Neos\ContentRepository\Core\SharedModel\Node\NodeName; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; /** * The Doctrine DBAL adapter content graph @@ -86,6 +87,8 @@ final public function getSubgraph( new ContentSubgraph( $this->contentRepositoryId, $contentStreamId, + // todo accept Workspace + WorkspaceName::forLive(), $dimensionSpacePoint, $visibilityConstraints, $this->client, diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentSubgraph.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentSubgraph.php index c1a278822d7..6f36cb83504 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentSubgraph.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentSubgraph.php @@ -72,6 +72,7 @@ use Neos\ContentRepository\Core\SharedModel\Node\NodeName; use Neos\ContentRepository\Core\SharedModel\Node\PropertyName; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; /** * The content subgraph application repository @@ -106,6 +107,7 @@ final class ContentSubgraph implements ContentSubgraphInterface public function __construct( private readonly ContentRepositoryId $contentRepositoryId, private readonly ContentStreamId $contentStreamId, + private readonly WorkspaceName $workspaceName, private readonly DimensionSpacePoint $dimensionSpacePoint, private readonly VisibilityConstraints $visibilityConstraints, private readonly DbalClientInterface $client, @@ -328,7 +330,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->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints); + $node = $this->nodeFactory->mapNodeRowToNode($nodeData, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints, $this->workspaceName); $subtree = new Subtree((int)$nodeData['level'], $node, array_key_exists($nodeAggregateId, $subtreesByParentNodeId) ? array_reverse($subtreesByParentNodeId[$nodeAggregateId]) : []); if ($subtree->level === 0) { return $subtree; @@ -359,7 +361,8 @@ public function findAncestorNodes(NodeAggregateId $entryNodeAggregateId, FindAnc $nodeRows, $this->contentStreamId, $this->dimensionSpacePoint, - $this->visibilityConstraints + $this->visibilityConstraints, + $this->workspaceName ); } @@ -420,7 +423,8 @@ public function findClosestNode(NodeAggregateId $entryNodeAggregateId, FindClose $nodeRows, $this->contentStreamId, $this->dimensionSpacePoint, - $this->visibilityConstraints + $this->visibilityConstraints, + $this->workspaceName )->first(); } @@ -435,7 +439,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->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints); + return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints, $this->workspaceName); } public function countDescendantNodes(NodeAggregateId $entryNodeAggregateId, CountDescendantNodesFilter $filter): int @@ -865,7 +869,8 @@ private function fetchNode(QueryBuilder $queryBuilder): ?Node $nodeRow, $this->contentStreamId, $this->dimensionSpacePoint, - $this->visibilityConstraints + $this->visibilityConstraints, + $this->workspaceName ); } @@ -876,7 +881,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->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints); + return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints, $this->workspaceName); } private function fetchCount(QueryBuilder $queryBuilder): int diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php index 837b7767eda..85d502bcf44 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php @@ -40,9 +40,11 @@ use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeNotFoundException; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; +use Neos\ContentRepository\Core\SharedModel\Node\NodeIdentity; use Neos\ContentRepository\Core\SharedModel\Node\NodeName; use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; /** * Implementation detail of ContentGraph and ContentSubgraph @@ -65,20 +67,27 @@ public function mapNodeRowToNode( array $nodeRow, ContentStreamId $contentStreamId, DimensionSpacePoint $dimensionSpacePoint, - VisibilityConstraints $visibilityConstraints + VisibilityConstraints $visibilityConstraints, + WorkspaceName $workspaceName, ): Node { $nodeType = $this->nodeTypeManager->hasNodeType($nodeRow['nodetypename']) ? $this->nodeTypeManager->getNodeType($nodeRow['nodetypename']) : null; return Node::create( + NodeIdentity::create( + $this->contentRepositoryId, + $workspaceName, + $dimensionSpacePoint, + $nodeId = NodeAggregateId::fromString($nodeRow['nodeaggregateid']) + ), ContentSubgraphIdentity::create( $this->contentRepositoryId, $contentStreamId, $dimensionSpacePoint, $visibilityConstraints ), - NodeAggregateId::fromString($nodeRow['nodeaggregateid']), + $nodeId, OriginDimensionSpacePoint::fromJsonString($nodeRow['origindimensionspacepoint']), NodeAggregateClassification::from($nodeRow['classification']), NodeTypeName::fromString($nodeRow['nodetypename']), @@ -98,10 +107,10 @@ public function mapNodeRowToNode( /** * @param array> $nodeRows */ - public function mapNodeRowsToNodes(array $nodeRows, ContentStreamId $contentStreamId, DimensionSpacePoint $dimensionSpacePoint, VisibilityConstraints $visibilityConstraints): Nodes + public function mapNodeRowsToNodes(array $nodeRows, ContentStreamId $contentStreamId, DimensionSpacePoint $dimensionSpacePoint, VisibilityConstraints $visibilityConstraints, WorkspaceName $workspaceName): Nodes { return Nodes::fromArray( - array_map(fn (array $nodeRow) => $this->mapNodeRowToNode($nodeRow, $contentStreamId, $dimensionSpacePoint, $visibilityConstraints), $nodeRows) + array_map(fn (array $nodeRow) => $this->mapNodeRowToNode($nodeRow, $contentStreamId, $dimensionSpacePoint, $visibilityConstraints, $workspaceName), $nodeRows) ); } @@ -128,7 +137,8 @@ public function mapReferenceRowsToReferences( $nodeRow, $contentStreamId, $dimensionSpacePoint, - $visibilityConstraints + $visibilityConstraints, + null // todo ); $result[] = new Reference( $node, @@ -178,7 +188,8 @@ public function mapNodeRowsToNodeAggregate( $nodeRow, $contentStreamId, $occupiedDimensionSpacePoint->toDimensionSpacePoint(), - $visibilityConstraints + $visibilityConstraints, + null // todo ); $occupiedDimensionSpacePoints[] = $occupiedDimensionSpacePoint; $rawNodeAggregateId = $rawNodeAggregateId ?: $nodeRow['nodeaggregateid']; @@ -261,7 +272,8 @@ public function mapNodeRowsToNodeAggregates( $nodeRow, $contentStreamId, $occupiedDimensionSpacePoint->toDimensionSpacePoint(), - $visibilityConstraints + $visibilityConstraints, + null // todo ); $occupiedDimensionSpacePointsByNodeAggregate[$rawNodeAggregateId][] = $occupiedDimensionSpacePoint; diff --git a/Neos.ContentGraph.PostgreSQLAdapter/src/Domain/Repository/NodeFactory.php b/Neos.ContentGraph.PostgreSQLAdapter/src/Domain/Repository/NodeFactory.php index da9b96cf28c..147283b0735 100644 --- a/Neos.ContentGraph.PostgreSQLAdapter/src/Domain/Repository/NodeFactory.php +++ b/Neos.ContentGraph.PostgreSQLAdapter/src/Domain/Repository/NodeFactory.php @@ -39,9 +39,11 @@ use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; +use Neos\ContentRepository\Core\SharedModel\Node\NodeIdentity; use Neos\ContentRepository\Core\SharedModel\Node\NodeName; use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; /** * The node factory for mapping database rows to nodes and node aggregates @@ -77,13 +79,20 @@ public function mapNodeRowToNode( : null; return Node::create( + NodeIdentity::create( + $this->contentRepositoryId, + // todo use actual workspace name + WorkspaceName::fromString('missing'), + $dimensionSpacePoint ?: DimensionSpacePoint::fromJsonString($nodeRow['dimensionspacepoint']), + $nodeId = NodeAggregateId::fromString($nodeRow['nodeaggregateid']) + ), ContentSubgraphIdentity::create( $this->contentRepositoryId, $contentStreamId ?: ContentStreamId::fromString($nodeRow['contentstreamid']), $dimensionSpacePoint ?: DimensionSpacePoint::fromJsonString($nodeRow['dimensionspacepoint']), $visibilityConstraints ), - NodeAggregateId::fromString($nodeRow['nodeaggregateid']), + $nodeId, OriginDimensionSpacePoint::fromJsonString($nodeRow['origindimensionspacepoint']), NodeAggregateClassification::from($nodeRow['classification']), NodeTypeName::fromString($nodeRow['nodetypename']), diff --git a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/Node.php b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/Node.php index e89b8aec790..e86a7c17c77 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/Node.php +++ b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/Node.php @@ -19,6 +19,7 @@ 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\Node\NodeIdentity; use Neos\ContentRepository\Core\SharedModel\Node\NodeName; /** @@ -34,6 +35,8 @@ * call findChildNodes() {@see ContentSubgraphInterface::findChildNodes()} * on the subgraph. * + * The identity of a node is summarized here {@see NodeIdentity} + * * @api Note: The constructor is not part of the public API */ final readonly class Node @@ -51,6 +54,8 @@ * @param Timestamps $timestamps Creation and modification timestamps of this node */ private function __construct( + public NodeIdentity $identity, + /** @deprecated will be removed before the final 9.0 release */ public ContentSubgraphIdentity $subgraphIdentity, public NodeAggregateId $nodeAggregateId, public OriginDimensionSpacePoint $originDimensionSpacePoint, @@ -70,9 +75,9 @@ private function __construct( /** * @internal The signature of this method can change in the future! */ - public static function create(ContentSubgraphIdentity $subgraphIdentity, NodeAggregateId $nodeAggregateId, OriginDimensionSpacePoint $originDimensionSpacePoint, NodeAggregateClassification $classification, NodeTypeName $nodeTypeName, ?NodeType $nodeType, PropertyCollection $properties, ?NodeName $nodeName, NodeTags $tags, Timestamps $timestamps): self + public static function create(NodeIdentity $identity, ContentSubgraphIdentity $subgraphIdentity, NodeAggregateId $nodeAggregateId, OriginDimensionSpacePoint $originDimensionSpacePoint, NodeAggregateClassification $classification, NodeTypeName $nodeTypeName, ?NodeType $nodeType, PropertyCollection $properties, ?NodeName $nodeName, NodeTags $tags, Timestamps $timestamps): self { - return new self($subgraphIdentity, $nodeAggregateId, $originDimensionSpacePoint, $classification, $nodeTypeName, $nodeType, $properties, $nodeName, $tags, $timestamps); + return new self($identity, $subgraphIdentity, $nodeAggregateId, $originDimensionSpacePoint, $classification, $nodeTypeName, $nodeType, $properties, $nodeName, $tags, $timestamps); } /** diff --git a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/NodeAggregate.php b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/NodeAggregate.php index 8db6d42a471..cfe4f4d07f4 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/NodeAggregate.php +++ b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/NodeAggregate.php @@ -65,6 +65,7 @@ final class NodeAggregate * @param OriginByCoverage $occupationByCovered * @param DimensionSpacePointsBySubtreeTags $dimensionSpacePointsBySubtreeTags dimension space points for every subtree tag this aggregate is *explicitly* tagged with (excluding inherited tags) */ + // todo add workspace name? public function __construct( public readonly ContentStreamId $contentStreamId, public readonly NodeAggregateId $nodeAggregateId, diff --git a/Neos.ContentRepository.TestSuite/Classes/Unit/NodeSubjectProvider.php b/Neos.ContentRepository.TestSuite/Classes/Unit/NodeSubjectProvider.php index 61ce76d10d0..1b1abc4fb62 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Unit/NodeSubjectProvider.php +++ b/Neos.ContentRepository.TestSuite/Classes/Unit/NodeSubjectProvider.php @@ -37,8 +37,10 @@ use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; +use Neos\ContentRepository\Core\SharedModel\Node\NodeIdentity; use Neos\ContentRepository\Core\SharedModel\Node\NodeName; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer; use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer; use Symfony\Component\Serializer\Serializer; @@ -87,13 +89,19 @@ public function createMinimalNodeOfType( ): Node { $serializedDefaultPropertyValues = SerializedPropertyValues::defaultFromNodeType($nodeType, $this->propertyConverter); return Node::create( + NodeIdentity::create( + ContentRepositoryId::fromString('default'), + WorkspaceName::forLive(), + DimensionSpacePoint::createWithoutDimensions(), + $id = NodeAggregateId::create() + ), ContentSubgraphIdentity::create( ContentRepositoryId::fromString('default'), ContentStreamId::fromString('cs-id'), DimensionSpacePoint::createWithoutDimensions(), VisibilityConstraints::withoutRestrictions() ), - NodeAggregateId::create(), + $id, OriginDimensionSpacePoint::createWithoutDimensions(), NodeAggregateClassification::CLASSIFICATION_REGULAR, $nodeType->name,