Skip to content

Commit

Permalink
Merge pull request #5082 from mhsdesign/task/deprecateSettingNodeName…
Browse files Browse the repository at this point in the history
…sViaCrCommands

!!! TASK: Deprecate setting NodeNames via cr commands
  • Loading branch information
mhsdesign authored Jul 7, 2024
2 parents 9dc5f48 + a63ad9e commit 607134b
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ private function __construct(
* @param OriginDimensionSpacePoint $originDimensionSpacePoint Origin of the new node in the dimension space. Will also be used to calculate a set of dimension points where the new node will cover from the configured specializations.
* @param NodeAggregateId $parentNodeAggregateId The id of the node aggregate underneath which the new node is added
* @param NodeAggregateId|null $succeedingSiblingNodeAggregateId Node aggregate id of the node's succeeding sibling (optional). If not given, the node will be added as the parent's first child
* @param NodeName|null $nodeName The node's optional name. Set if there is a meaningful relation to its parent that should be named.
* @param PropertyValuesToWrite|null $initialPropertyValues The node's initial property values. Will be merged over the node type's default property values
*/
public static function create(WorkspaceName $workspaceName, NodeAggregateId $nodeAggregateId, NodeTypeName $nodeTypeName, OriginDimensionSpacePoint $originDimensionSpacePoint, NodeAggregateId $parentNodeAggregateId, ?NodeAggregateId $succeedingSiblingNodeAggregateId = null, ?NodeName $nodeName = null, ?PropertyValuesToWrite $initialPropertyValues = null): self
public static function create(WorkspaceName $workspaceName, NodeAggregateId $nodeAggregateId, NodeTypeName $nodeTypeName, OriginDimensionSpacePoint $originDimensionSpacePoint, NodeAggregateId $parentNodeAggregateId, ?NodeAggregateId $succeedingSiblingNodeAggregateId = null, ?PropertyValuesToWrite $initialPropertyValues = null): self
{
return new self($workspaceName, $nodeAggregateId, $nodeTypeName, $originDimensionSpacePoint, $parentNodeAggregateId, $initialPropertyValues ?: PropertyValuesToWrite::createEmpty(), $succeedingSiblingNodeAggregateId, $nodeName, NodeAggregateIdsByNodePaths::createEmpty());
return new self($workspaceName, $nodeAggregateId, $nodeTypeName, $originDimensionSpacePoint, $parentNodeAggregateId, $initialPropertyValues ?: PropertyValuesToWrite::createEmpty(), $succeedingSiblingNodeAggregateId, null, NodeAggregateIdsByNodePaths::createEmpty());
}

public function withInitialPropertyValues(PropertyValuesToWrite $newInitialPropertyValues): self
Expand Down Expand Up @@ -130,4 +129,25 @@ public function withTetheredDescendantNodeAggregateIds(NodeAggregateIdsByNodePat
$tetheredDescendantNodeAggregateIds,
);
}

