Skip to content

Commit

Permalink
TASK: Introduce BaseWorkspaceUnchangedException to avoid no-op for Ch…
Browse files Browse the repository at this point in the history
…angeBaseWorkspace
  • Loading branch information
mhsdesign committed Jan 22, 2025
1 parent 6d5067c commit a134031
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ Feature: Change base workspace works :D what else
| baseWorkspaceName | "live" |
| newContentStreamId | "shared-cs-identifier" |

Scenario: Change base workspace is a no-op if the base already matches
When the command ChangeBaseWorkspace is executed with payload:
Scenario: Change base workspace is skipped (via exception) if the base already matches
When the command ChangeBaseWorkspace is executed with payload and exceptions are caught:
| Key | Value |
| workspaceName | "user-test" |
| baseWorkspaceName | "live" |
Then the last command should have thrown an exception of type "BaseWorkspaceUnchangedException" with code 1737534132 and message:
"""
Skipped changing the base workspace to "live" from workspace "user-test" because its already set.
"""

Then I expect exactly 1 event to be published on stream "Workspace:user-test"
And event at index 0 is of type "WorkspaceWasCreated" with payload:
Expand All @@ -65,38 +69,6 @@ Feature: Change base workspace works :D what else
Given I am in workspace "user-test" and dimension space point {}
Then I expect node aggregate identifier "nody-mc-nodeface" to lead to node user-cs-identifier;nody-mc-nodeface;{}

Scenario: Change base workspace is a no-op if the base already matches but the workspace is outdated
When the command CreateNodeAggregateWithNode is executed with payload:
| Key | Value |
| workspaceName | "live" |
| nodeAggregateId | "holy-nody" |
| nodeTypeName | "Neos.ContentRepository.Testing:Content" |
| originDimensionSpacePoint | {} |
| parentNodeAggregateId | "lady-eleonode-rootford" |
| initialPropertyValues | {"text": "New node in live"} |

Then workspaces user-test has status OUTDATED

When the command ChangeBaseWorkspace is executed with payload:
| Key | Value |
| workspaceName | "user-test" |
| baseWorkspaceName | "live" |

Then workspaces user-test has status OUTDATED

Then I expect exactly 1 event to be published on stream "Workspace:user-test"
And event at index 0 is of type "WorkspaceWasCreated" with payload:
| Key | Expected |
| workspaceName | "user-test" |
| baseWorkspaceName | "live" |
| newContentStreamId | "user-cs-identifier" |

Given I am in workspace "user-test" and dimension space point {}
Then I expect node aggregate identifier "holy-nody" to lead to no node

Given I am in workspace "live" and dimension space point {}
Then I expect node aggregate identifier "holy-nody" to lead to node cs-identifier;holy-nody;{}

Scenario: Change base workspace if user has no changes and is up to date with new base
When the command ChangeBaseWorkspace is executed with payload:
| Key | Value |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
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 @@ -716,8 +717,7 @@ private function handleChangeBaseWorkspace(
$this->requireContentStreamToNotBeClosed($workspace->currentContentStreamId, $commandHandlingDependencies);

if ($currentBaseWorkspace->workspaceName->equals($command->baseWorkspaceName)) {
// no-op
return;
throw BaseWorkspaceUnchangedException::becauseTheAttemptedBaseWorkspaceIsTheBase($command->baseWorkspaceName, $workspace->workspaceName);
}

$this->requireEmptyWorkspace($workspace);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Neos\ContentRepository\Core\Feature\WorkspaceModification\Exception;

use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
* Exception when attempting to change the base workspace to the currently set base workspace
*
* The case is not handled gracefully with a no-op as there would be no traces (emitted events) of the handled command.
* This exception denoting the operation is obsolete hardens the interaction.
*
* @api
*/
final class BaseWorkspaceUnchangedException extends \RuntimeException
{
public static function becauseTheAttemptedBaseWorkspaceIsTheBase(WorkspaceName $attemptedBaseWorkspaceName, WorkspaceName $workspaceName): self
{
return new self(sprintf('Skipped changing the base workspace to "%s" from workspace "%s" because its already set.', $attemptedBaseWorkspaceName->value, $workspaceName->value), 1737534132);
}
}

0 comments on commit a134031

Please sign in to comment.