Skip to content

Commit

Permalink
TASK: Remove `NodeTypeManager::getTetheredNodesConfigurationForNodeTy…
Browse files Browse the repository at this point in the history
…pe()`

Previously known as `NodeType::getAutoCreatedChildNodes`
  • Loading branch information
mhsdesign committed May 14, 2024
1 parent 5df367d commit ab41496
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,13 @@ protected function requireRootNodeTypeToBeUnoccupied(

/**
* @param NodeType $nodeType
* @throws NodeTypeNotFoundException the configured child nodeType doesnt exist
* @throws NodeTypeNotFound the configured child nodeType doesnt exist
*/
protected function requireTetheredDescendantNodeTypesToExist(NodeType $nodeType): void
{
// this getter throws if any of the child nodeTypes doesnt exist!
$tetheredNodeTypes = $this->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeType->name);
foreach ($tetheredNodeTypes as $tetheredNodeType) {
$this->requireTetheredDescendantNodeTypesToExist($tetheredNodeType);
foreach ($nodeType->tetheredNodeTypeDefinitions as $tetheredNodeTypeDefinition) {
$nodeType = $this->requireNodeType($tetheredNodeTypeDefinition->nodeTypeName);
$this->requireTetheredDescendantNodeTypesToExist($nodeType);
}
}

Expand All @@ -189,7 +188,8 @@ protected function requireTetheredDescendantNodeTypesToExist(NodeType $nodeType)
*/
protected function requireTetheredDescendantNodeTypesToNotBeOfTypeRoot(NodeType $nodeType): void
{
foreach ($this->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeType->name) as $tetheredChildNodeType) {
foreach ($nodeType->tetheredNodeTypeDefinitions as $tetheredNodeTypeDefinition) {
$tetheredChildNodeType = $this->requireNodeType($tetheredNodeTypeDefinition->nodeTypeName);
if ($tetheredChildNodeType->isOfType(NodeTypeName::ROOT_NODE_TYPE_NAME)) {
throw new NodeTypeIsOfTypeRoot(
'Node type "' . $nodeType->name->value . '" for tethered descendant is of type root.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated;
use Neos\ContentRepository\Core\Infrastructure\Property\PropertyConverter;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\NodeType\TetheredNodeTypeDefinition;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;

/**
* @internal implementation details of command handlers
Expand Down Expand Up @@ -58,15 +56,19 @@ protected function createEventsForMissingTetheredNode(
ContentGraphInterface $contentGraph,
NodeAggregate $parentNodeAggregate,
OriginDimensionSpacePoint $originDimensionSpacePoint,
NodeName $tetheredNodeName,
?NodeAggregateId $tetheredNodeAggregateId,
NodeType $expectedTetheredNodeType
TetheredNodeTypeDefinition $tetheredNodeTypeDefinition,
?NodeAggregateId $tetheredNodeAggregateId
): Events {
$childNodeAggregate = $contentGraph->findChildNodeAggregateByName(
$parentNodeAggregate->nodeAggregateId,
$tetheredNodeName
$tetheredNodeTypeDefinition->name
);

$expectedTetheredNodeType = $this->nodeTypeManager->getNodeType($tetheredNodeTypeDefinition->nodeTypeName);
$defaultProperties = $expectedTetheredNodeType
? SerializedPropertyValues::defaultFromNodeType($expectedTetheredNodeType, $this->getPropertyConverter())
: SerializedPropertyValues::createEmpty();

if ($childNodeAggregate === null) {
// there is no tethered child node aggregate already; let's create it!
$nodeType = $this->nodeTypeManager->getNodeType($parentNodeAggregate->nodeTypeName);
Expand All @@ -91,14 +93,14 @@ protected function createEventsForMissingTetheredNode(
$events[] = new NodeAggregateWithNodeWasCreated(
$parentNodeAggregate->contentStreamId,
$tetheredNodeAggregateId,
$expectedTetheredNodeType->name,
$tetheredNodeTypeDefinition->nodeTypeName,
$rootGeneralizationOrigin,
InterdimensionalSiblings::fromDimensionSpacePointSetWithoutSucceedingSiblings(
$this->getInterDimensionalVariationGraph()->getSpecializationSet($rootGeneralization)
),
$parentNodeAggregate->nodeAggregateId,
$tetheredNodeName,
SerializedPropertyValues::defaultFromNodeType($expectedTetheredNodeType, $this->getPropertyConverter()),
$tetheredNodeTypeDefinition->name,
$defaultProperties,
NodeAggregateClassification::CLASSIFICATION_TETHERED,
);
$creationOriginDimensionSpacePoint = $rootGeneralizationOrigin;
Expand All @@ -110,14 +112,14 @@ protected function createEventsForMissingTetheredNode(
new NodeAggregateWithNodeWasCreated(
$parentNodeAggregate->contentStreamId,
$tetheredNodeAggregateId ?: NodeAggregateId::create(),
$expectedTetheredNodeType->name,
$tetheredNodeTypeDefinition->nodeTypeName,
$originDimensionSpacePoint,
InterdimensionalSiblings::fromDimensionSpacePointSetWithoutSucceedingSiblings(
$parentNodeAggregate->getCoverageByOccupant($originDimensionSpacePoint)
),
$parentNodeAggregate->nodeAggregateId,
$tetheredNodeName,
SerializedPropertyValues::defaultFromNodeType($expectedTetheredNodeType, $this->getPropertyConverter()),
$tetheredNodeTypeDefinition->name,
$defaultProperties,
NodeAggregateClassification::CLASSIFICATION_TETHERED,
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodePath;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeNotFound;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;

/**
Expand Down Expand Up @@ -128,12 +129,16 @@ private static function createNodeAggregateIdsForNodeType(
?string $pathPrefix = null
): array {
$nodeAggregateIds = [];
foreach ($nodeTypeManager->getTetheredNodesConfigurationForNodeType($nodeTypeName) as $nodeName => $childNodeType) {
$path = $pathPrefix ? $pathPrefix . '/' . $nodeName : $nodeName;
$nodeType = $nodeTypeManager->getNodeType($nodeTypeName);
if (!$nodeType) {
throw new NodeTypeNotFound(sprintf('Cannot build NodeAggregateIdsByNodePaths because NodeType %s does not exist.', $nodeTypeName->value), 1715711379);
}
foreach ($nodeType->tetheredNodeTypeDefinitions as $tetheredNodeTypeDefinition) {
$path = $pathPrefix ? $pathPrefix . '/' . $tetheredNodeTypeDefinition->name->value : $tetheredNodeTypeDefinition->name->value;
$nodeAggregateIds[$path] = NodeAggregateId::create();
$nodeAggregateIds = array_merge(
$nodeAggregateIds,
self::createNodeAggregateIdsForNodeType($childNodeType->name, $nodeTypeManager, $path)
self::createNodeAggregateIdsForNodeType($tetheredNodeTypeDefinition->nodeTypeName, $nodeTypeManager, $path)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private function handleCreateNodeAggregateWithNodeAndSerializedProperties(
array_push($events, ...iterator_to_array($this->handleTetheredChildNodes(
$command,
$contentGraph,
$command->nodeTypeName,
$nodeType,
$coveredDimensionSpacePoints,
$command->nodeAggregateId,
$descendantNodeAggregateIds,
Expand Down Expand Up @@ -257,38 +257,41 @@ private function createRegularWithNode(
private function handleTetheredChildNodes(
CreateNodeAggregateWithNodeAndSerializedProperties $command,
ContentGraphInterface $contentGraph,
NodeTypeName $nodeTypeName,
NodeType $nodeType,
DimensionSpacePointSet $coveredDimensionSpacePoints,
NodeAggregateId $parentNodeAggregateId,
NodeAggregateIdsByNodePaths $nodeAggregateIds,
?NodePath $nodePath
): Events {
$events = [];
foreach ($this->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeTypeName) as $nodeNameString => $childNodeType) {
$nodeName = NodeName::fromString($nodeNameString);
foreach ($nodeType->tetheredNodeTypeDefinitions as $tetheredNodeTypeDefinition) {
$childNodeType = $this->requireNodeType($tetheredNodeTypeDefinition->nodeTypeName);
$childNodePath = $nodePath
? $nodePath->appendPathSegment($nodeName)
: NodePath::fromString($nodeName->value);
? $nodePath->appendPathSegment($tetheredNodeTypeDefinition->name)
: NodePath::fromString($tetheredNodeTypeDefinition->name->value);
$childNodeAggregateId = $nodeAggregateIds->getNodeAggregateId($childNodePath)
?? NodeAggregateId::create();
$initialPropertyValues = SerializedPropertyValues::defaultFromNodeType($childNodeType, $this->getPropertyConverter());
$initialPropertyValues = SerializedPropertyValues::defaultFromNodeType(
$childNodeType,
$this->getPropertyConverter()
);

$events[] = new NodeAggregateWithNodeWasCreated(
$contentGraph->getContentStreamId(),
$childNodeAggregateId,
$childNodeType->name,
$tetheredNodeTypeDefinition->nodeTypeName,
$command->originDimensionSpacePoint,
InterdimensionalSiblings::fromDimensionSpacePointSetWithoutSucceedingSiblings($coveredDimensionSpacePoints),
$parentNodeAggregateId,
$nodeName,
$tetheredNodeTypeDefinition->name,
$initialPropertyValues,
NodeAggregateClassification::CLASSIFICATION_TETHERED,
);

array_push($events, ...iterator_to_array($this->handleTetheredChildNodes(
$command,
$contentGraph,
$childNodeType->name,
$childNodeType,
$coveredDimensionSpacePoints,
$childNodeAggregateId,
$nodeAggregateIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
use Neos\ContentRepository\Core\Feature\NodeTypeChange\Event\NodeAggregateTypeWasChanged;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\TetheredNodeTypeDefinition;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodePath;
Expand Down Expand Up @@ -90,9 +90,8 @@ abstract protected function createEventsForMissingTetheredNode(
ContentGraphInterface $contentGraph,
NodeAggregate $parentNodeAggregate,
OriginDimensionSpacePoint $originDimensionSpacePoint,
NodeName $tetheredNodeName,
NodeAggregateId $tetheredNodeAggregateId,
NodeType $expectedTetheredNodeType
TetheredNodeTypeDefinition $tetheredNodeTypeDefinition,
NodeAggregateId $tetheredNodeAggregateId
): Events;

/**
Expand Down Expand Up @@ -177,36 +176,32 @@ private function handleChangeNodeAggregateType(
array_push($events, ...iterator_to_array($this->deleteObsoleteTetheredNodesWhenChangingNodeType(
$contentGraph,
$nodeAggregate,
$command->newNodeTypeName
$newNodeType
)));
}

// new tethered child nodes
$expectedTetheredNodes = $this->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($command->newNodeTypeName);
foreach ($nodeAggregate->getNodes() as $node) {
assert($node instanceof Node);
foreach ($expectedTetheredNodes as $serializedTetheredNodeName => $expectedTetheredNodeType) {
$tetheredNodeName = NodeName::fromString($serializedTetheredNodeName);

foreach ($newNodeType->tetheredNodeTypeDefinitions as $tetheredNodeTypeDefinition) {
$tetheredNode = $contentGraph->getSubgraph(
$node->originDimensionSpacePoint->toDimensionSpacePoint(),
VisibilityConstraints::withoutRestrictions()
)->findNodeByPath(
$tetheredNodeName,
$tetheredNodeTypeDefinition->name,
$node->nodeAggregateId,
);

if ($tetheredNode === null) {
$tetheredNodeAggregateId = $command->tetheredDescendantNodeAggregateIds
->getNodeAggregateId(NodePath::fromString($tetheredNodeName->value))
->getNodeAggregateId(NodePath::fromNodeNames($tetheredNodeTypeDefinition->name))
?: NodeAggregateId::create();
array_push($events, ...iterator_to_array($this->createEventsForMissingTetheredNode(
$contentGraph,
$nodeAggregate,
$node->originDimensionSpacePoint,
$tetheredNodeName,
$tetheredNodeAggregateId,
$expectedTetheredNodeType
$tetheredNodeTypeDefinition,
$tetheredNodeAggregateId
)));
}
}
Expand Down Expand Up @@ -348,17 +343,15 @@ private function deleteDisallowedNodesWhenChangingNodeType(
private function deleteObsoleteTetheredNodesWhenChangingNodeType(
ContentGraphInterface $contentGraph,
NodeAggregate $nodeAggregate,
NodeTypeName $newNodeTypeName
NodeType $newNodeType
): Events {
$expectedTetheredNodes = $this->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($newNodeTypeName);

$events = [];
// find disallowed tethered nodes
$tetheredNodeAggregates = $contentGraph->findTetheredChildNodeAggregates($nodeAggregate->nodeAggregateId);

foreach ($tetheredNodeAggregates as $tetheredNodeAggregate) {
/* @var $tetheredNodeAggregate NodeAggregate */
if ($tetheredNodeAggregate->nodeName !== null && !isset($expectedTetheredNodes[$tetheredNodeAggregate->nodeName->value])) {
if ($tetheredNodeAggregate->nodeName !== null && !$newNodeType->tetheredNodeTypeDefinitions->contain($tetheredNodeAggregate->nodeName)) {
// this aggregate (or parts thereof) are DISALLOWED according to constraints.
// We now need to find out which edges we need to remove,
$dimensionSpacePointsToBeRemoved = $this->findDimensionSpacePointsConnectingParentAndChildAggregate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private function handleCreateRootNodeAggregateWithNode(
foreach ($this->getInterDimensionalVariationGraph()->getRootGeneralizations() as $rootGeneralization) {
array_push($events, ...iterator_to_array($this->handleTetheredRootChildNodes(
$contentGraph->getContentStreamId(),
$command->nodeTypeName,
$nodeType,
OriginDimensionSpacePoint::fromDimensionSpacePoint($rootGeneralization),
$this->getInterDimensionalVariationGraph()->getSpecializationSet($rootGeneralization, true),
$command->nodeAggregateId,
Expand Down Expand Up @@ -184,37 +184,37 @@ private function handleUpdateRootNodeAggregateDimensions(
*/
private function handleTetheredRootChildNodes(
ContentStreamId $contentStreamId,
NodeTypeName $nodeTypeName,
NodeType $nodeType,
OriginDimensionSpacePoint $originDimensionSpacePoint,
DimensionSpacePointSet $coveredDimensionSpacePoints,
NodeAggregateId $parentNodeAggregateId,
NodeAggregateIdsByNodePaths $nodeAggregateIdsByNodePath,
?NodePath $nodePath
): Events {
$events = [];
foreach ($this->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeTypeName) as $nodeNameString => $childNodeType) {
$nodeName = NodeName::fromString($nodeNameString);
foreach ($nodeType->tetheredNodeTypeDefinitions as $tetheredNodeTypeDefinition) {
$childNodeType = $this->requireNodeType($tetheredNodeTypeDefinition->nodeTypeName);
$childNodePath = $nodePath
? $nodePath->appendPathSegment($nodeName)
: NodePath::fromString($nodeName->value);
? $nodePath->appendPathSegment($tetheredNodeTypeDefinition->name)
: NodePath::fromNodeNames($tetheredNodeTypeDefinition->name);
$childNodeAggregateId = $nodeAggregateIdsByNodePath->getNodeAggregateId($childNodePath)
?? NodeAggregateId::create();
$initialPropertyValues = SerializedPropertyValues::defaultFromNodeType($childNodeType, $this->getPropertyConverter());

$events[] = $this->createTetheredWithNodeForRoot(
$contentStreamId,
$childNodeAggregateId,
$childNodeType->name,
$tetheredNodeTypeDefinition->nodeTypeName,
$originDimensionSpacePoint,
$coveredDimensionSpacePoints,
$parentNodeAggregateId,
$nodeName,
$tetheredNodeTypeDefinition->name,
$initialPropertyValues
);

array_push($events, ...iterator_to_array($this->handleTetheredRootChildNodes(
$contentStreamId,
$childNodeType->name,
$childNodeType,
$originDimensionSpacePoint,
$coveredDimensionSpacePoints,
$childNodeAggregateId,
Expand Down
Loading

0 comments on commit ab41496

Please sign in to comment.