Skip to content
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

!!! FEATURE: Bind ContentGraph to workspace #5028

Merged
merged 32 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7d691d8
TASK: ContentGraph bound to Workspace
kitsunet May 6, 2024
138abbd
Apply suggestions from code review
kitsunet May 6, 2024
baec4b8
Add comments to new ContentGraph methods
kitsunet May 6, 2024
4a4b7c1
Code cleanup and documentation
kitsunet May 6, 2024
2345e3d
Fix linter issue
kitsunet May 6, 2024
24cfa06
Tweak ContentGraphFinder runtime cache
bwaidelich May 8, 2024
752894a
Merge branch 'feature/content-graph-bound' of https://github.com/kits…
bwaidelich May 8, 2024
73baee0
Merge remote-tracking branch 'origin/9.0' into feature/content-graph-…
kitsunet May 8, 2024
d5257e7
Separate CommandHandlingDependencies
kitsunet May 8, 2024
f6d7cb1
Fix phpcs errors
kitsunet May 8, 2024
5c00770
Fix lint errors
kitsunet May 8, 2024
7b884b5
Apply suggestions from code review
kitsunet May 8, 2024
1ff403c
Some cosmetic fixes
kitsunet May 9, 2024
67516e6
TASK: Declare `ContentGraphFinder` as internal and pass whole CR arou…
mhsdesign May 9, 2024
f639bf5
TASK: Try to pass one `ContentGraphTableNames` instance along instead…
mhsdesign May 9, 2024
b74e010
TASK: Refactor `HierarchyRelation` active record to use `ContentGraph…
mhsdesign May 10, 2024
e130a86
TASK: Refactor `NodeRecord` active record to use `ContentGraphTableNa…
mhsdesign May 10, 2024
723bea3
TASK: Remove string based `tableNamePrefix` from `DoctrineDbalContent…
mhsdesign May 10, 2024
14331e6
TASK: Rename `$contentGraphTableNames` to `$tableNames`
mhsdesign May 10, 2024
a208d9f
TASK: Remove dead code from ProjectionContentGraph
mhsdesign May 10, 2024
f632cb6
TASK: Use `ContentGraphTableNames` in `ProjectionContentGraph`
mhsdesign May 10, 2024
fb31212
TASK: Fix typo in `ContentGraphTableNames::hierarchyRelation`
mhsdesign May 10, 2024
9e6fcf0
Remove unused and unuseful getContentGraph methods
kitsunet May 10, 2024
4f77596
Merge pull request #3 from mhsdesign/task/refactorFurtherToContentGra…
kitsunet May 10, 2024
e045cea
Use TableNames in ProjectionIntegrityViolationDetector
kitsunet May 10, 2024
cf56d8b
TASK: Throw `WorkspaceDoesNotExist` exception when calling `getConten…
mhsdesign May 10, 2024
19b5104
TASK: Adjust executed exception to `WorkspaceDoesNotExist` in tests
mhsdesign May 10, 2024
22c8249
TASK: Remove obsolete `getSubgraphs` method
mhsdesign May 10, 2024
aa52b35
Apply suggestions from code review
kitsunet May 10, 2024
c0b5579
Remove unnecessary empty line
kitsunet May 10, 2024
8d9de7a
Re-add content stream does not exist check
kitsunet May 10, 2024
0078b7b
Don't expose ContentGraphTableNames tableNamePrefix
bwaidelich May 11, 2024
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 @@ -17,7 +17,7 @@
use Behat\Gherkin\Node\TableNode;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Neos\ContentGraph\DoctrineDbalAdapter\DoctrineDbalContentGraphProjectionFactory;
use Neos\ContentGraph\DoctrineDbalAdapter\ContentGraphTableNames;
use Neos\ContentGraph\DoctrineDbalAdapter\DoctrineDbalProjectionIntegrityViolationDetectionRunnerFactory;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentGraph\DoctrineDbalAdapter\Tests\Behavior\Features\Bootstrap\Helpers\TestingNodeAggregateId;
Expand Down Expand Up @@ -52,9 +52,9 @@ trait ProjectionIntegrityViolationDetectionTrait
*/
abstract private function getObject(string $className): object;

