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

WIP: TASK: Add workspace content stream mapping to content graph projection #5086

Closed
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
17 changes: 5 additions & 12 deletions Neos.ContentGraph.DoctrineDbalAdapter/src/ContentGraphFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,22 @@ public function __construct(

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

$row = $this->dbal->executeQuery(
$contentStreamId = $this->dbal->executeQuery(
'
SELECT * FROM ' . $tableName . '
SELECT currentcontentstreamid FROM ' . $this->tableNames->workspace() . '
WHERE workspaceName = :workspaceName
LIMIT 1
',
[
'workspaceName' => $workspaceName->value,
]
)->fetchAssociative();
)->fetchOne();

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

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

public function buildForWorkspaceAndContentStream(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public function referenceRelation(): string
return $this->tableNamePrefix . '_referencerelation';
}

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

public function checkpoint(): string
{
return $this->tableNamePrefix . '_checkpoint';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Types\Types;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\Feature\NodeMove;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\Feature\NodeRemoval;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\Feature\NodeVariation;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\Feature\SubtreeTagging;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\Feature\Workspace;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\HierarchyRelation;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\NodeRecord;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\NodeRelationAnchorPoint;
Expand Down Expand Up @@ -43,6 +43,16 @@
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Dto\SubtreeTags;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasTagged;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasUntagged;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Event\RootWorkspaceWasCreated;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Event\WorkspaceWasCreated;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Event\WorkspaceBaseWorkspaceWasChanged;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Event\WorkspaceWasRemoved;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasDiscarded;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPartiallyDiscarded;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPartiallyPublished;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPublished;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Event\WorkspaceRebaseFailed;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Event\WorkspaceWasRebased;
use Neos\ContentRepository\Core\Infrastructure\DbalCheckpointStorage;
use Neos\ContentRepository\Core\Infrastructure\DbalSchemaDiff;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
Expand All @@ -69,6 +79,7 @@
use SubtreeTagging;
use NodeRemoval;
use NodeMove;
use Workspace;


public const RELATION_DEFAULT_OFFSET = 128;
Expand Down Expand Up @@ -96,7 +107,19 @@

public function setUp(): void
{
foreach ($this->determineRequiredSqlStatements() as $statement) {
$statements = $this->determineRequiredSqlStatements();

// MIGRATION from 2024-05-23: copy data from "cr_<crid>_p_workspace" to "cr_<crid>_p_graph_workspace" table
$legacyWorkspaceTableName = str_replace('_p_graph_workspace', '_p_workspace', $this->tableNames->workspace());
if (
$this->dbal->getSchemaManager()?->tablesExist([$legacyWorkspaceTableName])

Check failure on line 115 in Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Using nullsafe method call on non-nullable type Doctrine\DBAL\Schema\AbstractSchemaManager. Use -> instead.

Check failure on line 115 in Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

Using nullsafe method call on non-nullable type Doctrine\DBAL\Schema\AbstractSchemaManager. Use -> instead.
&& !$this->dbal->getSchemaManager()?->tablesExist([$this->tableNames->workspace()])

Check failure on line 116 in Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Using nullsafe method call on non-nullable type Doctrine\DBAL\Schema\AbstractSchemaManager. Use -> instead.

Check failure on line 116 in Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

Using nullsafe method call on non-nullable type Doctrine\DBAL\Schema\AbstractSchemaManager. Use -> instead.
) {
$statements[] = 'INSERT INTO ' . $this->tableNames->workspace() . ' (workspacename, baseworkspacename, currentcontentstreamid, status) SELECT workspacename, baseworkspacename, currentcontentstreamid, status FROM ' . $legacyWorkspaceTableName;
}
// /MIGRATION

foreach ($statements as $statement) {
$this->getDatabaseConnection()->executeStatement($statement);
}
$this->checkpointStorage->setUp();
Expand Down Expand Up @@ -160,6 +183,7 @@
$this->dbal->executeQuery('TRUNCATE table ' . $this->tableNames->hierarchyRelation());
$this->dbal->executeQuery('TRUNCATE table ' . $this->tableNames->referenceRelation());
$this->dbal->executeQuery('TRUNCATE table ' . $this->tableNames->dimensionSpacePoints());
$this->dbal->executeQuery('TRUNCATE table ' . $this->tableNames->workspace());
}

public function canHandle(EventInterface $event): bool
Expand All @@ -183,7 +207,19 @@
NodePeerVariantWasCreated::class,
SubtreeWasTagged::class,
SubtreeWasUntagged::class,
]);

/** Workspace related events, {@see Workspace} trait **/
WorkspaceWasCreated::class,
RootWorkspaceWasCreated::class,
WorkspaceWasDiscarded::class,
WorkspaceWasPartiallyDiscarded::class,
WorkspaceWasPartiallyPublished::class,
WorkspaceWasPublished::class,
WorkspaceWasRebased::class,
WorkspaceRebaseFailed::class,
WorkspaceWasRemoved::class,
WorkspaceBaseWorkspaceWasChanged::class,
], true);
}