/**
* The node's optional name.
* Set if there is a meaningful relation to its parent that should be named.
*
* @deprecated the concept regarding node-names for non-tethered nodes is outdated.
*/
public function withNodeName(NodeName $nodeName): self
{
return new self(
$this->workspaceName,
$this->nodeAggregateId,
$this->nodeTypeName,
$this->originDimensionSpacePoint,
$this->parentNodeAggregateId,
$this->initialPropertyValues,
$this->succeedingSiblingNodeAggregateId,
$nodeName,
$this->tetheredDescendantNodeAggregateIds,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
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;

/**
Expand Down Expand Up @@ -70,12 +69,11 @@ private function __construct(
* @param OriginDimensionSpacePoint $originDimensionSpacePoint Origin of the new node in the dimension space. Will also be used to calculate a set of dimension points where the new node will cover from the configured specializations.
* @param NodeAggregateId $parentNodeAggregateId The id of the node aggregate underneath which the new node is added
* @param NodeAggregateId|null $succeedingSiblingNodeAggregateId Node aggregate id of the node's succeeding sibling (optional). If not given, the node will be added as the parent's first child
* @param NodeName|null $nodeName The node's optional name. Set if there is a meaningful relation to its parent that should be named.
* @param SerializedPropertyValues|null $initialPropertyValues The node's initial property values (serialized). Will be merged over the node type's default property values
*/
public static function create(WorkspaceName $workspaceName, NodeAggregateId $nodeAggregateId, NodeTypeName $nodeTypeName, OriginDimensionSpacePoint $originDimensionSpacePoint, NodeAggregateId $parentNodeAggregateId, NodeAggregateId $succeedingSiblingNodeAggregateId = null, NodeName $nodeName = null, SerializedPropertyValues $initialPropertyValues = null): self
public static function create(WorkspaceName $workspaceName, NodeAggregateId $nodeAggregateId, NodeTypeName $nodeTypeName, OriginDimensionSpacePoint $originDimensionSpacePoint, NodeAggregateId $parentNodeAggregateId, NodeAggregateId $succeedingSiblingNodeAggregateId = null, SerializedPropertyValues $initialPropertyValues = null): self
{
return new self($workspaceName, $nodeAggregateId, $nodeTypeName, $originDimensionSpacePoint, $parentNodeAggregateId, $initialPropertyValues ?? SerializedPropertyValues::createEmpty(), $succeedingSiblingNodeAggregateId, $nodeName, NodeAggregateIdsByNodePaths::createEmpty());
return new self($workspaceName, $nodeAggregateId, $nodeTypeName, $originDimensionSpacePoint, $parentNodeAggregateId, $initialPropertyValues ?? SerializedPropertyValues::createEmpty(), $succeedingSiblingNodeAggregateId, null, NodeAggregateIdsByNodePaths::createEmpty());
}

/**
Expand Down Expand Up @@ -105,11 +103,10 @@ public static function fromArray(array $array): self
}

/**
* Create a new CreateNodeAggregateWithNode command with all original values,
* except the tetheredDescendantNodeAggregateIds (where the passed in arguments are used).
* We precalculate all $tetheredDescendantNodeAggregateIds via {@see NodeAggregateIdsByNodePaths::completeForNodeOfType}
* so that when rebasing the command, it stays fully deterministic.
*
* Is needed to make this command fully deterministic before storing it at the events
* - we need this
* See also the documentation of the higher level API {@see CreateNodeAggregateWithNode::withTetheredDescendantNodeAggregateIds}
*/
public function withTetheredDescendantNodeAggregateIds(
NodeAggregateIdsByNodePaths $tetheredDescendantNodeAggregateIds
Expand All @@ -127,6 +124,27 @@ public function withTetheredDescendantNodeAggregateIds(
);
}

/**
* The node's optional name.
* Set if there is a meaningful relation to its parent that should be named.
*
* @deprecated the concept regarding node-names for non-tethered nodes is outdated.
*/
public function withNodeName(NodeName $nodeName): self
{
return new self(
$this->workspaceName,
$this->nodeAggregateId,
$this->nodeTypeName,
$this->originDimensionSpacePoint,
$this->parentNodeAggregateId,
$this->initialPropertyValues,
$this->succeedingSiblingNodeAggregateId,
$nodeName,
$this->tetheredDescendantNodeAggregateIds,
);
}

/**
* @return array<string,mixed>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ private function handleCreateNodeAggregateWithNode(
$command->originDimensionSpacePoint,
$command->parentNodeAggregateId,
$command->succeedingSiblingNodeAggregateId,
$command->nodeName,
$this->getPropertyConverter()->serializePropertyValues(
$command->initialPropertyValues->withoutUnsets(),
$this->requireNodeType($command->nodeTypeName)
Expand All @@ -92,6 +91,9 @@ private function handleCreateNodeAggregateWithNode(
if (!$command->tetheredDescendantNodeAggregateIds->isEmpty()) {
$lowLevelCommand = $lowLevelCommand->withTetheredDescendantNodeAggregateIds($command->tetheredDescendantNodeAggregateIds);
}
if ($command->nodeName) {
$lowLevelCommand = $lowLevelCommand->withNodeName($command->nodeName);
}

return $this->handleCreateNodeAggregateWithNodeAndSerializedProperties($lowLevelCommand, $commandHandlingDependencies);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ private function __construct(
* @param OriginDimensionSpacePoint $targetDimensionSpacePoint the dimension space point which is the target of the copy
* @param NodeAggregateId $targetParentNodeAggregateId Node aggregate id of the target node's parent. If not given, the node will be added as the parent's first child
* @param NodeAggregateId|null $targetSucceedingSiblingNodeAggregateId Node aggregate id of the target node's succeeding sibling (optional)
* @param NodeName|null $targetNodeName the root node name of the root-inserted-node
* @param NodeAggregateIdMapping $nodeAggregateIdMapping An assignment of "old" to "new" NodeAggregateIds ({@see NodeAggregateIdMapping})
*/
public static function create(WorkspaceName $workspaceName, NodeSubtreeSnapshot $nodeTreeToInsert, OriginDimensionSpacePoint $targetDimensionSpacePoint, NodeAggregateId $targetParentNodeAggregateId, ?NodeAggregateId $targetSucceedingSiblingNodeAggregateId, ?NodeName $targetNodeName, NodeAggregateIdMapping $nodeAggregateIdMapping): self
public static function create(WorkspaceName $workspaceName, NodeSubtreeSnapshot $nodeTreeToInsert, OriginDimensionSpacePoint $targetDimensionSpacePoint, NodeAggregateId $targetParentNodeAggregateId, ?NodeAggregateId $targetSucceedingSiblingNodeAggregateId, NodeAggregateIdMapping $nodeAggregateIdMapping): self
{
return new self($workspaceName, $nodeTreeToInsert, $targetDimensionSpacePoint, $targetParentNodeAggregateId, $targetSucceedingSiblingNodeAggregateId, $targetNodeName, $nodeAggregateIdMapping);
return new self($workspaceName, $nodeTreeToInsert, $targetDimensionSpacePoint, $targetParentNodeAggregateId, $targetSucceedingSiblingNodeAggregateId, null, $nodeAggregateIdMapping);
}

/**
Expand All @@ -86,8 +85,7 @@ public static function createFromSubgraphAndStartNode(
Node $startNode,
OriginDimensionSpacePoint $dimensionSpacePoint,
NodeAggregateId $targetParentNodeAggregateId,
?NodeAggregateId $targetSucceedingSiblingNodeAggregateId,
?NodeName $targetNodeName
?NodeAggregateId $targetSucceedingSiblingNodeAggregateId
): self {
$nodeSubtreeSnapshot = NodeSubtreeSnapshot::fromSubgraphAndStartNode($subgraph, $startNode);

Expand All @@ -97,7 +95,7 @@ public static function createFromSubgraphAndStartNode(
$dimensionSpacePoint,
$targetParentNodeAggregateId,
$targetSucceedingSiblingNodeAggregateId,
$targetNodeName,
null,
NodeAggregateIdMapping::generateForNodeSubtreeSnapshot($nodeSubtreeSnapshot)
);
}
Expand Down Expand Up @@ -154,6 +152,24 @@ public function withNodeAggregateIdMapping(
);
}

/**
* The target node's optional name.
*
* @deprecated the concept regarding node-names for non-tethered nodes is outdated.
*/
public function withTargetNodeName(NodeName $targetNodeName): self
{
return new self(
$this->workspaceName,
$this->nodeTreeToInsert,
$this->targetDimensionSpacePoint,
$this->targetParentNodeAggregateId,
$this->targetSucceedingSiblingNodeAggregateId,
$targetNodeName,
$this->nodeAggregateIdMapping
);
}

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
): self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Dto\NodeIdToPublishOrDiscard;
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;

/**
* All variants in a NodeAggregate have the same NodeName - and this can be changed here.
* This is the case because Node Names are usually only used for tethered nodes (=autocreated in the old CR);
* as then the Node Name is used for querying.
* All variants in a NodeAggregate have the same (optional) NodeName, which this can be changed here.
*
* Node Names are usually only used for tethered nodes; as then the Node Name is used for querying.
* Tethered Nodes cannot be renamed via the command API.
*
* @deprecated the concept regarding node-names for non-tethered nodes is outdated.
* @api commands are the write-API of the ContentRepository
*/
final readonly class ChangeNodeAggregateName implements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public function theCommandCopyNodesRecursivelyIsExecutedCopyingTheCurrentNodeAgg
$targetSucceedingSiblingNodeAggregateId = isset($commandArguments['targetSucceedingSiblingNodeAggregateId'])
? NodeAggregateId::fromString($commandArguments['targetSucceedingSiblingNodeAggregateId'])
: null;
$targetNodeName = isset($commandArguments['targetNodeName'])
? NodeName::fromString($commandArguments['targetNodeName'])
: null;

$workspaceName = isset($commandArguments['workspaceName'])
? WorkspaceName::fromString($commandArguments['workspaceName'])
: $this->currentWorkspaceName;
Expand All @@ -62,9 +60,11 @@ public function theCommandCopyNodesRecursivelyIsExecutedCopyingTheCurrentNodeAgg
$this->currentNode,
$targetDimensionSpacePoint,
NodeAggregateId::fromString($commandArguments['targetParentNodeAggregateId']),
$targetSucceedingSiblingNodeAggregateId,
$targetNodeName
$targetSucceedingSiblingNodeAggregateId
);
if (isset($commandArguments['targetNodeName'])) {
$command = $command->withTargetNodeName(NodeName::fromString($commandArguments['targetNodeName']));
}
$command = $command->withNodeAggregateIdMapping(NodeAggregateIdMapping::fromArray($commandArguments['nodeAggregateIdMapping']));

