Skip to content

Commit 96ce9e9

Browse files
authored
Merge pull request #5042 from neos/task/workspaceAwareNode
FEATURE: workspace aware Node (introduce new `NodeAdress`)
2 parents 6cd089a + 4e5993a commit 96ce9e9

File tree

35 files changed

+537
-256
lines changed

35 files changed

+537
-256
lines changed

Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentGraph.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ public function __construct(
8484
$this->nodeQueryBuilder = new NodeQueryBuilder($this->client->getConnection(), $this->tableNames);
8585
}
8686

87+
public function getContentRepositoryId(): ContentRepositoryId
88+
{
89+
return $this->contentRepositoryId;
90+
}
91+
92+
public function getWorkspaceName(): WorkspaceName
93+
{
94+
return $this->workspaceName;
95+
}
96+
8797
public function getSubgraph(
8898
DimensionSpacePoint $dimensionSpacePoint,
8999
VisibilityConstraints $visibilityConstraints
@@ -171,6 +181,7 @@ public function findNodeAggregateById(
171181

172182
return $this->nodeFactory->mapNodeRowsToNodeAggregate(
173183
$this->fetchRows($queryBuilder),
184+
$this->workspaceName,
174185
$this->contentStreamId,
175186
VisibilityConstraints::withoutRestrictions()
176187
);
@@ -236,6 +247,7 @@ public function findParentNodeAggregateByChildOriginDimensionSpacePoint(NodeAggr
236247

237248
return $this->nodeFactory->mapNodeRowsToNodeAggregate(
238249
$this->fetchRows($queryBuilder),
250+
$this->workspaceName,
239251
$this->contentStreamId,
240252
VisibilityConstraints::withoutRestrictions()
241253
);
@@ -304,7 +316,7 @@ public function countNodes(): int
304316
try {
305317
return (int)$result->fetchOne();
306318
} catch (DriverException | DBALException $e) {
307-
throw new \RuntimeException(sprintf('Failed to fetch rows from database: %s', $e->getMessage()), 1701444590, $e);
319+
throw new \RuntimeException(sprintf('Failed to count rows in database: %s', $e->getMessage()), 1701444590, $e);
308320
}
309321
}
310322

@@ -325,6 +337,7 @@ private function mapQueryBuilderToNodeAggregate(QueryBuilder $queryBuilder): ?No
325337
{
326338
return $this->nodeFactory->mapNodeRowsToNodeAggregate(
327339
$this->fetchRows($queryBuilder),
340+
$this->workspaceName,
328341
$this->contentStreamId,
329342
VisibilityConstraints::withoutRestrictions()
330343
);
@@ -338,6 +351,7 @@ private function mapQueryBuilderToNodeAggregates(QueryBuilder $queryBuilder): it
338351
{
339352
return $this->nodeFactory->mapNodeRowsToNodeAggregates(
340353
$this->fetchRows($queryBuilder),
354+
$this->workspaceName,
341355
$this->contentStreamId,
342356
VisibilityConstraints::withoutRestrictions()
343357
);
@@ -359,13 +373,6 @@ private function fetchRows(QueryBuilder $queryBuilder): array
359373
}
360374
}
361375

362-
/** The workspace this content graph is operating on */
363-
public function getWorkspaceName(): WorkspaceName
364-
{
365-
return $this->workspaceName;
366-
}
367-
368-
/** @internal The content stream id where the workspace name points to for this instance */
369376
public function getContentStreamId(): ContentStreamId
370377
{
371378
return $this->contentStreamId;

Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/ContentSubgraph.php

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ final class ContentSubgraph implements ContentSubgraphInterface
9292

9393
public function __construct(
9494
private readonly ContentRepositoryId $contentRepositoryId,
95-
/** @phpstan-ignore-next-line */
9695
private readonly WorkspaceName $workspaceName,
9796
private readonly ContentStreamId $contentStreamId,
9897
private readonly DimensionSpacePoint $dimensionSpacePoint,
@@ -105,14 +104,24 @@ public function __construct(
105104
$this->nodeQueryBuilder = new NodeQueryBuilder($this->client->getConnection(), $tableNames);
106105
}
107106

108-
public function getIdentity(): ContentSubgraphIdentity
107+
public function getContentRepositoryId(): ContentRepositoryId
109108
{
110-
return ContentSubgraphIdentity::create(
111-
$this->contentRepositoryId,
112-
$this->contentStreamId,
113-
$this->dimensionSpacePoint,
114-
$this->visibilityConstraints
115-
);
109+
return $this->contentRepositoryId;
110+
}
111+
112+
public function getWorkspaceName(): WorkspaceName
113+
{
114+
return $this->workspaceName;
115+
}
116+
117+
public function getDimensionSpacePoint(): DimensionSpacePoint
118+
{
119+
return $this->dimensionSpacePoint;
120+
}
121+
122+
public function getVisibilityConstraints(): VisibilityConstraints
123+
{
124+
return $this->visibilityConstraints;
116125
}
117126

118127
public function findChildNodes(NodeAggregateId $parentNodeAggregateId, FindChildNodesFilter $filter): Nodes
@@ -290,7 +299,13 @@ public function findSubtree(NodeAggregateId $entryNodeAggregateId, FindSubtreeFi
290299
foreach (array_reverse($result) as $nodeData) {
291300
$nodeAggregateId = $nodeData['nodeaggregateid'];
292301
$parentNodeAggregateId = $nodeData['parentNodeAggregateId'];
293-
$node = $this->nodeFactory->mapNodeRowToNode($nodeData, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints);
302+
$node = $this->nodeFactory->mapNodeRowToNode(
303+
$nodeData,
304+
$this->workspaceName,
305+
$this->contentStreamId,
306+
$this->dimensionSpacePoint,
307+
$this->visibilityConstraints
308+
);
294309
$subtree = new Subtree((int)$nodeData['level'], $node, array_key_exists($nodeAggregateId, $subtreesByParentNodeId) ? array_reverse($subtreesByParentNodeId[$nodeAggregateId]) : []);
295310
if ($subtree->level === 0) {
296311
return $subtree;
@@ -319,6 +334,7 @@ public function findAncestorNodes(NodeAggregateId $entryNodeAggregateId, FindAnc
319334

320335
return $this->nodeFactory->mapNodeRowsToNodes(
321336
$nodeRows,
337+
$this->workspaceName,
322338
$this->contentStreamId,
323339
$this->dimensionSpacePoint,
324340
$this->visibilityConstraints
@@ -374,6 +390,7 @@ public function findClosestNode(NodeAggregateId $entryNodeAggregateId, FindClose
374390
);
375391
return $this->nodeFactory->mapNodeRowsToNodes(
376392
$nodeRows,
393+
$this->workspaceName,
377394
$this->contentStreamId,
378395
$this->dimensionSpacePoint,
379396
$this->visibilityConstraints
@@ -391,7 +408,13 @@ public function findDescendantNodes(NodeAggregateId $entryNodeAggregateId, FindD
391408
}
392409
$queryBuilderCte->addOrderBy('level')->addOrderBy('position');
393410
$nodeRows = $this->fetchCteResults($queryBuilderInitial, $queryBuilderRecursive, $queryBuilderCte, 'tree');
394-
return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints);
411+
return $this->nodeFactory->mapNodeRowsToNodes(
412+
$nodeRows,
413+
$this->workspaceName,
414+
$this->contentStreamId,
415+
$this->dimensionSpacePoint,
416+
$this->visibilityConstraints
417+
);
395418
}
396419

397420
public function countDescendantNodes(NodeAggregateId $entryNodeAggregateId, CountDescendantNodesFilter $filter): int
@@ -416,9 +439,15 @@ public function countNodes(): int
416439
return $result;
417440
}
418441

419-
public function jsonSerialize(): ContentSubgraphIdentity
442+
/**
443+
* @return array<string,mixed>
444+
*/
445+
public function jsonSerialize(): array
420446
{
421-
return $this->getIdentity();
447+
return [
448+
'workspaceName' => $this->workspaceName,
449+
'dimensionSpacePoint' => $this->dimensionSpacePoint,
450+
];
422451
}
423452

424453
/** ------------------------------------------- */
@@ -668,6 +697,7 @@ private function fetchNode(QueryBuilder $queryBuilder): ?Node
668697
}
669698
return $this->nodeFactory->mapNodeRowToNode(
670699
$nodeRow,
700+
$this->workspaceName,
671701
$this->contentStreamId,
672702
$this->dimensionSpacePoint,
673703
$this->visibilityConstraints
@@ -681,7 +711,13 @@ private function fetchNodes(QueryBuilder $queryBuilder): Nodes
681711
} catch (DbalDriverException | DbalException $e) {
682712
throw new \RuntimeException(sprintf('Failed to fetch nodes: %s', $e->getMessage()), 1678292896, $e);
683713
}
684-
return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints);
714+
return $this->nodeFactory->mapNodeRowsToNodes(
715+
$nodeRows,
716+
$this->workspaceName,
717+
$this->contentStreamId,
718+
$this->dimensionSpacePoint,
719+
$this->visibilityConstraints
720+
);
685721
}
686722

687723
private function fetchCount(QueryBuilder $queryBuilder): int
@@ -700,7 +736,7 @@ private function fetchReferences(QueryBuilder $queryBuilder): References
700736
} catch (DbalDriverException | DbalException $e) {
701737
throw new \RuntimeException(sprintf('Failed to fetch references: %s', $e->getMessage()), 1678364944, $e);
702738
}
703-
return $this->nodeFactory->mapReferenceRowsToReferences($referenceRows, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints);
739+
return $this->nodeFactory->mapReferenceRowsToReferences($referenceRows, $this->workspaceName, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints);
704740
}
705741

706742
/**

Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository/NodeFactory.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
1818
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
19-
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
2019
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePointSet;
2120
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
2221
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Dto\SubtreeTags;
@@ -38,11 +37,13 @@
3837
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
3938
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
4039
use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeNotFoundException;
40+
use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress;
4141
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
4242
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
4343
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
4444
use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName;
4545
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
46+
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
4647

4748
/**
4849
* Implementation detail of ContentGraph and ContentSubgraph
@@ -64,6 +65,7 @@ public function __construct(
6465
*/
6566
public function mapNodeRowToNode(
6667
array $nodeRow,
68+
WorkspaceName $workspaceName,
6769
ContentStreamId $contentStreamId,
6870
DimensionSpacePoint $dimensionSpacePoint,
6971
VisibilityConstraints $visibilityConstraints
@@ -73,17 +75,13 @@ public function mapNodeRowToNode(
7375
: null;
7476

7577
return Node::create(
76-
ContentSubgraphIdentity::create(
77-
$this->contentRepositoryId,
78-
$contentStreamId,
79-
$dimensionSpacePoint,
80-
$visibilityConstraints
81-
),
78+
$this->contentRepositoryId,
79+
$workspaceName,
80+
$dimensionSpacePoint,
8281
NodeAggregateId::fromString($nodeRow['nodeaggregateid']),
8382
$this->dimensionSpacePointRepository->getOriginDimensionSpacePointByHash($nodeRow['origindimensionspacepointhash']),
8483
NodeAggregateClassification::from($nodeRow['classification']),
8584
NodeTypeName::fromString($nodeRow['nodetypename']),
86-
$nodeType,
8785
$this->createPropertyCollectionFromJsonString($nodeRow['properties']),
8886
isset($nodeRow['name']) ? NodeName::fromString($nodeRow['name']) : null,
8987
self::extractNodeTagsFromJson($nodeRow['subtreetags']),
@@ -93,16 +91,30 @@ public function mapNodeRowToNode(
9391
isset($nodeRow['lastmodified']) ? self::parseDateTimeString($nodeRow['lastmodified']) : null,
9492
isset($nodeRow['originallastmodified']) ? self::parseDateTimeString($nodeRow['originallastmodified']) : null,
9593
),
94+
$visibilityConstraints,
95+
$nodeType,
96+
$contentStreamId
9697
);
9798
}
9899

99100
/**
100101
* @param array<int, array<string, mixed>> $nodeRows
101102
*/
102-
public function mapNodeRowsToNodes(array $nodeRows, ContentStreamId $contentStreamId, DimensionSpacePoint $dimensionSpacePoint, VisibilityConstraints $visibilityConstraints): Nodes
103-
{
103+
public function mapNodeRowsToNodes(
104+
array $nodeRows,
105+
WorkspaceName $workspaceName,
106+
ContentStreamId $contentStreamId,
107+
DimensionSpacePoint $dimensionSpacePoint,
108+
VisibilityConstraints $visibilityConstraints
109+
): Nodes {
104110
return Nodes::fromArray(
105-
array_map(fn (array $nodeRow) => $this->mapNodeRowToNode($nodeRow, $contentStreamId, $dimensionSpacePoint, $visibilityConstraints), $nodeRows)
111+
array_map(fn (array $nodeRow) => $this->mapNodeRowToNode(
112+
$nodeRow,
113+
$workspaceName,
114+
$contentStreamId,
115+
$dimensionSpacePoint,
116+
$visibilityConstraints
117+
), $nodeRows)
106118
);
107119
}
108120

@@ -119,6 +131,7 @@ public function createPropertyCollectionFromJsonString(string $jsonString): Prop
119131
*/
120132
public function mapReferenceRowsToReferences(
121133
array $nodeRows,
134+
WorkspaceName $workspaceName,
122135
ContentStreamId $contentStreamId,
123136
DimensionSpacePoint $dimensionSpacePoint,
124137
VisibilityConstraints $visibilityConstraints
@@ -127,6 +140,7 @@ public function mapReferenceRowsToReferences(
127140
foreach ($nodeRows as $nodeRow) {
128141
$node = $this->mapNodeRowToNode(
129142
$nodeRow,
143+
$workspaceName,
130144
$contentStreamId,
131145
$dimensionSpacePoint,
132146
$visibilityConstraints
@@ -149,6 +163,7 @@ public function mapReferenceRowsToReferences(
149163
*/
150164
public function mapNodeRowsToNodeAggregate(
151165
array $nodeRows,
166+
WorkspaceName $workspaceName,
152167
ContentStreamId $contentStreamId,
153168
VisibilityConstraints $visibilityConstraints
154169
): ?NodeAggregate {
@@ -175,6 +190,7 @@ public function mapNodeRowsToNodeAggregate(
175190
// ... so we handle occupation exactly once ...
176191
$nodesByOccupiedDimensionSpacePoints[$occupiedDimensionSpacePoint->hash] = $this->mapNodeRowToNode(
177192
$nodeRow,
193+
$workspaceName,
178194
$contentStreamId,
179195
$occupiedDimensionSpacePoint->toDimensionSpacePoint(),
180196
$visibilityConstraints
@@ -230,6 +246,7 @@ public function mapNodeRowsToNodeAggregate(
230246
*/
231247
public function mapNodeRowsToNodeAggregates(
232248
iterable $nodeRows,
249+
WorkspaceName $workspaceName,
233250
ContentStreamId $contentStreamId,
234251
VisibilityConstraints $visibilityConstraints
235252
): iterable {
@@ -256,6 +273,7 @@ public function mapNodeRowsToNodeAggregates(
256273
$nodesByOccupiedDimensionSpacePointsByNodeAggregate
257274
[$rawNodeAggregateId][$occupiedDimensionSpacePoint->hash] = $this->mapNodeRowToNode(
258275
$nodeRow,
276+
$workspaceName,
259277
$contentStreamId,
260278
$occupiedDimensionSpacePoint->toDimensionSpacePoint(),
261279
$visibilityConstraints

Neos.ContentGraph.PostgreSQLAdapter/src/Domain/Repository/ContentHypergraph.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public function __construct(
6868
$this->nodeFactory = $nodeFactory;
6969
}
7070

71+
public function getContentRepositoryId(): ContentRepositoryId
72+
{
73+
return $this->contentRepositoryId;
74+
}
75+
76+
public function getWorkspaceName(): WorkspaceName
77+
{
78+
return $this->workspaceName;
79+
}
80+
7181
public function getSubgraph(
7282
DimensionSpacePoint $dimensionSpacePoint,
7383
VisibilityConstraints $visibilityConstraints
@@ -77,6 +87,7 @@ public function getSubgraph(
7787
$this->subhypergraphs[$index] = new ContentSubhypergraph(
7888
$this->contentRepositoryId,
7989
$this->contentStreamId,
90+
$this->workspaceName,
8091
$dimensionSpacePoint,
8192
$visibilityConstraints,
8293
$this->databaseClient,
@@ -307,11 +318,6 @@ private function getDatabaseConnection(): DatabaseConnection
307318
return $this->databaseClient->getConnection();
308319
}
309320

310-
public function getWorkspaceName(): WorkspaceName
311-
{
312-
return $this->workspaceName;
313-
}
314-
315321
public function getContentStreamId(): ContentStreamId
316322
{
317323
return $this->contentStreamId;

0 commit comments

Comments
 (0)