-
-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUGFIX: make tethered node ids deterministic #4313
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,10 +199,9 @@ private function handleCreateNodeAggregateWithNodeAndSerializedProperties( | |
$contentRepository | ||
); | ||
} | ||
$descendantNodeAggregateIds = self::populateNodeAggregateIds( | ||
$nodeType, | ||
$command->tetheredDescendantNodeAggregateIds | ||
); | ||
|
||
$descendantNodeAggregateIds = $nodeType->tetheredNodeAggregateIds($command->nodeAggregateId) | ||
->merge($command->tetheredDescendantNodeAggregateIds); | ||
// Write the auto-created descendant node aggregate ids back to the command; | ||
// so that when rebasing the command, it stays fully deterministic. | ||
$command = $command->withTetheredDescendantNodeAggregateIds($descendantNodeAggregateIds); | ||
Comment on lines
205
to
207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we can remove this step now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point.. yes, I think so |
||
|
@@ -338,29 +337,4 @@ private function createTetheredWithNode( | |
$precedingNodeAggregateId | ||
); | ||
} | ||
|
||
protected static function populateNodeAggregateIds( | ||
NodeType $nodeType, | ||
?NodeAggregateIdsByNodePaths $nodeAggregateIds, | ||
NodePath $childPath = null | ||
): NodeAggregateIdsByNodePaths { | ||
if ($nodeAggregateIds === null) { | ||
$nodeAggregateIds = NodeAggregateIdsByNodePaths::createEmpty(); | ||
} | ||
// TODO: handle Multiple levels of autocreated child nodes | ||
foreach ($nodeType->getAutoCreatedChildNodes() as $rawChildName => $childNodeType) { | ||
$childName = NodeName::fromString($rawChildName); | ||
$childPath = $childPath | ||
? $childPath->appendPathSegment($childName) | ||
: NodePath::fromString($childName->value); | ||
if (!$nodeAggregateIds->getNodeAggregateId($childPath)) { | ||
$nodeAggregateIds = $nodeAggregateIds->add( | ||
$childPath, | ||
NodeAggregateId::create() | ||
); | ||
} | ||
} | ||
|
||
return $nodeAggregateIds; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,10 @@ | |
*/ | ||
|
||
|
||
use Neos\ContentRepository\Core\Feature\NodeCreation\Dto\NodeAggregateIdsByNodePaths; | ||
use Neos\ContentRepository\Core\Projection\ContentGraph\NodePath; | ||
use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeNotFoundException; | ||
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; | ||
use Neos\ContentRepository\Core\SharedModel\Node\NodeName; | ||
use Neos\Utility\ObjectAccess; | ||
use Neos\Utility\Arrays; | ||
|
@@ -490,11 +493,31 @@ public function hasAutoCreatedChildNode(NodeName $nodeName): bool | |
*/ | ||
public function getTypeOfAutoCreatedChildNode(NodeName $nodeName): ?NodeType | ||
{ | ||
$this->initialize(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haha actually not the only missing 😂 will revert this and must be fixed correctly in another pr |
||
return isset($this->fullConfiguration['childNodes'][$nodeName->value]['type']) | ||
? $this->nodeTypeManager->getNodeType($this->fullConfiguration['childNodes'][$nodeName->value]['type']) | ||
: null; | ||
} | ||
|
||
/** | ||
* Calculates the deterministic nodeAggregateIds for the auto-created childNodes. | ||
*/ | ||
public function tetheredNodeAggregateIds(NodeAggregateId $parentNodeAggregateId): NodeAggregateIdsByNodePaths | ||
{ | ||
$this->initialize(); | ||
$nodeAggregateIdsByNodePaths = NodeAggregateIdsByNodePaths::createEmpty(); | ||
if (!isset($this->fullConfiguration['childNodes'])) { | ||
return $nodeAggregateIdsByNodePaths; | ||
} | ||
// TODO: handle Multiple levels of autocreated child nodes | ||
foreach (array_keys($this->fullConfiguration['childNodes']) as $tetheredNodeName) { | ||
$nodeAggregateIdsByNodePaths = $nodeAggregateIdsByNodePaths->add( | ||
NodePath::fromString($tetheredNodeName), | ||
NodeAggregateId::fromParentNodeAggregateIdAndNodeName($parentNodeAggregateId, NodeName::fromString($tetheredNodeName)) | ||
); | ||
} | ||
return $nodeAggregateIdsByNodePaths; | ||
} | ||
|
||
/** | ||
* Checks if the given NodeType is acceptable as sub-node with the configured constraints, | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -50,6 +50,23 @@ public static function fromString(string $value): self | |||||||||||
return new self($value); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Calculates a deterministic nodeAggregateId. | ||||||||||||
* | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used for new nodes, but previously created tethered node ids were random comment |
||||||||||||
* Used for determining the nodeAggregateIds of tethered nodes. | ||||||||||||
* | ||||||||||||
* e.g. in case you want to get the main content collection node aggregate id: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
* NodeAggregateId::fromParentNodeAggregateIdAndNodeName($parentNodeAggregateId, NodeName::fromString('main')) | ||||||||||||
* | ||||||||||||
*/ | ||||||||||||
public static function fromParentNodeAggregateIdAndNodeName(NodeAggregateId $parentNodeAggregateId, NodeName $tetheredNodeName): self | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to NodeName There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this should be moved because it contains a concept that does not belong to the Node Aggregate ID itself.. It's not too bad though IMO and I'm not sure if |
||||||||||||
{ | ||||||||||||
$hex = md5($parentNodeAggregateId->value . '-' . $tetheredNodeName->value); | ||||||||||||
return new self( | ||||||||||||
substr($hex, 0, 8) . '-' . substr($hex, 8, 4) . '-' . substr($hex, 12, 4) . '-' . substr($hex, 16, 4) . '-' . substr($hex, 20, 12) | ||||||||||||
); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to discuss: does this have to be a UUID pattern? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to follow up on this: I would suggest to just do |
||||||||||||
} | ||||||||||||
|
||||||||||||
public function equals(self $other): bool | ||||||||||||
{ | ||||||||||||
return $this->value === $other->value; | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice addition! Just a mini nitpick