Skip to content

Commit

Permalink
4993 - Adjust subtree tag moval CTE to pass the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schmitt committed May 5, 2024
1 parent 22ced03 commit 097918f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ private function whenNodeAggregateWasMoved(NodeAggregateWasMoved $event): void
);
$this->moveSubtreeTags(
$event->contentStreamId,
$event->nodeAggregateId,
$event->newParentNodeAggregateId,
$succeedingSiblingForCoverage->dimensionSpacePoint
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ private function whenSubtreeWasUntagged(SubtreeWasUntagged $event): void
]);
}

private function moveSubtreeTags(ContentStreamId $contentStreamId, NodeAggregateId $nodeAggregateId, NodeAggregateId $newParentNodeAggregateId, DimensionSpacePoint $coveredDimensionSpacePoint): void
{
private function moveSubtreeTags(
ContentStreamId $contentStreamId,
NodeAggregateId $newParentNodeAggregateId,
DimensionSpacePoint $coveredDimensionSpacePoint
): void {
$this->getDatabaseConnection()->executeStatement('
UPDATE ' . $this->getTableNamePrefix() . '_hierarchyrelation h,
(
Expand All @@ -146,20 +149,36 @@ private function moveSubtreeTags(ContentStreamId $contentStreamId, NodeAggregate
' . $this->getTableNamePrefix() . '_hierarchyrelation th
INNER JOIN ' . $this->getTableNamePrefix() . '_node tn ON tn.relationanchorpoint = th.childnodeanchor
WHERE
tn.nodeaggregateid = :nodeAggregateId
tn.nodeaggregateid = :newParentNodeAggregateId
AND th.contentstreamid = :contentStreamId
AND th.dimensionspacepointhash = :dimensionSpacePointHash
UNION
SELECT JSON_MERGE(cte.subtreetagsToInherit, JSON_KEYS(JSON_MERGE_PATCH(\'{}\', dh.subtreetags))) subtreeTagsToInherit, dh.childnodeanchor
SELECT
JSON_MERGE_PRESERVE(
cte.subtreeTagsToInherit,
JSON_KEYS(JSON_MERGE_PATCH(
\'{}\',
dh.subtreetags
))
) subtreeTagsToInherit,
dh.childnodeanchor
FROM
cte
JOIN ' . $this->getTableNamePrefix() . '_hierarchyrelation dh ON dh.parentnodeanchor = cte.childnodeanchor
JOIN ' . $this->getTableNamePrefix() . '_hierarchyrelation dh
ON
dh.parentnodeanchor = cte.childnodeanchor
WHERE
dh.contentstreamid = :contentStreamId
AND dh.dimensionspacepointhash = :dimensionSpacePointHash
)
SELECT * FROM cte
) AS r
SET h.subtreetags = (
SELECT
JSON_MERGE_PATCH(JSON_OBJECTAGG(htk.k, null), JSON_MERGE_PATCH(\'{}\', h.subtreetags))
JSON_MERGE_PATCH(
IFNULL(JSON_OBJECTAGG(htk.k, null), \'{}\'),
JSON_MERGE_PATCH(\'{}\', h.subtreetags)
)
FROM
JSON_TABLE(r.subtreeTagsToInherit, \'$[*]\' COLUMNS (k VARCHAR(36) PATH \'$\')) htk
)
Expand All @@ -169,7 +188,7 @@ private function moveSubtreeTags(ContentStreamId $contentStreamId, NodeAggregate
AND h.dimensionspacepointhash = :dimensionSpacePointHash
', [
'contentStreamId' => $contentStreamId->value,
'nodeAggregateId' => $newParentNodeAggregateId->value,
'newParentNodeAggregateId' => $newParentNodeAggregateId->value,
'dimensionSpacePointHash' => $coveredDimensionSpacePoint->hash,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,11 @@ public function iExpectTheNodeWithAggregateIdentifierToNotContainTheTag(string $
public function iExpectThisNodeToBeExactlyExplicitlyTagged(string $expectedTagList): void
{
$this->assertOnCurrentNode(function (Node $currentNode) use ($expectedTagList) {
$actualTags = $currentNode->tags->withoutInherited()->toStringArray();
sort($actualTags);
Assert::assertSame(
($expectedTagList === '') ? [] : explode(',', $expectedTagList),
$currentNode->tags->withoutInherited()->toStringArray()
$actualTags
);
});
}
Expand All @@ -262,9 +264,11 @@ public function iExpectThisNodeToBeExactlyExplicitlyTagged(string $expectedTagLi
public function iExpectThisNodeToExactlyInheritTheTags(string $expectedTagList): void
{
$this->assertOnCurrentNode(function (Node $currentNode) use ($expectedTagList) {
$actualTags = $currentNode->tags->onlyInherited()->toStringArray();
sort($actualTags);
Assert::assertSame(
($expectedTagList === '') ? [] : explode(',', $expectedTagList),
$currentNode->tags->onlyInherited()->toStringArray(),
$actualTags,
);
});
}
Expand Down

0 comments on commit 097918f

Please sign in to comment.