Skip to content

Commit

Permalink
BUGFIX: Avoid live events in non live content stream
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsunet committed Oct 19, 2024
1 parent 1f8d400 commit 3dd9069
Showing 1 changed file with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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;
Expand Down Expand Up @@ -470,34 +472,30 @@ private function handlePublishIndividualNodesFromWorkspace(
/** @var array<int,RebasableToOtherWorkspaceInterface&CommandInterface> $matchingCommands */
/** @var array<int,RebasableToOtherWorkspaceInterface&CommandInterface> $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(

Check failure on line 478 in Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php

View workflow job for this annotation

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

Static method Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateWorkspace::create() invoked with 5 parameters, 3 required.

Check failure on line 478 in Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php

View workflow job for this annotation

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

Static method Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateWorkspace::create() invoked with 5 parameters, 3 required.
$matchingWorkspaceName,
$baseWorkspace->workspaceName,
WorkspaceTitle::fromString('tmp'),

Check failure on line 481 in Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php

View workflow job for this annotation

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

Call to static method fromString() on an unknown class Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceTitle.

Check failure on line 481 in Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php

View workflow job for this annotation

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

Call to static method fromString() on an unknown class Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceTitle.
WorkspaceDescription::fromString(''),

Check failure on line 482 in Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php

View workflow job for this annotation

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

Call to static method fromString() on an unknown class Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceDescription.

Check failure on line 482 in Neos.ContentRepository.Core/Classes/Feature/WorkspaceCommandHandler.php

View workflow job for this annotation

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

Call to static method fromString() on an unknown class Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceDescription.
$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(
Expand All @@ -514,7 +512,6 @@ function () use ($matchingCommands, $commandHandlingDependencies, $baseWorkspace
)
);


// 7) apply REMAINING commands to the workspace's new content stream
$commandHandlingDependencies->overrideContentStreamId(
$command->workspaceName,
Expand Down Expand Up @@ -549,10 +546,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
Expand Down

0 comments on commit 3dd9069

Please sign in to comment.