Skip to content

Commit

Permalink
Merge pull request #4961 from neos/4742-interdimensionalRelatives
Browse files Browse the repository at this point in the history
BUGFIX: #4742 - Interdimensional relatives
  • Loading branch information
mhsdesign committed Apr 5, 2024
2 parents 04fae33 + 0a57b90 commit 7fec5e6
Show file tree
Hide file tree
Showing 35 changed files with 3,386 additions and 1,856 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Feature\Common\InterdimensionalSiblings;
use Neos\ContentRepository\Core\Feature\ContentStreamForking\Event\ContentStreamWasForked;
use Neos\ContentRepository\Core\Feature\ContentStreamRemoval\Event\ContentStreamWasRemoved;
use Neos\ContentRepository\Core\Feature\DimensionSpaceAdjustment\Event\DimensionShineThroughWasAdded;
Expand Down Expand Up @@ -343,10 +344,9 @@ private function whenNodeAggregateWithNodeWasCreated(NodeAggregateWithNodeWasCre
$event->nodeTypeName,
$event->parentNodeAggregateId,
$event->originDimensionSpacePoint,
$event->coveredDimensionSpacePoints,
$event->succeedingSiblingsForCoverage,
$event->initialPropertyValues,
$event->nodeAggregateClassification,
$event->succeedingNodeAggregateId,
$event->nodeName,
$eventEnvelope,
);
Expand Down Expand Up @@ -393,10 +393,9 @@ private function createNodeWithHierarchy(
NodeTypeName $nodeTypeName,
NodeAggregateId $parentNodeAggregateId,
OriginDimensionSpacePoint $originDimensionSpacePoint,
DimensionSpacePointSet $visibleInDimensionSpacePoints,
InterdimensionalSiblings $coverageSucceedingSiblings,
SerializedPropertyValues $propertyDefaultValuesAndTypes,
NodeAggregateClassification $nodeAggregateClassification,
?NodeAggregateId $succeedingSiblingNodeAggregateId,
?NodeName $nodeName,
EventEnvelope $eventEnvelope,
): void {
Expand All @@ -419,7 +418,7 @@ private function createNodeWithHierarchy(
);

// reconnect parent relations
$missingParentRelations = $visibleInDimensionSpacePoints->points;
$missingParentRelations = $coverageSucceedingSiblings->toDimensionSpacePointSet()->points;

if (!empty($missingParentRelations)) {
// add yet missing parent relations
Expand All @@ -431,6 +430,7 @@ private function createNodeWithHierarchy(
$dimensionSpacePoint
);

$succeedingSiblingNodeAggregateId = $coverageSucceedingSiblings->getSucceedingSiblingIdForDimensionSpacePoint($dimensionSpacePoint);
$succeedingSibling = $succeedingSiblingNodeAggregateId
? $this->projectionContentGraph->findNodeInAggregate(
$contentStreamId,
Expand Down Expand Up @@ -767,27 +767,16 @@ function (NodeRecord $node) use ($eventEnvelope) {
}

/**
* @param HierarchyRelation $sourceHierarchyRelation
* @param ContentStreamId $contentStreamId
* @param DimensionSpacePoint $dimensionSpacePoint
* @param NodeRelationAnchorPoint|null $newParent
* @param NodeRelationAnchorPoint|null $newChild
* @return HierarchyRelation
* @throws \Doctrine\DBAL\DBALException
*/
protected function copyHierarchyRelationToDimensionSpacePoint(
HierarchyRelation $sourceHierarchyRelation,
ContentStreamId $contentStreamId,
DimensionSpacePoint $dimensionSpacePoint,
?NodeRelationAnchorPoint $newParent = null,
?NodeRelationAnchorPoint $newChild = null
NodeRelationAnchorPoint $newParent,
NodeRelationAnchorPoint $newChild,
?NodeRelationAnchorPoint $newSucceedingSibling = null,
): HierarchyRelation {
if ($newParent === null) {
$newParent = $sourceHierarchyRelation->parentNodeAnchor;
}
if ($newChild === null) {
$newChild = $sourceHierarchyRelation->childNodeAnchor;
}
$parentSubtreeTags = $this->subtreeTagsForHierarchyRelation($contentStreamId, $newParent, $dimensionSpacePoint);
$inheritedSubtreeTags = NodeTags::create($sourceHierarchyRelation->subtreeTags->withoutInherited()->all(), $parentSubtreeTags->withoutInherited()->all());
$copy = new HierarchyRelation(
Expand All @@ -800,7 +789,7 @@ protected function copyHierarchyRelationToDimensionSpacePoint(
$this->getRelationPosition(
$newParent,
$newChild,
null, // todo: find proper sibling
$newSucceedingSibling,
$contentStreamId,
$dimensionSpacePoint
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVaria
$eventEnvelope
);

$uncoveredDimensionSpacePoints = $event->specializationCoverage->points;
$uncoveredDimensionSpacePoints = $event->specializationSiblings->toDimensionSpacePointSet()->points;
foreach (
$this->getProjectionContentGraph()->findIngoingHierarchyRelationsForNodeAggregate(
$event->contentStreamId,
$sourceNode->nodeAggregateId,
$event->specializationCoverage
$event->specializationSiblings->toDimensionSpacePointSet()
) as $hierarchyRelation
) {
$hierarchyRelation->assignNewChildNode(
Expand Down Expand Up @@ -93,6 +93,17 @@ private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVaria
);
}
$parentSubtreeTags = $this->subtreeTagsForHierarchyRelation($event->contentStreamId, $parentNode->relationAnchorPoint, $uncoveredDimensionSpacePoint);

$specializationSucceedingSiblingNodeAggregateId = $event->specializationSiblings
->getSucceedingSiblingIdForDimensionSpacePoint($uncoveredDimensionSpacePoint);
$specializationSucceedingSiblingNode = $specializationSucceedingSiblingNodeAggregateId
? $this->getProjectionContentGraph()->findNodeInAggregate(
$event->contentStreamId,
$specializationSucceedingSiblingNodeAggregateId,
$uncoveredDimensionSpacePoint
)
: null;

$hierarchyRelation = new HierarchyRelation(
$parentNode->relationAnchorPoint,
$specializedNode->relationAnchorPoint,
Expand All @@ -103,7 +114,7 @@ private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVaria
$this->projectionContentGraph->determineHierarchyRelationPosition(
$parentNode->relationAnchorPoint,
$specializedNode->relationAnchorPoint,
null,
$specializationSucceedingSiblingNode?->relationAnchorPoint,
$event->contentStreamId,
$uncoveredDimensionSpacePoint
),
Expand All @@ -117,7 +128,7 @@ private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVaria
$this->getProjectionContentGraph()->findOutgoingHierarchyRelationsForNodeAggregate(
$event->contentStreamId,
$sourceNode->nodeAggregateId,
$event->specializationCoverage
$event->specializationSiblings->toDimensionSpacePointSet()
) as $hierarchyRelation
) {
$hierarchyRelation->assignNewParentNode(
Expand Down Expand Up @@ -167,12 +178,12 @@ public function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVarian
$eventEnvelope
);

$unassignedIngoingDimensionSpacePoints = $event->generalizationCoverage;
$unassignedIngoingDimensionSpacePoints = $event->variantSucceedingSiblings->toDimensionSpacePointSet();
foreach (
$this->getProjectionContentGraph()->findIngoingHierarchyRelationsForNodeAggregate(
$event->contentStreamId,
$event->nodeAggregateId,
$event->generalizationCoverage
$event->variantSucceedingSiblings->toDimensionSpacePointSet()
) as $existingIngoingHierarchyRelation
) {
$existingIngoingHierarchyRelation->assignNewChildNode(
Expand All @@ -191,7 +202,7 @@ public function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVarian
$this->getProjectionContentGraph()->findOutgoingHierarchyRelationsForNodeAggregate(
$event->contentStreamId,
$event->nodeAggregateId,
$event->generalizationCoverage
$event->variantSucceedingSiblings->toDimensionSpacePointSet()
) as $existingOutgoingHierarchyRelation
) {
$existingOutgoingHierarchyRelation->assignNewParentNode(
Expand Down Expand Up @@ -229,12 +240,23 @@ public function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVarian
);
}

$generalizationSucceedingSiblingNodeAggregateId = $event->variantSucceedingSiblings
->getSucceedingSiblingIdForDimensionSpacePoint($unassignedDimensionSpacePoint);
$generalizationSucceedingSiblingNode = $generalizationSucceedingSiblingNodeAggregateId
? $this->getProjectionContentGraph()->findNodeInAggregate(
$event->contentStreamId,
$generalizationSucceedingSiblingNodeAggregateId,
$unassignedDimensionSpacePoint
)
: null;

$this->copyHierarchyRelationToDimensionSpacePoint(
$ingoingSourceHierarchyRelation,
$event->contentStreamId,
$unassignedDimensionSpacePoint,
$generalizationParentNode->relationAnchorPoint,
$generalizedNode->relationAnchorPoint
$generalizedNode->relationAnchorPoint,
$generalizationSucceedingSiblingNode?->relationAnchorPoint
);
}
}
Expand Down Expand Up @@ -262,26 +284,18 @@ public function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event,
if (is_null($sourceNode)) {
throw EventCouldNotBeAppliedToContentGraph::becauseTheSourceNodeIsMissing(get_class($event));
}
$sourceParentNode = $this->getProjectionContentGraph()->findParentNode(
$event->contentStreamId,
$event->nodeAggregateId,
$event->sourceOrigin
);
if (is_null($sourceParentNode)) {
throw EventCouldNotBeAppliedToContentGraph::becauseTheSourceParentNodeIsMissing(get_class($event));
}
$peerNode = $this->copyNodeToDimensionSpacePoint(
$sourceNode,
$event->peerOrigin,
$eventEnvelope
);

$unassignedIngoingDimensionSpacePoints = $event->peerCoverage;
$unassignedIngoingDimensionSpacePoints = $event->peerSucceedingSiblings->toDimensionSpacePointSet();
foreach (
$this->getProjectionContentGraph()->findIngoingHierarchyRelationsForNodeAggregate(
$event->contentStreamId,
$event->nodeAggregateId,
$event->peerCoverage
$event->peerSucceedingSiblings->toDimensionSpacePointSet()
) as $existingIngoingHierarchyRelation
) {
$existingIngoingHierarchyRelation->assignNewChildNode(
Expand All @@ -300,7 +314,7 @@ public function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event,
$this->getProjectionContentGraph()->findOutgoingHierarchyRelationsForNodeAggregate(
$event->contentStreamId,
$event->nodeAggregateId,
$event->peerCoverage
$event->peerSucceedingSiblings->toDimensionSpacePointSet()
) as $existingOutgoingHierarchyRelation
) {
$existingOutgoingHierarchyRelation->assignNewParentNode(
Expand All @@ -311,6 +325,14 @@ public function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event,
);
}

$sourceParentNode = $this->getProjectionContentGraph()->findParentNode(
$event->contentStreamId,
$event->nodeAggregateId,
$event->sourceOrigin
);
if (is_null($sourceParentNode)) {
throw EventCouldNotBeAppliedToContentGraph::becauseTheSourceParentNodeIsMissing(get_class($event));
}
foreach ($unassignedIngoingDimensionSpacePoints as $coveredDimensionSpacePoint) {
// The parent node aggregate might be varied as well,
// so we need to find a parent node for each covered dimension space point
Expand All @@ -322,13 +344,22 @@ public function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event,
if (is_null($peerParentNode)) {
throw EventCouldNotBeAppliedToContentGraph::becauseTheTargetParentNodeIsMissing(get_class($event));
}
$peerSucceedingSiblingNodeAggregateId = $event->peerSucceedingSiblings
->getSucceedingSiblingIdForDimensionSpacePoint($coveredDimensionSpacePoint);
$peerSucceedingSiblingNode = $peerSucceedingSiblingNodeAggregateId
? $this->getProjectionContentGraph()->findNodeInAggregate(
$event->contentStreamId,
$peerSucceedingSiblingNodeAggregateId,
$coveredDimensionSpacePoint
)
: null;

$this->connectHierarchy(
$event->contentStreamId,
$peerParentNode->relationAnchorPoint,
$peerNode->relationAnchorPoint,
new DimensionSpacePointSet([$coveredDimensionSpacePoint]),
null, // @todo fetch appropriate sibling
$peerSucceedingSiblingNode?->relationAnchorPoint,
$sourceNode->nodeName
);
}
Expand All @@ -351,8 +382,9 @@ abstract protected function copyHierarchyRelationToDimensionSpacePoint(
HierarchyRelation $sourceHierarchyRelation,
ContentStreamId $contentStreamId,
DimensionSpacePoint $dimensionSpacePoint,
?NodeRelationAnchorPoint $newParent = null,
?NodeRelationAnchorPoint $newChild = null
NodeRelationAnchorPoint $newParent,
NodeRelationAnchorPoint $newChild,
?NodeRelationAnchorPoint $newSucceedingSibling = null,
): HierarchyRelation;

abstract protected function connectHierarchy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,22 @@ public function whenNodeAggregateWithNodeWasCreated(NodeAggregateWithNodeWasCrea

$this->transactional(function () use ($node, $event) {
$node->addToDatabase($this->getDatabaseConnection(), $this->tableNamePrefix);
foreach ($event->coveredDimensionSpacePoints as $dimensionSpacePoint) {
foreach ($event->succeedingSiblingsForCoverage->toDimensionSpacePointSet() as $dimensionSpacePoint) {
$hierarchyRelation = $this->getProjectionHypergraph()->findChildHierarchyHyperrelationRecord(
$event->contentStreamId,
$dimensionSpacePoint,
$event->parentNodeAggregateId
);
if ($hierarchyRelation) {
$succeedingSiblingNodeAnchor = null;
if ($event->succeedingNodeAggregateId) {
$succeedingSiblingNodeAggregateId = $event->succeedingSiblingsForCoverage->getSucceedingSiblingIdForDimensionSpacePoint($dimensionSpacePoint);
if ($succeedingSiblingNodeAggregateId) {
$succeedingSiblingNode = $this->getProjectionHypergraph()->findNodeRecordByCoverage(
$event->contentStreamId,
$dimensionSpacePoint,
$event->succeedingNodeAggregateId
$succeedingSiblingNodeAggregateId
);
if ($succeedingSiblingNode) {
$succeedingSiblingNodeAnchor = $succeedingSiblingNode->relationAnchorPoint;
}
$succeedingSiblingNodeAnchor = $succeedingSiblingNode?->relationAnchorPoint;
}
$hierarchyRelation->addChildNodeAnchor(
$node->relationAnchorPoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVaria
$event->contentStreamId,
$oldCoveringNode->relationAnchorPoint,
$specializedNode->relationAnchorPoint,
$event->specializationCoverage
$event->specializationSiblings->toDimensionSpacePointSet()
);
$this->assignNewParentNodeToAffectedHierarchyRelations(
$event->contentStreamId,
$oldCoveringNode->relationAnchorPoint,
$specializedNode->relationAnchorPoint,
$event->specializationCoverage
$event->specializationSiblings->toDimensionSpacePointSet()
);
} else {
// the dimension space point is not yet covered by the node aggregate,
Expand All @@ -92,7 +92,7 @@ private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVaria
(get_class($event))
);
}
foreach ($event->specializationCoverage as $specializedDimensionSpacePoint) {
foreach ($event->specializationSiblings->toDimensionSpacePointSet() as $specializedDimensionSpacePoint) {
$parentNode = $this->projectionHypergraph->findNodeRecordByCoverage(
$event->contentStreamId,
$specializedDimensionSpacePoint,
Expand Down Expand Up @@ -149,15 +149,15 @@ private function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVaria
$this->replaceNodeRelationAnchorPoint(
$event->contentStreamId,
$event->nodeAggregateId,
$event->generalizationCoverage,
$event->variantSucceedingSiblings->toDimensionSpacePointSet(),
$generalizedNode->relationAnchorPoint
);
$this->addMissingHierarchyRelations(
$event->contentStreamId,
$event->nodeAggregateId,
$event->sourceOrigin,
$generalizedNode->relationAnchorPoint,
$event->generalizationCoverage,
$event->variantSucceedingSiblings->toDimensionSpacePointSet(),
get_class($event)
);
$this->copyReferenceRelations(
Expand Down Expand Up @@ -186,15 +186,15 @@ private function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event)
$this->replaceNodeRelationAnchorPoint(
$event->contentStreamId,
$event->nodeAggregateId,
$event->peerCoverage,
$event->peerSucceedingSiblings->toDimensionSpacePointSet(),
$peerNode->relationAnchorPoint
);
$this->addMissingHierarchyRelations(
$event->contentStreamId,
$event->nodeAggregateId,
$event->sourceOrigin,
$peerNode->relationAnchorPoint,
$event->peerCoverage,
$event->peerSucceedingSiblings->toDimensionSpacePointSet(),
get_class($event)
);
$this->copyReferenceRelations(
Expand Down

0 comments on commit 7fec5e6

Please sign in to comment.