protected function getTableNamePrefix(): string
private function tableNames(): ContentGraphTableNames
{
return DoctrineDbalContentGraphProjectionFactory::graphProjectionTableNamePrefix(
return ContentGraphTableNames::create(
$this->currentContentRepository->id
);
}
Expand All @@ -80,7 +80,7 @@ public function iRemoveTheFollowingSubtreeTag(TableNode $payloadTable): void
throw new \RuntimeException(sprintf('Failed to remove subtree tag "%s" because that tag is not set', $subtreeTagToRemove->value), 1708618267);
}
$this->dbalClient->getConnection()->update(
$this->getTableNamePrefix() . '_hierarchyrelation',
$this->tableNames()->hierarchyRelation(),
[
'subtreetags' => json_encode($subtreeTags->without($subtreeTagToRemove), JSON_THROW_ON_ERROR | JSON_FORCE_OBJECT),
],
Expand All @@ -97,7 +97,7 @@ public function iAddTheFollowingHierarchyRelation(TableNode $payloadTable): void
$dataset = $this->transformPayloadTableToDataset($payloadTable);
$record = $this->transformDatasetToHierarchyRelationRecord($dataset);
$this->dbalClient->getConnection()->insert(
$this->getTableNamePrefix() . '_hierarchyrelation',
$this->tableNames()->hierarchyRelation(),
$record
);
}
Expand All @@ -114,7 +114,7 @@ public function iChangeTheFollowingHierarchyRelationsDimensionSpacePointHash(Tab
unset($record['position']);

$this->dbalClient->getConnection()->update(
$this->getTableNamePrefix() . '_hierarchyrelation',
$this->tableNames()->hierarchyRelation(),
[
'dimensionspacepointhash' => $dataset['newDimensionSpacePointHash']
],
Expand All @@ -134,7 +134,7 @@ public function iChangeTheFollowingHierarchyRelationsEdgeName(TableNode $payload
unset($record['position']);

$this->dbalClient->getConnection()->update(
$this->getTableNamePrefix() . '_hierarchyrelation',
$this->tableNames()->hierarchyRelation(),
[
'name' => $dataset['newName']
],
Expand All @@ -158,7 +158,7 @@ public function iSetTheFollowingPosition(TableNode $payloadTable): void
];

$this->dbalClient->getConnection()->update(
$this->getTableNamePrefix() . '_hierarchyrelation',
$this->tableNames()->hierarchyRelation(),
[
'position' => $dataset['newPosition']
],
Expand All @@ -176,7 +176,7 @@ public function iDetachTheFollowingReferenceRelationFromItsSource(TableNode $pay
$dataset = $this->transformPayloadTableToDataset($payloadTable);

$this->dbalClient->getConnection()->update(
$this->getTableNamePrefix() . '_referencerelation',
$this->tableNames()->referenceRelation(),
[
'nodeanchorpoint' => 7777777
],
Expand All @@ -194,7 +194,7 @@ public function iSetTheFollowingReferencePosition(TableNode $payloadTable): void
$dataset = $this->transformPayloadTableToDataset($payloadTable);

$this->dbalClient->getConnection()->update(
$this->getTableNamePrefix() . '_referencerelation',
$this->tableNames()->referenceRelation(),
[
'position' => $dataset['newPosition']
],
Expand Down Expand Up @@ -265,8 +265,8 @@ private function findHierarchyRelationByIds(
): array {
$nodeRecord = $this->dbalClient->getConnection()->executeQuery(
'SELECT h.*
FROM ' . $this->getTableNamePrefix() . '_node n
INNER JOIN ' . $this->getTableNamePrefix() . '_hierarchyrelation h
FROM ' . $this->tableNames()->node() . ' n
INNER JOIN ' . $this->tableNames()->hierarchyRelation() . ' h
ON n.relationanchorpoint = h.childnodeanchor
WHERE n.nodeaggregateid = :nodeAggregateId
AND h.contentstreamid = :contentStreamId
Expand Down
71 changes: 71 additions & 0 deletions Neos.ContentGraph.DoctrineDbalAdapter/src/ContentGraphFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of the Neos.ContentGraph.DoctrineDbalAdapter package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

namespace Neos\ContentGraph\DoctrineDbalAdapter;

use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ContentGraph;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentRepository\Core\ContentGraphFactoryInterface;
use Neos\ContentRepository\Core\Infrastructure\DbalClientInterface;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
* @internal only used inside the
* @see ContentGraphFinder
*/
final readonly class ContentGraphFactory implements ContentGraphFactoryInterface
{
public function __construct(
private DbalClientInterface $client,
private NodeFactory $nodeFactory,
private ContentRepositoryId $contentRepositoryId,
private NodeTypeManager $nodeTypeManager,
private ContentGraphTableNames $tableNames
) {
}

public function buildForWorkspace(WorkspaceName $workspaceName): ContentGraph
{
// FIXME: Should be part of this projection, this is forbidden
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
$tableName = strtolower(sprintf(
'cr_%s_p_%s',
$this->contentRepositoryId->value,
'workspace'
));

$row = $this->client->getConnection()->executeQuery(
'
SELECT * FROM ' . $tableName . '
WHERE workspaceName = :workspaceName
kitsunet marked this conversation as resolved.
Show resolved Hide resolved
LIMIT 1
',
[
'workspaceName' => $workspaceName->value,
]
)->fetchAssociative();

if ($row === false) {
throw WorkspaceDoesNotExist::butWasSupposedTo($workspaceName);
}

return $this->buildForWorkspaceAndContentStream($workspaceName, ContentStreamId::fromString($row['currentcontentstreamid']));
}

public function buildForWorkspaceAndContentStream(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraph
{
return new ContentGraph($this->client, $this->nodeFactory, $this->contentRepositoryId, $this->nodeTypeManager, $this->tableNames, $workspaceName, $contentStreamId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Neos\ContentGraph\DoctrineDbalAdapter;

use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;

/**
* Encapsulates table name generation for content graph tables
* @internal
*/
final readonly class ContentGraphTableNames
{
private function __construct(
private string $tableNamePrefix
) {
}

public static function create(ContentRepositoryId $contentRepositoryId): self
{
return new self(sprintf('cr_%s_p_graph', $contentRepositoryId->value));
}

public function node(): string
{
return $this->tableNamePrefix . '_node';
}

public function hierarchyRelation(): string
{
return $this->tableNamePrefix . '_hierarchyrelation';
}

public function dimensionSpacePoints(): string
{
return $this->tableNamePrefix . '_dimensionspacepoints';
}

public function referenceRelation(): string
{
return $this->tableNamePrefix . '_referencerelation';
}

public function checkpoint(): string
{
return $this->tableNamePrefix . '_checkpoint';
}
}
Loading
Loading