From 1e281bc9076f29b03307fc65f5621303ef8c9722 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 17 Oct 2024 23:33:08 +0200 Subject: [PATCH] TASK: Remove obsolete `REBASE_ERROR` content stream state Via #4965 the status REBASE_ERROR is obsolete. Instead of still using this status on replay we mimic the new logic: > In case of a [rebase error}, reopen the old content stream and remove the newly created Additionally, to not break `findContentStreams` when fetching all content streams we make sure that the streams with `REBASE_ERROR` are transformed to `NO_LONGER_IN_USE` so they can be cleaned up. Related https://github.com/neos/neos-development-collection/issues/5101 --- src/DoctrineDbalContentGraphProjection.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/DoctrineDbalContentGraphProjection.php b/src/DoctrineDbalContentGraphProjection.php index ecd410b..b6567a6 100644 --- a/src/DoctrineDbalContentGraphProjection.php +++ b/src/DoctrineDbalContentGraphProjection.php @@ -125,7 +125,10 @@ public function setUp(): void $this->dbal->getSchemaManager()->tablesExist([$legacyContentStreamTableName]) && !$this->dbal->getSchemaManager()->tablesExist([$this->tableNames->contentStream()]) ) { - $statements[] = 'INSERT INTO ' . $this->tableNames->contentStream() . ' (id, version, sourceContentStreamId, status, removed) SELECT contentStreamId AS id, version, sourceContentStreamId, state AS status, removed FROM ' . $legacyContentStreamTableName; + // special migration regarding content stream table: + // 1.) don't copy removed content streams as they would not be flagged but actually removed + // 2.) transform legacy `REBASE_ERROR` content streams into `NO_LONGER_IN_USE`, as they should be removed and wouldn't exist today as well. (We cannot reopen the content stream that was attempted to be rebased like we would today in the migration here, for that a replay must be executed see whenWorkspaceRebaseFailed) + $statements[] = 'INSERT INTO ' . $this->tableNames->contentStream() . ' (id, version, sourceContentStreamId, status) SELECT contentStreamId AS id, version, sourceContentStreamId, REPLACE(state, \'REBASE_ERROR\', \'NO_LONGER_IN_USE\') AS status FROM ' . $legacyContentStreamTableName . ' WHERE NOT removed = 1'; } // /MIGRATION @@ -733,8 +736,15 @@ private function whenWorkspaceBaseWorkspaceWasChanged(WorkspaceBaseWorkspaceWasC private function whenWorkspaceRebaseFailed(WorkspaceRebaseFailed $event): void { + // legacy handling: + // before https://github.com/neos/neos-development-collection/pull/4965 this event was emitted and set the content stream status to `REBASE_ERROR` + // instead of setting the error state on replay for old events we make it behave like if the rebase had failed today: + // 4.E) In case of a [rebase error}, reopen the old content stream and remove the newly created + // The ContentStreamWasReopened event would be emitted with `IN_USE_BY_WORKSPACE` (because that _must_ be the previous state as a workspace was rebased) + $this->whenContentStreamWasReopened(new ContentStreamWasReopened($event->sourceContentStreamId, ContentStreamStatus::IN_USE_BY_WORKSPACE)); + $this->whenContentStreamWasRemoved(new ContentStreamWasRemoved($event->candidateContentStreamId)); + $this->markWorkspaceAsOutdatedConflict($event->workspaceName); - $this->updateContentStreamStatus($event->candidateContentStreamId, ContentStreamStatus::REBASE_ERROR); } private function whenWorkspaceWasCreated(WorkspaceWasCreated $event): void