From ef2d4591f83f3d9934415901b487c168713a3701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mu=CC=88ller?= Date: Wed, 16 Oct 2024 22:33:01 +0200 Subject: [PATCH] BUGFIX: Avoid live events in non live content stream --- .../Feature/WorkspaceCommandHandler.php | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php b/Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php index 3789512c04d..b898cd1c1bf 100644 --- a/Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php +++ b/Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php @@ -74,7 +74,9 @@ use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceHasNoBaseWorkspaceName; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceDescription; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceTitle; use Neos\EventStore\EventStoreInterface; use Neos\EventStore\Exception\ConcurrencyException; use Neos\EventStore\Model\Event\EventType; @@ -509,34 +511,30 @@ private function handlePublishIndividualNodesFromWorkspace( /** @var array $matchingCommands */ /** @var array $remainingCommands */ - // 3) fork a new contentStream, based on the base WS, and apply MATCHING + // 3) fork a temporary workspace, based on the base WS, and apply MATCHING + $matchingWorkspaceName = WorkspaceName::transliterateFromString('tmp' . str_replace('-', '', $command->contentStreamIdForMatchingPart->value)); $commandHandlingDependencies->handle( - ForkContentStream::create( - $command->contentStreamIdForMatchingPart, - $baseWorkspace->currentContentStreamId, + CreateWorkspace::create( + $matchingWorkspaceName, + $baseWorkspace->workspaceName, + WorkspaceTitle::fromString('tmp'), + WorkspaceDescription::fromString(''), + $command->contentStreamIdForMatchingPart ) ); try { // 4) using the new content stream, apply the matching commands - $commandHandlingDependencies->overrideContentStreamId( - $baseWorkspace->workspaceName, - $command->contentStreamIdForMatchingPart, - function () use ($matchingCommands, $commandHandlingDependencies, $baseWorkspace): void { - foreach ($matchingCommands as $matchingCommand) { - if (!($matchingCommand instanceof RebasableToOtherWorkspaceInterface)) { - throw new \RuntimeException( - 'ERROR: The command ' . get_class($matchingCommand) - . ' does not implement ' . RebasableToOtherWorkspaceInterface::class . '; but it should!' - ); - } - - $commandHandlingDependencies->handle($matchingCommand->createCopyForWorkspace( - $baseWorkspace->workspaceName, - )); - } + foreach ($matchingCommands as $matchingCommand) { + if (!($matchingCommand instanceof RebasableToOtherWorkspaceInterface)) { + throw new \RuntimeException( + 'ERROR: The command ' . get_class($matchingCommand) + . ' does not implement ' . RebasableToOtherWorkspaceInterface::class . '; but it should!' + ); } - ); + + $commandHandlingDependencies->handle($matchingCommand->createCopyForWorkspace($matchingWorkspaceName)); + } // 5) take EVENTS(MATCHING) and apply them to base WS. $this->publishContentStream( @@ -553,7 +551,6 @@ function () use ($matchingCommands, $commandHandlingDependencies, $baseWorkspace ) ); - // 7) apply REMAINING commands to the workspace's new content stream $commandHandlingDependencies->overrideContentStreamId( $command->workspaceName, @@ -588,10 +585,10 @@ function () use ($commandHandlingDependencies, $remainingCommands) { throw $exception; } - // 8) to avoid dangling content streams, we need to remove our temporary content stream (whose events - // have already been published) as well as the old one - $commandHandlingDependencies->handle(RemoveContentStream::create( - $command->contentStreamIdForMatchingPart + // 8) to avoid dangling content streams, we need to remove our temporary workspace (whose events + // have already been published) as well as the old content stream + $commandHandlingDependencies->handle(DeleteWorkspace::create( + $matchingWorkspaceName )); $commandHandlingDependencies->handle(RemoveContentStream::create( $oldWorkspaceContentStreamId