Skip to content

Commit

Permalink
Merge pull request #5018 from neos/4150-copyOnRename
Browse files Browse the repository at this point in the history
!!! TASK: Node name consistency adjustments
  • Loading branch information
kitsunet committed May 13, 2024
2 parents 7c5784f + e07783c commit b1a5abd
Show file tree
Hide file tree
Showing 35 changed files with 559 additions and 417 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentGraph\DoctrineDbalAdapter\Tests\Behavior\Features\Bootstrap\Helpers\TestingNodeAggregateId;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Dto\SubtreeTag;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
Expand Down Expand Up @@ -123,22 +124,35 @@ public function iChangeTheFollowingHierarchyRelationsDimensionSpacePointHash(Tab
}

/**
* @When /^I change the following hierarchy relation's name:$/
* @When /^I change the following node's name:$/
* @param TableNode $payloadTable
* @throws DBALException
*/
public function iChangeTheFollowingHierarchyRelationsEdgeName(TableNode $payloadTable): void
public function iChangeTheFollowingNodesName(TableNode $payloadTable): void
{
$dataset = $this->transformPayloadTableToDataset($payloadTable);
$record = $this->transformDatasetToHierarchyRelationRecord($dataset);
unset($record['position']);

$relationAnchorPoint = $this->dbalClient->getConnection()->executeQuery(
'SELECT n.relationanchorpoint FROM ' . $this->tableNames()->node() . ' n
JOIN ' . $this->tableNames()->hierarchyRelation() . ' h ON h.childnodeanchor = n.relationanchorpoint
WHERE h.contentstreamid = :contentStreamId
AND n.nodeaggregateId = :nodeAggregateId
AND n.origindimensionspacepointhash = :originDimensionSpacePointHash',
[
'contentStreamId' => $dataset['contentStreamId'],
'nodeAggregateId' => $dataset['nodeAggregateId'],
'originDimensionSpacePointHash' => OriginDimensionSpacePoint::fromArray($dataset['originDimensionSpacePoint'])->hash,
]
)->fetchOne();

$this->dbalClient->getConnection()->update(
$this->tableNames()->hierarchyRelation(),
$this->tableNames()->node(),
[
'name' => $dataset['newName']
],
$record
[
'relationanchorpoint' => $relationAnchorPoint
]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,47 @@ Feature: Run projection integrity violation detection regarding naming of tether
And using identifier "default", I define a content repository
And I am in content repository "default"
And the command CreateRootWorkspace is executed with payload:
| Key | Value |
| workspaceName | "live" |
| workspaceTitle | "Live" |
| workspaceDescription | "The live workspace" |
| newContentStreamId | "cs-identifier" |
| Key | Value |
| workspaceName | "live" |
| workspaceTitle | "Live" |
| workspaceDescription | "The live workspace" |
| newContentStreamId | "cs-identifier" |
And the graph projection is fully up to date
And I am in workspace "live" and dimension space point {"language":"de"}
And the command CreateRootNodeAggregateWithNode is executed with payload:
| Key | Value |
| nodeAggregateId | "lady-eleonode-rootford" |
| nodeTypeName | "Neos.ContentRepository:Root" |
| Key | Value |
| nodeAggregateId | "lady-eleonode-rootford" |
| nodeTypeName | "Neos.ContentRepository:Root" |
And the event NodeAggregateWithNodeWasCreated was published with payload:
| Key | Value |
| contentStreamId | "cs-identifier" |
| nodeAggregateId | "sir-david-nodenborough" |
| nodeTypeName | "Neos.ContentRepository.Testing:Document" |
| originDimensionSpacePoint | {"language":"de"} |
| coveredDimensionSpacePoints | [{"language":"de"}] |
| parentNodeAggregateId | "lady-eleonode-rootford" |
| nodeName | "document" |
| nodeAggregateClassification | "regular" |
| Key | Value |
| contentStreamId | "cs-identifier" |
| nodeAggregateId | "sir-david-nodenborough" |
| nodeTypeName | "Neos.ContentRepository.Testing:Document" |
| originDimensionSpacePoint | {"language":"de"} |
| coveredDimensionSpacePoints | [{"language":"de"}] |
| parentNodeAggregateId | "lady-eleonode-rootford" |
| nodeName | "document" |
| nodeAggregateClassification | "regular" |
And the graph projection is fully up to date

Scenario: Create node variants of different type
Scenario: Remove tethered node's name
When the event NodeAggregateWithNodeWasCreated was published with payload:
| Key | Value |
| contentStreamId | "cs-identifier" |
| nodeAggregateId | "nodewyn-tetherton" |
| nodeTypeName | "Neos.ContentRepository.Testing:Document" |
| originDimensionSpacePoint | {"language":"de"} |
| coveredDimensionSpacePoints | [{"language":"de"}] |
| parentNodeAggregateId | "sir-david-nodenborough" |
| nodeName | "to-be-hacked-to-null" |
| nodeAggregateClassification | "tethered" |
| Key | Value |
| contentStreamId | "cs-identifier" |
| nodeAggregateId | "nodewyn-tetherton" |
| nodeTypeName | "Neos.ContentRepository.Testing:Document" |
| originDimensionSpacePoint | {"language":"de"} |
| coveredDimensionSpacePoints | [{"language":"de"}] |
| parentNodeAggregateId | "sir-david-nodenborough" |
| nodeName | "to-be-hacked-to-null" |
| nodeAggregateClassification | "tethered" |
And the graph projection is fully up to date
And I change the following hierarchy relation's name:
| Key | Value |
| contentStreamId | "cs-identifier" |
| dimensionSpacePoint | {"language":"de"} |
| parentNodeAggregateId | "sir-david-nodenborough" |
| childNodeAggregateId | "nodewyn-tetherton" |
| newName | null |
And I change the following node's name:
| Key | Value |
| contentStreamId | "cs-identifier" |
| originDimensionSpacePoint | {"language":"de"} |
| nodeAggregateId | "nodewyn-tetherton" |
| newName | null |
And I run integrity violation detection
Then I expect the integrity violation detection result to contain exactly 1 errors
And I expect integrity violation detection result error number 1 to have code 1597923103
Original file line number Diff line number Diff line change
Expand Up @@ -321,28 +321,24 @@ private function whenNodeAggregateWithNodeWasCreated(NodeAggregateWithNodeWasCre
private function whenNodeAggregateNameWasChanged(NodeAggregateNameWasChanged $event, EventEnvelope $eventEnvelope): void
{
$this->transactional(function () use ($event, $eventEnvelope) {
$this->getDatabaseConnection()->executeStatement('
UPDATE ' . $this->tableNames->hierarchyRelation() . ' h
INNER JOIN ' . $this->tableNames->node() . ' n on
h.childnodeanchor = n.relationanchorpoint
SET
h.name = :newName,
n.lastmodified = :lastModified,
n.originallastmodified = :originalLastModified
WHERE
n.nodeaggregateid = :nodeAggregateId
and h.contentstreamid = :contentStreamId
', [
'newName' => $event->newNodeName->value,
'nodeAggregateId' => $event->nodeAggregateId->value,
'contentStreamId' => $event->contentStreamId->value,
'lastModified' => $eventEnvelope->recordedAt,
'originalLastModified' => self::initiatingDateTime($eventEnvelope),
], [
'lastModified' => Types::DATETIME_IMMUTABLE,
'originalLastModified' => Types::DATETIME_IMMUTABLE,
]);
foreach (
$this->projectionContentGraph->getAnchorPointsForNodeAggregateInContentStream(
$event->nodeAggregateId,
$event->contentStreamId,
) as $anchorPoint
) {
$this->updateNodeRecordWithCopyOnWrite(
$event->contentStreamId,
$anchorPoint,
function (NodeRecord $node) use ($event, $eventEnvelope) {
$node->nodeName = $event->newNodeName;
$node->timestamps = $node->timestamps->with(
lastModified: $eventEnvelope->recordedAt,
originalLastModified: self::initiatingDateTime($eventEnvelope)
);
}
);
}
});
}

Expand Down Expand Up @@ -408,7 +404,6 @@ private function createNodeWithHierarchy(
$node->relationAnchorPoint,
new DimensionSpacePointSet([$dimensionSpacePoint]),
$succeedingSibling?->relationAnchorPoint,
$nodeName
);
}
}
Expand All @@ -419,7 +414,6 @@ private function createNodeWithHierarchy(
* @param NodeRelationAnchorPoint $parentNodeAnchorPoint
* @param NodeRelationAnchorPoint $childNodeAnchorPoint
* @param NodeRelationAnchorPoint|null $succeedingSiblingNodeAnchorPoint
* @param NodeName|null $relationName
* @param ContentStreamId $contentStreamId
* @param DimensionSpacePointSet $dimensionSpacePointSet
* @throws \Doctrine\DBAL\DBALException
Expand All @@ -430,7 +424,6 @@ private function connectHierarchy(
NodeRelationAnchorPoint $childNodeAnchorPoint,
DimensionSpacePointSet $dimensionSpacePointSet,
?NodeRelationAnchorPoint $succeedingSiblingNodeAnchorPoint,
NodeName $relationName = null
): void {
foreach ($dimensionSpacePointSet as $dimensionSpacePoint) {
$position = $this->getRelationPosition(
Expand All @@ -447,7 +440,6 @@ private function connectHierarchy(
$hierarchyRelation = new HierarchyRelation(
$parentNodeAnchorPoint,
$childNodeAnchorPoint,
$relationName,
$contentStreamId,
$dimensionSpacePoint,
$dimensionSpacePoint->hash,
Expand Down Expand Up @@ -562,7 +554,6 @@ private function whenContentStreamWasForked(ContentStreamWasForked $event): void
INSERT INTO ' . $this->tableNames->hierarchyRelation() . ' (
parentnodeanchor,
childnodeanchor,
`name`,
position,
dimensionspacepointhash,
subtreetags,
Expand All @@ -571,7 +562,6 @@ private function whenContentStreamWasForked(ContentStreamWasForked $event): void
SELECT
h.parentnodeanchor,
h.childnodeanchor,
h.name,
h.position,
h.dimensionspacepointhash,
h.subtreetags,
Expand Down Expand Up @@ -744,7 +734,6 @@ protected function copyHierarchyRelationToDimensionSpacePoint(
$copy = new HierarchyRelation(
$newParent,
$newChild,
$sourceHierarchyRelation->name,
$contentStreamId,
$dimensionSpacePoint,
$dimensionSpacePoint->hash,
Expand Down Expand Up @@ -964,7 +953,6 @@ private function whenDimensionShineThroughWasAdded(DimensionShineThroughWasAdded
INSERT INTO ' . $this->tableNames->hierarchyRelation() . ' (
parentnodeanchor,
childnodeanchor,
`name`,
position,
subtreetags,
dimensionspacepointhash,
Expand All @@ -973,7 +961,6 @@ private function whenDimensionShineThroughWasAdded(DimensionShineThroughWasAdded
SELECT
h.parentnodeanchor,
h.childnodeanchor,
h.name,
h.position,
h.subtreetags,
:newDimensionSpacePointHash AS dimensionspacepointhash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private function createNodeTable(): Table
DbalSchemaFactory::columnForNodeAggregateId('nodeaggregateid')->setNotnull(false),
DbalSchemaFactory::columnForDimensionSpacePointHash('origindimensionspacepointhash')->setNotnull(false),
DbalSchemaFactory::columnForNodeTypeName('nodetypename'),
(new Column('name', Type::getType(Types::STRING)))->setLength(255)->setNotnull(false)->setCustomSchemaOption('charset', 'ascii')->setCustomSchemaOption('collation', 'ascii_general_ci'),
(new Column('properties', Type::getType(Types::TEXT)))->setNotnull(true)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('classification', Type::getType(Types::BINARY)))->setLength(20)->setNotnull(true),
(new Column('created', Type::getType(Types::DATETIME_IMMUTABLE)))->setDefault('CURRENT_TIMESTAMP')->setNotnull(true),
Expand All @@ -56,7 +57,6 @@ private function createNodeTable(): Table
private function createHierarchyRelationTable(): Table
{
$table = new Table($this->contentGraphTableNames->hierarchyRelation(), [
(new Column('name', Type::getType(Types::STRING)))->setLength(255)->setNotnull(false)->setCustomSchemaOption('charset', 'ascii')->setCustomSchemaOption('collation', 'ascii_general_ci'),
(new Column('position', Type::getType(Types::INTEGER)))->setNotnull(true),
DbalSchemaFactory::columnForContentStreamId('contentstreamid')->setNotnull(true),
DbalSchemaFactory::columnForDimensionSpacePointHash('dimensionspacepointhash')->setNotnull(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVaria
$hierarchyRelation = new HierarchyRelation(
$parentNode->relationAnchorPoint,
$specializedNode->relationAnchorPoint,
$sourceNode->nodeName,
$event->contentStreamId,
$uncoveredDimensionSpacePoint,
$uncoveredDimensionSpacePoint->hash,
Expand Down Expand Up @@ -358,7 +357,6 @@ public function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event,
$peerNode->relationAnchorPoint,
new DimensionSpacePointSet([$coveredDimensionSpacePoint]),
$peerSucceedingSiblingNode?->relationAnchorPoint,
$sourceNode->nodeName
);
}

Expand Down Expand Up @@ -391,7 +389,6 @@ abstract protected function connectHierarchy(
NodeRelationAnchorPoint $childNodeAnchorPoint,
DimensionSpacePointSet $dimensionSpacePointSet,
?NodeRelationAnchorPoint $succeedingSiblingNodeAnchorPoint,
NodeName $relationName = null
): void;

abstract protected function copyReferenceRelations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\DimensionSpacePointsRepository;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTags;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;

/**
Expand All @@ -32,7 +31,6 @@
public function __construct(
public NodeRelationAnchorPoint $parentNodeAnchor,
public NodeRelationAnchorPoint $childNodeAnchor,
public ?NodeName $name,
public ContentStreamId $contentStreamId,
public DimensionSpacePoint $dimensionSpacePoint,
public string $dimensionSpacePointHash,
Expand All @@ -55,7 +53,6 @@ public function addToDatabase(Connection $databaseConnection, ContentGraphTableN
$databaseConnection->insert($tableNames->hierarchyRelation(), [
'parentnodeanchor' => $this->parentNodeAnchor->value,
'childnodeanchor' => $this->childNodeAnchor->value,
'name' => $this->name?->value,
'contentstreamid' => $this->contentStreamId->value,
'dimensionspacepointhash' => $this->dimensionSpacePointHash,
'position' => $this->position,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public function __construct(
public SerializedPropertyValues $properties,
public NodeTypeName $nodeTypeName,
public NodeAggregateClassification $classification,
/** Transient node name to store a node name after fetching a node with hierarchy (not always available) */
public ?NodeName $nodeName,
public Timestamps $timestamps,
) {
Expand All @@ -59,6 +58,7 @@ public function updateToDatabase(Connection $databaseConnection, ContentGraphTab
'origindimensionspacepointhash' => $this->originDimensionSpacePointHash,
'properties' => json_encode($this->properties),
'nodetypename' => $this->nodeTypeName->value,
'name' => $this->nodeName?->value,
'classification' => $this->classification->value,
'lastmodified' => $this->timestamps->lastModified,
'originallastmodified' => $this->timestamps->originalLastModified,
Expand Down Expand Up @@ -123,6 +123,7 @@ public static function createNewInDatabase(
$originDimensionSpacePointHash,
$properties,
$nodeTypeName,
$nodeName,
$classification,
$timestamps
) {
Expand All @@ -134,6 +135,7 @@ public static function createNewInDatabase(
'origindimensionspacepointhash' => $originDimensionSpacePointHash,
'properties' => json_encode($properties),
'nodetypename' => $nodeTypeName->value,
'name' => $nodeName?->value,
'classification' => $classification->value,
'created' => $timestamps->created,
'originalcreated' => $timestamps->originalCreated,
Expand Down

0 comments on commit b1a5abd

Please sign in to comment.