Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!!! TASK: Throw exceptions in unnecessary rebase and publish cases #5337

Draft
wants to merge 3 commits into
base: 9.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
use Neos\ContentRepository\Core\CommandHandler\CommandSimulatorFactory;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\EventStore\DecoratedEvent;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\EventStore\EventNormalizer;
use Neos\ContentRepository\Core\EventStore\Events;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Feature\Common\PublishableToWorkspaceInterface;
use Neos\ContentRepository\Core\Feature\ContentStreamClosing\Event\ContentStreamWasClosed;
use Neos\ContentRepository\Core\Feature\ContentStreamClosing\Event\ContentStreamWasReopened;
use Neos\ContentRepository\Core\Feature\ContentStreamForking\Event\ContentStreamWasForked;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateRootWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Event\RootWorkspaceWasCreated;
Expand All @@ -49,6 +47,7 @@
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPartiallyDiscarded;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPartiallyPublished;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPublished;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Exception\NoChangesException;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Command\RebaseWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Dto\RebaseErrorHandlingStrategy;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Event\WorkspaceWasRebased;
Expand All @@ -62,7 +61,6 @@
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceStatus;
use Neos\EventStore\EventStoreInterface;
use Neos\EventStore\Model\Event\EventType;
use Neos\EventStore\Model\Event\SequenceNumber;
use Neos\EventStore\Model\Event\Version;
use Neos\EventStore\Model\EventStream\EventStreamInterface;
Expand Down Expand Up @@ -180,8 +178,7 @@ private function handlePublishWorkspace(
$workspace = $this->requireWorkspace($command->workspaceName, $commandHandlingDependencies);
$baseWorkspace = $this->requireBaseWorkspace($workspace, $commandHandlingDependencies);
if (!$workspace->hasPublishableChanges()) {
// no-op
return;
throw NoChangesException::inWorkspaceToPublish($command->workspaceName);
}

if (!$commandHandlingDependencies->contentStreamExists($workspace->currentContentStreamId)) {
Expand Down Expand Up @@ -275,33 +272,6 @@ static function ($handle) use ($rebaseableCommands): void {
yield $this->removeContentStream($workspace->currentContentStreamId, $commandHandlingDependencies);
}

private function rebaseWorkspaceWithoutChanges(
Workspace $workspace,
Workspace $baseWorkspace,
ContentStreamId $newContentStreamId,
CommandHandlingDependencies $commandHandlingDependencies,
): \Generator {
yield $this->forkContentStream(
$newContentStreamId,
$baseWorkspace->currentContentStreamId,
$commandHandlingDependencies
);

yield new EventsToPublish(
WorkspaceEventStreamName::fromWorkspaceName($workspace->workspaceName)->getEventStreamName(),
Events::with(
new WorkspaceWasRebased(
$workspace->workspaceName,
$newContentStreamId,
$workspace->currentContentStreamId,
),
),
ExpectedVersion::ANY()
);

yield $this->removeContentStream($workspace->currentContentStreamId, $commandHandlingDependencies);
}

/**
* Copy all events from the passed event stream which implement the {@see PublishableToOtherContentStreamsInterface}
*/
Expand Down Expand Up @@ -345,25 +315,19 @@ private function handleRebaseWorkspace(
&& $command->rebaseErrorHandlingStrategy !== RebaseErrorHandlingStrategy::STRATEGY_FORCE
) {
// no-op if workspace is not outdated and not forcing it
// TODO throw here too?
return;
}

if (!$workspace->hasPublishableChanges()) {
NoChangesException::noChangesToRebase($command->workspaceName);
}

yield $this->closeContentStream(
$workspace->currentContentStreamId,
$commandHandlingDependencies
);

if (!$workspace->hasPublishableChanges()) {
// if we have no changes in the workspace we can fork from the base directly
yield from $this->rebaseWorkspaceWithoutChanges(
$workspace,
$baseWorkspace,
$command->rebasedContentStreamId,
$commandHandlingDependencies
);
return;
}

$rebaseableCommands = RebaseableCommands::extractFromEventStream(
$this->eventStore->load(
ContentStreamEventStreamName::fromContentStreamId($workspace->currentContentStreamId)
Expand Down Expand Up @@ -435,9 +399,11 @@ private function handlePublishIndividualNodesFromWorkspace(
): \Generator {
$workspace = $this->requireWorkspace($command->workspaceName, $commandHandlingDependencies);
$baseWorkspace = $this->requireBaseWorkspace($workspace, $commandHandlingDependencies);
if ($command->nodesToPublish->isEmpty() || !$workspace->hasPublishableChanges()) {
// noop
return;
if ($command->nodesToPublish->isEmpty()) {
throw NoChangesException::nothingSelectedForPublish($command->workspaceName);
}
if (!$workspace->hasPublishableChanges()) {
throw NoChangesException::inWorkspaceToPublish($command->workspaceName);
}

// todo check that fetching workspace throws if there is no content stream id for it
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the Neos.ContentRepository package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

declare(strict_types=1);

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

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

/**
* @api thrown as part of command handling in case of empty publish and rebase operations
*/
class NoChangesException extends \RuntimeException
{
public static function inWorkspaceToPublish(WorkspaceName $workspaceName): self
{
return new self(sprintf('Cannot publish workspace "%s" without any changes', $workspaceName->value), 1730463156);
}

public static function nothingSelectedForPublish(WorkspaceName $workspaceName): self
{
return new self(sprintf('Cannot publish workspace "%s" because no changes were selected.', $workspaceName->value), 1730463510);
}

public static function noChangesToRebase(WorkspaceName $workspaceName): self
{
return new self(sprintf('Cannot rebase workspace "%s" because it has no changes.', $workspaceName->value), 1730463693);
}
}
Loading