diff --git a/Classes/CommandHandler/CommandHandlingDependencies.php b/Classes/CommandHandler/CommandHandlingDependencies.php index 9e726cac..629f5c01 100644 --- a/Classes/CommandHandler/CommandHandlingDependencies.php +++ b/Classes/CommandHandler/CommandHandlingDependencies.php @@ -16,6 +16,7 @@ use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphReadModelInterface; +use Neos\ContentRepository\Core\SharedModel\Exception\ContentStreamDoesNotExistYet; use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace; @@ -48,11 +49,17 @@ public function contentStreamExists(ContentStreamId $contentStreamId): bool return $this->contentGraphReadModel->findContentStreamById($contentStreamId) !== null; } + /** + * @throws ContentStreamDoesNotExistYet if there is no matching content stream + */ public function isContentStreamClosed(ContentStreamId $contentStreamId): bool { $contentStream = $this->contentGraphReadModel->findContentStreamById($contentStreamId); if ($contentStream === null) { - throw new \InvalidArgumentException(sprintf('Failed to find content stream with id "%s"', $contentStreamId->value), 1729863973); + throw new ContentStreamDoesNotExistYet( + 'Content stream "' . $contentStreamId->value . '" does not exist.', + 1521386692 + ); } return $contentStream->isClosed; } diff --git a/Classes/Feature/Common/ConstraintChecks.php b/Classes/Feature/Common/ConstraintChecks.php index 2be9688f..5364907d 100644 --- a/Classes/Feature/Common/ConstraintChecks.php +++ b/Classes/Feature/Common/ConstraintChecks.php @@ -81,14 +81,9 @@ protected function requireContentStream( CommandHandlingDependencies $commandHandlingDependencies ): ContentStreamId { $contentStreamId = $commandHandlingDependencies->getContentGraph($workspaceName)->getContentStreamId(); - if (!$commandHandlingDependencies->contentStreamExists($contentStreamId)) { - throw new ContentStreamDoesNotExistYet( - 'Content stream for "' . $workspaceName->value . '" does not exist yet.', - 1521386692 - ); - } + $closedState = $commandHandlingDependencies->isContentStreamClosed($contentStreamId); - if ($commandHandlingDependencies->isContentStreamClosed($contentStreamId)) { + if ($closedState) { throw new ContentStreamIsClosed( 'Content stream "' . $contentStreamId->value . '" is closed.', 1710260081 diff --git a/Classes/Feature/WorkspaceCommandHandler.php b/Classes/Feature/WorkspaceCommandHandler.php index aafa7ec0..d1675235 100644 --- a/Classes/Feature/WorkspaceCommandHandler.php +++ b/Classes/Feature/WorkspaceCommandHandler.php @@ -195,8 +195,8 @@ private function handlePublishWorkspace( // no-op return; } - $workspaceContentStreamVersion = $this->requireOpenContentStreamVersion($workspace, $commandHandlingDependencies); - $baseWorkspaceContentStreamVersion = $this->requireOpenContentStreamVersion($baseWorkspace, $commandHandlingDependencies); + $workspaceContentStreamVersion = $this->requireOpenContentStreamAndVersion($workspace, $commandHandlingDependencies); + $baseWorkspaceContentStreamVersion = $this->requireOpenContentStreamAndVersion($baseWorkspace, $commandHandlingDependencies); yield $this->closeContentStream( $workspace->currentContentStreamId, @@ -348,11 +348,9 @@ private function handleRebaseWorkspace( ): \Generator { $workspace = $this->requireWorkspace($command->workspaceName, $commandHandlingDependencies); $baseWorkspace = $this->requireBaseWorkspace($workspace, $commandHandlingDependencies); - if (!$commandHandlingDependencies->contentStreamExists($workspace->currentContentStreamId)) { - throw new \RuntimeException('Cannot rebase a workspace with a stateless content stream', 1711718314); - } - $workspaceContentStreamVersion = $this->requireOpenContentStreamVersion($workspace, $commandHandlingDependencies); - $baseWorkspaceContentStreamVersion = $this->requireOpenContentStreamVersion($baseWorkspace, $commandHandlingDependencies); + + $workspaceContentStreamVersion = $this->requireOpenContentStreamAndVersion($workspace, $commandHandlingDependencies); + $baseWorkspaceContentStreamVersion = $this->requireOpenContentStreamAndVersion($baseWorkspace, $commandHandlingDependencies); if ( $workspace->status === WorkspaceStatus::UP_TO_DATE @@ -449,12 +447,8 @@ private function handlePublishIndividualNodesFromWorkspace( return; } - // todo check that fetching workspace throws if there is no content stream id for it - if (!$commandHandlingDependencies->contentStreamExists($workspace->currentContentStreamId)) { - throw new \RuntimeException('Cannot publish nodes on a workspace with a stateless content stream', 1710410114); - } - $workspaceContentStreamVersion = $this->requireOpenContentStreamVersion($workspace, $commandHandlingDependencies); - $baseWorkspaceContentStreamVersion = $this->requireOpenContentStreamVersion($baseWorkspace, $commandHandlingDependencies); + $workspaceContentStreamVersion = $this->requireOpenContentStreamAndVersion($workspace, $commandHandlingDependencies); + $baseWorkspaceContentStreamVersion = $this->requireOpenContentStreamAndVersion($baseWorkspace, $commandHandlingDependencies); yield $this->closeContentStream( $workspace->currentContentStreamId, @@ -582,8 +576,8 @@ private function handleDiscardIndividualNodesFromWorkspace( return; } - $workspaceContentStreamVersion = $this->requireOpenContentStreamVersion($workspace, $commandHandlingDependencies); - $baseWorkspaceContentStreamVersion = $this->requireOpenContentStreamVersion($baseWorkspace, $commandHandlingDependencies); + $workspaceContentStreamVersion = $this->requireOpenContentStreamAndVersion($workspace, $commandHandlingDependencies); + $baseWorkspaceContentStreamVersion = $this->requireOpenContentStreamAndVersion($baseWorkspace, $commandHandlingDependencies); yield $this->closeContentStream( $workspace->currentContentStreamId, @@ -678,8 +672,8 @@ private function handleDiscardWorkspace( return; } - $workspaceContentStreamVersion = $this->requireOpenContentStreamVersion($workspace, $commandHandlingDependencies); - $baseWorkspaceContentStreamVersion = $this->requireOpenContentStreamVersion($baseWorkspace, $commandHandlingDependencies); + $workspaceContentStreamVersion = $this->requireOpenContentStreamAndVersion($workspace, $commandHandlingDependencies); + $baseWorkspaceContentStreamVersion = $this->requireOpenContentStreamAndVersion($baseWorkspace, $commandHandlingDependencies); yield from $this->discardWorkspace( $workspace, @@ -747,7 +741,7 @@ private function handleChangeBaseWorkspace( $newBaseWorkspace = $this->requireWorkspace($command->baseWorkspaceName, $commandHandlingDependencies); $this->requireNonCircularRelationBetweenWorkspaces($workspace, $newBaseWorkspace, $commandHandlingDependencies); - $newBaseWorkspaceContentStreamVersion = $this->requireOpenContentStreamVersion($newBaseWorkspace, $commandHandlingDependencies); + $newBaseWorkspaceContentStreamVersion = $this->requireOpenContentStreamAndVersion($newBaseWorkspace, $commandHandlingDependencies); yield $this->forkContentStream( $command->newContentStreamId, @@ -844,7 +838,7 @@ private function requireWorkspaceToNotExist(WorkspaceName $workspaceName, Comman ), 1715341085); } - private function requireOpenContentStreamVersion(Workspace $workspace, CommandHandlingDependencies $commandHandlingDependencies): Version + private function requireOpenContentStreamAndVersion(Workspace $workspace, CommandHandlingDependencies $commandHandlingDependencies): Version { if ($commandHandlingDependencies->isContentStreamClosed($workspace->currentContentStreamId)) { throw new ContentStreamIsClosed(