diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentRepositoryReadModelAdapter.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentRepositoryReadModelAdapter.php index 05bd545d25a..9fad838826b 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentRepositoryReadModelAdapter.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentRepositoryReadModelAdapter.php @@ -30,6 +30,8 @@ use Neos\ContentRepository\Core\SharedModel\Workspace\Workspaces; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceStatus; use Neos\EventStore\Model\Event\Version; +use Neos\EventStore\Model\EventStream\ExpectedVersion; +use Neos\EventStore\Model\EventStream\MaybeVersion; /** * @internal only used inside the @@ -55,11 +57,11 @@ public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace { $workspaceByNameStatement = <<tableNames->workspace()} ws JOIN {$this->tableNames->contentStream()} cs ON cs.id = ws.currentcontentstreamid - LEFT JOIN {$this->tableNames->contentStream()} scs ON cs.sourceContentStreamId = scs.id + LEFT JOIN {$this->tableNames->contentStream()} scs ON scs.id = cs.sourceContentStreamId WHERE ws.name = :workspaceName LIMIT 1 @@ -81,11 +83,11 @@ public function findWorkspaces(): Workspaces { $workspacesStatement = <<tableNames->workspace()} ws JOIN {$this->tableNames->contentStream()} cs ON cs.id = ws.currentcontentstreamid - LEFT JOIN {$this->tableNames->contentStream()} scs ON cs.sourceContentStreamId = scs.id + LEFT JOIN {$this->tableNames->contentStream()} scs ON scs.id = cs.sourceContentStreamId SQL; try { $rows = $this->dbal->fetchAllAssociative($workspacesStatement); @@ -140,16 +142,21 @@ public function findContentStreams(): ContentStreams */ private static function workspaceFromDatabaseRow(array $row): Workspace { - if ($row['sourceVersion'] === null) { - $status = WorkspaceStatus::UP_TO_DATE; - } elseif ($row['sourceVersion'] > $row['lastSourceVersion']) { - $status = WorkspaceStatus::OUTDATED; - } else { - $status = WorkspaceStatus::UP_TO_DATE; + $baseWorkspaceName = $row['baseWorkspaceName'] !== null ? WorkspaceName::fromString($row['baseWorkspaceName']) : null; + + $status = WorkspaceStatus::UP_TO_DATE; + if ($baseWorkspaceName !== null) { + // root workspaces can never be out of date and dont have a source content stream + $sourceVersion = MaybeVersion::fromVersionOrNull(Version::fromInteger($row['sourceVersion'])); + $expectedSourceVersion = ExpectedVersion::fromVersion(Version::fromInteger($row['expectedSourceVersion'])); + + if (!$expectedSourceVersion->isSatisfiedBy($sourceVersion)) { + $status = WorkspaceStatus::OUTDATED; + } } return new Workspace( WorkspaceName::fromString($row['name']), - isset($row['baseWorkspaceName']) ? WorkspaceName::fromString($row['baseWorkspaceName']) : null, + $baseWorkspaceName, ContentStreamId::fromString($row['currentContentStreamId']), $status, ); diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphSchemaBuilder.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphSchemaBuilder.php index 08ca2f8919a..0ce0ee51e2f 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphSchemaBuilder.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphSchemaBuilder.php @@ -126,10 +126,10 @@ private function createContentStreamTable(): Table DbalSchemaFactory::columnForContentStreamId('id')->setNotnull(true), (new Column('version', Type::getType(Types::INTEGER)))->setNotnull(true), DbalSchemaFactory::columnForContentStreamId('sourceContentStreamId')->setNotnull(false), + (new Column('sourceContentStreamVersion', Type::getType(Types::INTEGER)))->setNotnull(false), // Should become a DB ENUM (unclear how to configure with DBAL) or int (latter needs adaption to code) (new Column('status', Type::getType(Types::BINARY)))->setLength(20)->setNotnull(true), (new Column('removed', Type::getType(Types::BOOLEAN)))->setDefault(false)->setNotnull(false), - (new Column('sourceVersion', Type::getType(Types::INTEGER)))->setNotnull(false), ]); } diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Projection/Feature/ContentStream.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Projection/Feature/ContentStream.php index 8ee20873714..10a4392aca1 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Projection/Feature/ContentStream.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Projection/Feature/ContentStream.php @@ -19,9 +19,9 @@ private function createContentStream(ContentStreamId $contentStreamId, ContentSt { $this->dbal->insert($this->tableNames->contentStream(), [ 'id' => $contentStreamId->value, - 'sourceContentStreamId' => $sourceContentStreamId?->value, 'version' => 0, - 'sourceVersion' => $sourceVersion?->value, + 'sourceContentStreamId' => $sourceContentStreamId?->value, + 'sourceContentStreamVersion' => $sourceVersion?->value, 'status' => $status->value, ]); }