Skip to content

Commit

Permalink
TASK: Combine BaseWorkspaceUnchangedException with `WorkspaceComman…
Browse files Browse the repository at this point in the history
…dSkipped`
  • Loading branch information
mhsdesign committed Jan 27, 2025
1 parent faad1fc commit 6bd31ee
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Feature: Change base workspace works :D what else
| Key | Value |
| workspaceName | "user-test" |
| baseWorkspaceName | "live" |
Then the last command should have thrown an exception of type "BaseWorkspaceUnchangedException" with code 1737534132 and message:
Then the last command should have thrown an exception of type "WorkspaceCommandSkipped" with code 1737534132 and message:
"""
Skipped changing the base workspace to "live" from workspace "user-test" because its already set.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Event\WorkspaceBaseWorkspaceWasChanged;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Event\WorkspaceWasRemoved;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Exception\BaseWorkspaceEqualsWorkspaceException;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Exception\BaseWorkspaceUnchangedException;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Exception\CircularRelationBetweenWorkspacesException;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Exception\WorkspaceIsNotEmptyException;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Command\DiscardIndividualNodesFromWorkspace;
Expand Down Expand Up @@ -720,7 +719,7 @@ private function handleChangeBaseWorkspace(
$this->requireContentStreamToNotBeClosed($workspace->currentContentStreamId, $commandHandlingDependencies);

if ($currentBaseWorkspace->workspaceName->equals($command->baseWorkspaceName)) {
throw BaseWorkspaceUnchangedException::becauseTheAttemptedBaseWorkspaceIsTheBase($command->baseWorkspaceName, $workspace->workspaceName);
throw WorkspaceCommandSkipped::becauseTheBaseWorkspaceIsUnchanged($command->baseWorkspaceName, $command->workspaceName);
}

$this->requireEmptyWorkspace($workspace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
*
* Command skipped if there are no (selected) publishable changes.
*
* The case is not handled gracefully with a no-op as there would be no traces (emitted events) of the handled command,
* and the original content stream id is kept. This exception denoting the operation is obsolete hardens the interactions.
*
* To avoid this exception being thrown into the outer world it should be caught and logged or the case were its
* likely that the operation might be a noop can easily be determined beforehand via {@see Workspace::hasPublishableChanges()}:
*
Expand All @@ -39,6 +36,16 @@
*
* Command skipped if the workspace is not outdated.
*
* *Workspace base change*
*
* Command skipped when attempting to change the base workspace to the currently set base workspace.
*
* Note:
*
* The case is not handled gracefully with a no-op as there would be no traces (emitted events) of the handled command,
* and the original content stream id is kept (for publish operations).
* This exception denoting the operation is obsolete should harden the interaction and make behaviour more explicit.
*
* @api thrown as part of command handling in case of a workspace no-op
*/
class WorkspaceCommandSkipped extends \RuntimeException
Expand All @@ -53,13 +60,18 @@ public static function becauseWorkspaceToDiscardIsEmpty(WorkspaceName $workspace
return new self(sprintf('Skipped discard workspace "%s" without any publishable changes.', $workspaceName->value), 1730463156);
}

public static function becauseFilterDidNotMatch(WorkspaceName $workspaceName, NodeAggregateIds $selectedNodeAggregateIds): self
{
return new self(sprintf('No nodes matched in workspace "%s" the filter %s.', $workspaceName->value, join(',', $selectedNodeAggregateIds->toStringArray())), 1737477674);
}

public static function becauseWorkspaceToRebaseIsNotOutdated(WorkspaceName $workspaceName): self
{
return new self(sprintf('Skipped rebase workspace "%s" because it is not outdated.', $workspaceName->value), 1730463693);
}

public static function becauseFilterDidNotMatch(WorkspaceName $workspaceName, NodeAggregateIds $selectedNodeAggregateIds): self
public static function becauseTheBaseWorkspaceIsUnchanged(WorkspaceName $baseWorkspaceName, WorkspaceName $workspaceName): self
{
return new self(sprintf('No nodes matched in workspace "%s" the filter %s.', $workspaceName->value, join(',', $selectedNodeAggregateIds->toStringArray())), 1737477674);
return new self(sprintf('Skipped changing the base workspace to "%s" from workspace "%s" because its already set.', $baseWorkspaceName->value, $workspaceName->value), 1737534132);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Neos\ContentRepository\Core\Feature\WorkspaceCommandSkipped;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Command\ChangeBaseWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Exception\BaseWorkspaceEqualsWorkspaceException;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Exception\BaseWorkspaceUnchangedException;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Exception\CircularRelationBetweenWorkspacesException;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Exception\WorkspaceIsNotEmptyException;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Command\DiscardIndividualNodesFromWorkspace;
Expand Down Expand Up @@ -244,7 +243,7 @@ public function discardChangesInDocument(ContentRepositoryId $contentRepositoryI
}

/**
* @throws BaseWorkspaceUnchangedException|WorkspaceIsNotEmptyException|BaseWorkspaceEqualsWorkspaceException|CircularRelationBetweenWorkspacesException
* @throws WorkspaceCommandSkipped|WorkspaceIsNotEmptyException|BaseWorkspaceEqualsWorkspaceException|CircularRelationBetweenWorkspacesException
*/
public function changeBaseWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceName $newBaseWorkspaceName): void
{
Expand Down

0 comments on commit 6bd31ee

Please sign in to comment.