Skip to content

Commit

Permalink
WIP: Prepare node factory to build nodes with node identity
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Mar 18, 2024
1 parent 86a4709 commit c9feaca
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,6 +87,8 @@ final public function getSubgraph(
new ContentSubgraph(
$this->contentRepositoryId,
$contentStreamId,
// todo accept Workspace
WorkspaceName::forLive(),
$dimensionSpacePoint,
$visibilityConstraints,
$this->client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -359,7 +361,8 @@ public function findAncestorNodes(NodeAggregateId $entryNodeAggregateId, FindAnc
$nodeRows,
$this->contentStreamId,
$this->dimensionSpacePoint,
$this->visibilityConstraints
$this->visibilityConstraints,
$this->workspaceName
);
}

Expand Down Expand Up @@ -420,7 +423,8 @@ public function findClosestNode(NodeAggregateId $entryNodeAggregateId, FindClose
$nodeRows,
$this->contentStreamId,
$this->dimensionSpacePoint,
$this->visibilityConstraints
$this->visibilityConstraints,
$this->workspaceName
)->first();
}

Expand All @@ -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
Expand Down Expand Up @@ -865,7 +869,8 @@ private function fetchNode(QueryBuilder $queryBuilder): ?Node
$nodeRow,
$this->contentStreamId,
$this->dimensionSpacePoint,
$this->visibilityConstraints
$this->visibilityConstraints,
$this->workspaceName
);
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']),
Expand All @@ -98,10 +107,10 @@ public function mapNodeRowToNode(
/**
* @param array<int, array<string, mixed>> $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)
);
}

Expand All @@ -128,7 +137,8 @@ public function mapReferenceRowsToReferences(
$nodeRow,
$contentStreamId,
$dimensionSpacePoint,
$visibilityConstraints
$visibilityConstraints,
null // todo

Check failure on line 141 in Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Parameter #5 $workspaceName of method Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory::mapNodeRowToNode() expects Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName, null given.

Check failure on line 141 in Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

Parameter #5 $workspaceName of method Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory::mapNodeRowToNode() expects Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName, null given.
);
$result[] = new Reference(
$node,
Expand Down Expand Up @@ -178,7 +188,8 @@ public function mapNodeRowsToNodeAggregate(
$nodeRow,
$contentStreamId,
$occupiedDimensionSpacePoint->toDimensionSpacePoint(),
$visibilityConstraints
$visibilityConstraints,
null // todo

Check failure on line 192 in Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Parameter #5 $workspaceName of method Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory::mapNodeRowToNode() expects Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName, null given.

Check failure on line 192 in Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

Parameter #5 $workspaceName of method Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory::mapNodeRowToNode() expects Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName, null given.
);
$occupiedDimensionSpacePoints[] = $occupiedDimensionSpacePoint;
$rawNodeAggregateId = $rawNodeAggregateId ?: $nodeRow['nodeaggregateid'];
Expand Down Expand Up @@ -261,7 +272,8 @@ public function mapNodeRowsToNodeAggregates(
$nodeRow,
$contentStreamId,
$occupiedDimensionSpacePoint->toDimensionSpacePoint(),
$visibilityConstraints
$visibilityConstraints,
null // todo

Check failure on line 276 in Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Parameter #5 $workspaceName of method Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory::mapNodeRowToNode() expects Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName, null given.

Check failure on line 276 in Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

Parameter #5 $workspaceName of method Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory::mapNodeRowToNode() expects Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName, null given.
);
$occupiedDimensionSpacePointsByNodeAggregate[$rawNodeAggregateId][]
= $occupiedDimensionSpacePoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c9feaca

Please sign in to comment.