public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
Expand All @@ -207,6 +243,18 @@
NodePeerVariantWasCreated::class => $this->whenNodePeerVariantWasCreated($event, $eventEnvelope),
SubtreeWasTagged::class => $this->whenSubtreeWasTagged($event),
SubtreeWasUntagged::class => $this->whenSubtreeWasUntagged($event),

WorkspaceWasCreated::class => $this->whenWorkspaceWasCreated($event),
RootWorkspaceWasCreated::class => $this->whenRootWorkspaceWasCreated($event),
WorkspaceWasDiscarded::class => $this->whenWorkspaceWasDiscarded($event),
WorkspaceWasPartiallyDiscarded::class => $this->whenWorkspaceWasPartiallyDiscarded($event),
WorkspaceWasPartiallyPublished::class => $this->whenWorkspaceWasPartiallyPublished($event),
WorkspaceWasPublished::class => $this->whenWorkspaceWasPublished($event),
WorkspaceWasRebased::class => $this->whenWorkspaceWasRebased($event),
WorkspaceRebaseFailed::class => $this->whenWorkspaceRebaseFailed($event),
WorkspaceWasRemoved::class => $this->whenWorkspaceWasRemoved($event),
WorkspaceBaseWorkspaceWasChanged::class => $this->whenWorkspaceBaseWorkspaceWasChanged($event),

default => throw new \InvalidArgumentException(sprintf('Unsupported event %s', get_debug_type($event))),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Neos\ContentRepository\Core\Infrastructure\DbalSchemaFactory;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
* @internal
Expand All @@ -18,7 +19,7 @@ class DoctrineDbalContentGraphSchemaBuilder
private const DEFAULT_TEXT_COLLATION = 'utf8mb4_unicode_520_ci';

public function __construct(
private readonly ContentGraphTableNames $contentGraphTableNames
private readonly ContentGraphTableNames $tableNames
) {
}

Expand All @@ -28,13 +29,14 @@ public function buildSchema(AbstractSchemaManager $schemaManager): Schema
$this->createNodeTable(),
$this->createHierarchyRelationTable(),
$this->createReferenceRelationTable(),
$this->createDimensionSpacePointsTable()
$this->createDimensionSpacePointsTable(),
$this->createWorkspaceTable(),
]);
}

private function createNodeTable(): Table
{
$table = new Table($this->contentGraphTableNames->node(), [
$table = new Table($this->tableNames->node(), [
DbalSchemaFactory::columnForNodeAnchorPoint('relationanchorpoint')->setAutoincrement(true),
DbalSchemaFactory::columnForNodeAggregateId('nodeaggregateid')->setNotnull(false),
DbalSchemaFactory::columnForDimensionSpacePointHash('origindimensionspacepointhash')->setNotnull(false),
Expand All @@ -56,7 +58,7 @@ private function createNodeTable(): Table

private function createHierarchyRelationTable(): Table
{
$table = new Table($this->contentGraphTableNames->hierarchyRelation(), [
$table = new Table($this->tableNames->hierarchyRelation(), [
(new Column('position', Type::getType(Types::INTEGER)))->setNotnull(true),
DbalSchemaFactory::columnForContentStreamId('contentstreamid')->setNotnull(true),
DbalSchemaFactory::columnForDimensionSpacePointHash('dimensionspacepointhash')->setNotnull(true),
Expand All @@ -75,7 +77,7 @@ private function createHierarchyRelationTable(): Table

private function createDimensionSpacePointsTable(): Table
{
$table = new Table($this->contentGraphTableNames->dimensionSpacePoints(), [
$table = new Table($this->tableNames->dimensionSpacePoints(), [
DbalSchemaFactory::columnForDimensionSpacePointHash('hash')->setNotnull(true),
DbalSchemaFactory::columnForDimensionSpacePoint('dimensionspacepoint')->setNotnull(true)
]);
Expand All @@ -86,7 +88,7 @@ private function createDimensionSpacePointsTable(): Table

private function createReferenceRelationTable(): Table
{
$table = new Table($this->contentGraphTableNames->referenceRelation(), [
$table = new Table($this->tableNames->referenceRelation(), [
(new Column('name', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setCustomSchemaOption('charset', 'ascii')->setCustomSchemaOption('collation', 'ascii_general_ci'),
(new Column('position', Type::getType(Types::INTEGER)))->setNotnull(true),
DbalSchemaFactory::columnForNodeAnchorPoint('nodeanchorpoint'),
Expand All @@ -97,4 +99,16 @@ private function createReferenceRelationTable(): Table
return $table
->setPrimaryKey(['name', 'position', 'nodeanchorpoint']);
}

private function createWorkspaceTable(): Table
{
$workspaceTable = new Table($this->tableNames->workspace(), [
DbalSchemaFactory::columnForWorkspaceName('workspacename')->setNotnull(true),
DbalSchemaFactory::columnForWorkspaceName('baseworkspacename')->setNotnull(false),
DbalSchemaFactory::columnForContentStreamId('currentcontentstreamid')->setNotNull(true),
(new Column('status', Type::getType(Types::BINARY)))->setLength(20)->setNotnull(false),
]);

return $workspaceTable->setPrimaryKey(['workspacename']);
}
}
Loading
Loading