Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Neos\ContentGraph\DoctrineDbalAdapter\ContentGraphTableNames;
use Neos\ContentGraph\DoctrineDbalAdapter\DoctrineDbalProjectionIntegrityViolationDetectionRunnerFactory;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\ContentStreamDbId;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentGraph\DoctrineDbalAdapter\Tests\Behavior\Features\Bootstrap\Helpers\TestingNodeAggregateId;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
Expand Down Expand Up @@ -118,7 +119,9 @@ public function iChangeTheFollowingHierarchyRelationsParent(TableNode $payloadTa
unset($record['subtreetags']);

$newParentHierarchyRelation = $this->findHierarchyRelationByIds(
ContentStreamId::fromString($dataset['contentStreamId']),
$this->getContentStreamDbId(
ContentStreamId::fromString($dataset['contentStreamId'])
),
DimensionSpacePoint::fromArray($dataset['dimensionSpacePoint']),
NodeAggregateId::fromString($dataset['newParentNodeAggregateId'])
);
Expand Down Expand Up @@ -162,14 +165,18 @@ public function iChangeTheFollowingNodesName(TableNode $payloadTable): void
{
$dataset = $this->transformPayloadTableToDataset($payloadTable);

$contentStreamDbId = $this->getContentStreamDbId(
ContentStreamId::fromString($dataset['contentStreamId'])
);

$relationAnchorPoint = $this->dbal->executeQuery(
'SELECT n.relationanchorpoint FROM ' . $this->tableNames()->node() . ' n
JOIN ' . $this->tableNames()->hierarchyRelation() . ' h ON h.childnodeanchor = n.relationanchorpoint
WHERE h.contentstreamid = :contentStreamId
WHERE h.contentstreamdbid = :contentStreamDbId
AND n.nodeaggregateId = :nodeAggregateId
AND n.origindimensionspacepointhash = :originDimensionSpacePointHash',
[
'contentStreamId' => $dataset['contentStreamId'],
'contentStreamDbId' => $contentStreamDbId->value,
'nodeAggregateId' => $dataset['nodeAggregateId'],
'originDimensionSpacePointHash' => OriginDimensionSpacePoint::fromArray($dataset['originDimensionSpacePoint'])->hash,
]
Expand All @@ -195,8 +202,13 @@ public function iSetTheFollowingPosition(TableNode $payloadTable): void
{
$dataset = $this->transformPayloadTableToDataset($payloadTable);
$dimensionSpacePoint = DimensionSpacePoint::fromArray($dataset['dimensionSpacePoint']);

$contentStreamDbId = $this->getContentStreamDbId(
ContentStreamId::fromString($dataset['contentStreamId'])
);

$record = [
'contentstreamid' => $dataset['contentStreamId'],
'contentstreamdbid' => $contentStreamDbId->value,
'dimensionspacepointhash' => $dimensionSpacePoint->hash,
'childnodeanchor' => $this->findRelationAnchorPointByDataset($dataset)
];
Expand Down Expand Up @@ -251,7 +263,9 @@ private function transformDatasetToReferenceRelationRecord(array $dataset): arra
return [
'name' => $dataset['referenceName'],
'nodeanchorpoint' => $this->findHierarchyRelationByIds(
ContentStreamId::fromString($dataset['contentStreamId']),
$this->getContentStreamDbId(
ContentStreamId::fromString($dataset['contentStreamId'])
),
DimensionSpacePoint::fromArray($dataset['dimensionSpacePoint']),
NodeAggregateId::fromString($dataset['sourceNodeAggregateId'])
)['childnodeanchor'],
Expand All @@ -264,25 +278,28 @@ private function transformDatasetToHierarchyRelationRecord(array $dataset): arra
$dimensionSpacePoint = DimensionSpacePoint::fromArray($dataset['dimensionSpacePoint']);
$parentNodeAggregateId = TestingNodeAggregateId::fromString($dataset['parentNodeAggregateId']);
$childAggregateId = TestingNodeAggregateId::fromString($dataset['childNodeAggregateId']);
$contentStreamDbId = $this->getContentStreamDbId(
ContentStreamId::fromString($dataset['contentStreamId'])
);

$parentHierarchyRelation = $parentNodeAggregateId->isNonExistent()
? null
: $this->findHierarchyRelationByIds(
ContentStreamId::fromString($dataset['contentStreamId']),
$contentStreamDbId,
$dimensionSpacePoint,
NodeAggregateId::fromString($dataset['parentNodeAggregateId'])
);

$childHierarchyRelation = $childAggregateId->isNonExistent()
? null
: $this->findHierarchyRelationByIds(
ContentStreamId::fromString($dataset['contentStreamId']),
$contentStreamDbId,
$dimensionSpacePoint,
NodeAggregateId::fromString($dataset['childNodeAggregateId'])
);

return [
'contentstreamid' => $dataset['contentStreamId'],
'contentstreamdbid' => $contentStreamDbId->value,
'dimensionspacepointhash' => $dimensionSpacePoint->hash,
'parentnodeanchor' => $parentHierarchyRelation !== null ? $parentHierarchyRelation['childnodeanchor'] : 9999999,
'childnodeanchor' => $childHierarchyRelation !== null ? $childHierarchyRelation['childnodeanchor'] : 8888888,
Expand All @@ -296,14 +313,16 @@ private function findRelationAnchorPointByDataset(array $dataset): int
$dimensionSpacePoint = DimensionSpacePoint::fromArray($dataset['originDimensionSpacePoint'] ?? $dataset['dimensionSpacePoint']);

return $this->findHierarchyRelationByIds(
ContentStreamId::fromString($dataset['contentStreamId']),
$this->getContentStreamDbId(
ContentStreamId::fromString($dataset['contentStreamId'])
),
$dimensionSpacePoint,
NodeAggregateId::fromString($dataset['nodeAggregateId'] ?? $dataset['childNodeAggregateId'])
)['childnodeanchor'];
}

private function findHierarchyRelationByIds(
ContentStreamId $contentStreamId,
ContentStreamDbId $contentStreamDbId,
DimensionSpacePoint $dimensionSpacePoint,
NodeAggregateId $nodeAggregateId
): array {
Expand All @@ -312,17 +331,17 @@ private function findHierarchyRelationByIds(
FROM ' . $this->tableNames()->node() . ' n
INNER JOIN ' . $this->tableNames()->hierarchyRelation() . ' h
ON n.relationanchorpoint = h.childnodeanchor
WHERE n.nodeaggregateid = :nodeAggregateId
AND h.contentstreamid = :contentStreamId
WHERE h.contentstreamdbid = :contentStreamDbId
AND n.nodeaggregateid = :nodeAggregateId
AND h.dimensionspacepointhash = :dimensionSpacePointHash',
[
'contentStreamId' => $contentStreamId->value,
'contentStreamDbId' => $contentStreamDbId->value,
'dimensionSpacePointHash' => $dimensionSpacePoint->hash,
'nodeAggregateId' => $nodeAggregateId->value
]
)->fetchAssociative();
if ($nodeRecord === false) {
throw new \InvalidArgumentException(sprintf('Failed to find hierarchy relation for content stream "%s", dimension space point "%s" and node aggregate id "%s"', $contentStreamId->value, $dimensionSpacePoint->hash, $nodeAggregateId->value), 1708617712);
throw new \InvalidArgumentException(sprintf('Failed to find hierarchy relation for content stream "%s", dimension space point "%s" and node aggregate id "%s"', $contentStreamDbId->value, $dimensionSpacePoint->hash, $nodeAggregateId->value), 1708617712);
}

return $nodeRecord;
Expand All @@ -338,6 +357,18 @@ private function transformPayloadTableToDataset(TableNode $payloadTable): array
return $result;
}

private function getContentStreamDbId(ContentStreamId $contentStreamId): ContentStreamDbId
{
return ContentStreamDbId::fromInt(
$this->dbal->executeQuery(
'SELECT dbId FROM ' . $this->tableNames()->contentStream() . ' WHERE id = :contentStreamId',
[
'contentStreamId' => $contentStreamId->value,
]
)->fetchOne()
);
}

/**
* @When /^I run integrity violation detection$/
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Query\QueryBuilder;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\ContentStreamDbId;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ContentGraph;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
Expand Down Expand Up @@ -49,11 +50,13 @@ public function getContentGraph(WorkspaceName $workspaceName): ContentGraph
{
$currentContentStreamIdStatement = <<<SQL
SELECT
currentContentStreamId
ws.currentContentStreamId,
cs.dbId AS contentStreamDbId
FROM
{$this->tableNames->workspace()}
{$this->tableNames->workspace()} ws
JOIN {$this->tableNames->contentStream()} cs ON cs.id = ws.currentContentStreamId
WHERE
name = :workspaceName
ws.name = :workspaceName
LIMIT 1
SQL;
try {
Expand All @@ -67,7 +70,8 @@ public function getContentGraph(WorkspaceName $workspaceName): ContentGraph
throw WorkspaceDoesNotExist::butWasSupposedTo($workspaceName);
}
$currentContentStreamId = ContentStreamId::fromString($row['currentContentStreamId']);
return new ContentGraph($this->dbal, $this->nodeFactory, $this->contentRepositoryId, $this->nodeTypeManager, $this->tableNames, $workspaceName, $currentContentStreamId);
$contentStreamDbId = ContentStreamDbId::fromInt((int)$row['contentStreamDbId']);
return new ContentGraph($this->dbal, $this->nodeFactory, $this->contentRepositoryId, $this->nodeTypeManager, $this->tableNames, $workspaceName, $currentContentStreamId, $contentStreamDbId);
}

public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace
Expand Down
Loading
Loading