$this->currentContentRepository->handle($command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ public function theCommandCreateNodeAggregateWithNodeIsExecutedWithPayload(Table
isset($commandArguments['succeedingSiblingNodeAggregateId'])
? NodeAggregateId::fromString($commandArguments['succeedingSiblingNodeAggregateId'])
: null,
isset($commandArguments['nodeName'])
? NodeName::fromString($commandArguments['nodeName'])
: null,
isset($commandArguments['initialPropertyValues'])
? $this->deserializeProperties($commandArguments['initialPropertyValues'])
: null,
);
if (isset($commandArguments['tetheredDescendantNodeAggregateIds'])) {
$command = $command->withTetheredDescendantNodeAggregateIds(NodeAggregateIdsByNodePaths::fromArray($commandArguments['tetheredDescendantNodeAggregateIds']));
}
if (isset($commandArguments['nodeName'])) {
$command = $command->withNodeName(NodeName::fromString($commandArguments['nodeName']));
}
$this->currentContentRepository->handle($command);
}

Expand Down Expand Up @@ -198,16 +198,16 @@ public function theFollowingCreateNodeAggregateWithNodeCommandsAreExecuted(Table
!empty($row['succeedingSiblingNodeAggregateId'])
? NodeAggregateId::fromString($row['succeedingSiblingNodeAggregateId'])
: null,
isset($row['nodeName'])
? NodeName::fromString($row['nodeName'])
: null,
isset($row['initialPropertyValues'])
? $this->parsePropertyValuesJsonString($row['initialPropertyValues'])
: null,
);
if (isset($row['tetheredDescendantNodeAggregateIds'])) {
$command = $command->withTetheredDescendantNodeAggregateIds(NodeAggregateIdsByNodePaths::fromJsonString($row['tetheredDescendantNodeAggregateIds']));
}
if (isset($row['nodeName'])) {
$command = $command->withNodeName(NodeName::fromString($row['nodeName']));
}
$this->currentContentRepository->handle($command);
}
}
Expand Down Expand Up @@ -243,16 +243,16 @@ public function theCommandCreateNodeAggregateWithNodeAndSerializedPropertiesIsEx
isset($commandArguments['succeedingSiblingNodeAggregateId'])
? NodeAggregateId::fromString($commandArguments['succeedingSiblingNodeAggregateId'])
: null,
isset($commandArguments['nodeName'])
? NodeName::fromString($commandArguments['nodeName'])
: null,
isset($commandArguments['initialPropertyValues'])
? SerializedPropertyValues::fromArray($commandArguments['initialPropertyValues'])
: null
);
if (isset($commandArguments['tetheredDescendantNodeAggregateIds'])) {
$command = $command->withTetheredDescendantNodeAggregateIds(NodeAggregateIdsByNodePaths::fromArray($commandArguments['tetheredDescendantNodeAggregateIds']));
}
if (isset($commandArguments['nodeName'])) {
$command = $command->withNodeName(NodeName::fromString($commandArguments['nodeName']));
}
$this->currentContentRepository->handle($command);
}

Expand Down
3 changes: 1 addition & 2 deletions Neos.Neos/Classes/Domain/Service/SiteServiceInternals.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,10 @@ public function createSiteNodeIfNotExists(Site $site, string $nodeTypeName): voi
OriginDimensionSpacePoint::fromDimensionSpacePoint($arbitraryRootDimensionSpacePoint),
$sitesNodeIdentifier,
null,
$site->getNodeName()->toNodeName(),
PropertyValuesToWrite::fromArray([
'title' => $site->getName()
])
));
)->withNodeName($site->getNodeName()->toNodeName()));

// Handle remaining root dimension space points by creating peer variants
foreach ($rootDimensionSpacePoints as $rootDimensionSpacePoint) {
Expand Down

0 comments on commit 607134b

Please sign in to comment.