From 4f503a2337ac52da732c499c525092a130a1b2f3 Mon Sep 17 00:00:00 2001 From: Wilhelm Behncke Date: Mon, 22 Apr 2024 13:01:36 +0200 Subject: [PATCH] TASK: Add command handlers for all Publish-related commands This includes the following tasks; - Move `PublishChangesInDocument` -> `PublishChangesInDocument\PublishChangesInDocumentCommand` - Create `PublishChangesInDocumentCommandHandler` - Move `PublishChangesInSite` -> `PublishChangesInSite\PublishChangesInSiteCommand` - Create `PublishChangesInSiteCommandHandler` --- .../PublishChangesInDocumentCommand.php} | 7 ++- ...PublishChangesInDocumentCommandHandler.php | 57 +++++++++++++++++ .../PublishChangesInSiteCommand.php} | 7 ++- .../PublishChangesInSiteCommandHandler.php | 46 ++++++++++++++ .../Application/Shared/PublishSucceeded.php | 37 +++++++++++ .../Controller/BackendServiceController.php | 62 ++++++++----------- 6 files changed, 173 insertions(+), 43 deletions(-) rename Classes/Application/{PublishChangesInDocument.php => PublishChangesInDocument/PublishChangesInDocumentCommand.php} (88%) create mode 100644 Classes/Application/PublishChangesInDocument/PublishChangesInDocumentCommandHandler.php rename Classes/Application/{PublishChangesInSite.php => PublishChangesInSite/PublishChangesInSiteCommand.php} (89%) create mode 100644 Classes/Application/PublishChangesInSite/PublishChangesInSiteCommandHandler.php create mode 100644 Classes/Application/Shared/PublishSucceeded.php diff --git a/Classes/Application/PublishChangesInDocument.php b/Classes/Application/PublishChangesInDocument/PublishChangesInDocumentCommand.php similarity index 88% rename from Classes/Application/PublishChangesInDocument.php rename to Classes/Application/PublishChangesInDocument/PublishChangesInDocumentCommand.php index 85069b6606..87d9762511 100644 --- a/Classes/Application/PublishChangesInDocument.php +++ b/Classes/Application/PublishChangesInDocument/PublishChangesInDocumentCommand.php @@ -12,7 +12,7 @@ declare(strict_types=1); -namespace Neos\Neos\Ui\Application; +namespace Neos\Neos\Ui\Application\PublishChangesInDocument; use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; @@ -20,12 +20,13 @@ use Neos\Flow\Annotations as Flow; /** - * The application layer level command DTO to communicate publication of all changes recorded for a given document + * The application layer level command DTO to communicate publication of + * all changes recorded for a given document * * @internal for communication within the Neos UI only */ #[Flow\Proxy(false)] -final readonly class PublishChangesInDocument +final readonly class PublishChangesInDocumentCommand { public function __construct( public ContentRepositoryId $contentRepositoryId, diff --git a/Classes/Application/PublishChangesInDocument/PublishChangesInDocumentCommandHandler.php b/Classes/Application/PublishChangesInDocument/PublishChangesInDocumentCommandHandler.php new file mode 100644 index 0000000000..3b7393c692 --- /dev/null +++ b/Classes/Application/PublishChangesInDocument/PublishChangesInDocumentCommandHandler.php @@ -0,0 +1,57 @@ +workspaceProvider->provideForWorkspaceName( + $command->contentRepositoryId, + $command->workspaceName + ); + $publishingResult = $workspace->publishChangesInDocument($command->documentId); + + return new PublishSucceeded( + numberOfAffectedChanges: $publishingResult->numberOfPublishedChanges, + baseWorkspaceName: $workspace->getCurrentBaseWorkspaceName()?->value + ); + } catch (NodeAggregateCurrentlyDoesNotExist $e) { + throw new NodeAggregateCurrentlyDoesNotExist( + 'Node could not be published, probably because of a missing parentNode. Please check that the parentNode has been published.', + 1682762156 + ); + } + } +} diff --git a/Classes/Application/PublishChangesInSite.php b/Classes/Application/PublishChangesInSite/PublishChangesInSiteCommand.php similarity index 89% rename from Classes/Application/PublishChangesInSite.php rename to Classes/Application/PublishChangesInSite/PublishChangesInSiteCommand.php index f645520cf4..0f5b82abde 100644 --- a/Classes/Application/PublishChangesInSite.php +++ b/Classes/Application/PublishChangesInSite/PublishChangesInSiteCommand.php @@ -12,7 +12,7 @@ declare(strict_types=1); -namespace Neos\Neos\Ui\Application; +namespace Neos\Neos\Ui\Application\PublishChangesInSite; use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; @@ -20,12 +20,13 @@ use Neos\Flow\Annotations as Flow; /** - * The application layer level command DTO to communicate publication of all changes recorded for a given site + * The application layer level command DTO to communicate publication of + * all changes recorded for a given site * * @internal for communication within the Neos UI only */ #[Flow\Proxy(false)] -final readonly class PublishChangesInSite +final readonly class PublishChangesInSiteCommand { public function __construct( public ContentRepositoryId $contentRepositoryId, diff --git a/Classes/Application/PublishChangesInSite/PublishChangesInSiteCommandHandler.php b/Classes/Application/PublishChangesInSite/PublishChangesInSiteCommandHandler.php new file mode 100644 index 0000000000..63710ca355 --- /dev/null +++ b/Classes/Application/PublishChangesInSite/PublishChangesInSiteCommandHandler.php @@ -0,0 +1,46 @@ +workspaceProvider->provideForWorkspaceName( + $command->contentRepositoryId, + $command->workspaceName + ); + $publishingResult = $workspace->publishChangesInSite($command->siteId); + + return new PublishSucceeded( + numberOfAffectedChanges: $publishingResult->numberOfPublishedChanges, + baseWorkspaceName: $workspace->getCurrentBaseWorkspaceName()?->value + ); + } +} diff --git a/Classes/Application/Shared/PublishSucceeded.php b/Classes/Application/Shared/PublishSucceeded.php new file mode 100644 index 0000000000..dd20220b2a --- /dev/null +++ b/Classes/Application/Shared/PublishSucceeded.php @@ -0,0 +1,37 @@ + get_object_vars($this) + ]; + } +} diff --git a/Classes/Controller/BackendServiceController.php b/Classes/Controller/BackendServiceController.php index b48698b088..a00da6f5c0 100644 --- a/Classes/Controller/BackendServiceController.php +++ b/Classes/Controller/BackendServiceController.php @@ -18,7 +18,6 @@ use Neos\ContentRepository\Core\Feature\WorkspaceModification\Exception\WorkspaceIsNotEmptyException; use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Dto\RebaseErrorHandlingStrategy; use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints; -use Neos\ContentRepository\Core\SharedModel\Exception\NodeAggregateCurrentlyDoesNotExist; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Eel\FlowQuery\FlowQuery; @@ -40,8 +39,10 @@ use Neos\Neos\Ui\Application\DiscardAllChanges; use Neos\Neos\Ui\Application\DiscardChangesInDocument; use Neos\Neos\Ui\Application\DiscardChangesInSite; -use Neos\Neos\Ui\Application\PublishChangesInDocument; -use Neos\Neos\Ui\Application\PublishChangesInSite; +use Neos\Neos\Ui\Application\PublishChangesInDocument\PublishChangesInDocumentCommand; +use Neos\Neos\Ui\Application\PublishChangesInDocument\PublishChangesInDocumentCommandHandler; +use Neos\Neos\Ui\Application\PublishChangesInSite\PublishChangesInSiteCommand; +use Neos\Neos\Ui\Application\PublishChangesInSite\PublishChangesInSiteCommandHandler; use Neos\Neos\Ui\Application\ReloadNodes\ReloadNodesQuery; use Neos\Neos\Ui\Application\ReloadNodes\ReloadNodesQueryHandler; use Neos\Neos\Ui\Application\Shared\ConflictsOccurred; @@ -138,6 +139,18 @@ class BackendServiceController extends ActionController */ protected $workspaceProvider; + /** + * @Flow\Inject + * @var PublishChangesInSiteCommandHandler + */ + protected $publishChangesInSiteCommandHandler; + + /** + * @Flow\Inject + * @var PublishChangesInDocumentCommandHandler + */ + protected $publishChangesInDocumentCommandHandler; + /** * @Flow\Inject * @var SyncWorkspaceCommandHandler @@ -202,20 +215,12 @@ public function publishChangesInSiteAction(array $command): void $command['siteId'], $contentRepositoryId )->nodeAggregateId->value; - $command = PublishChangesInSite::fromArray($command); - $workspace = $this->workspaceProvider->provideForWorkspaceName( - $command->contentRepositoryId, - $command->workspaceName - ); - $publishingResult = $workspace - ->publishChangesInSite($command->siteId); + $command = PublishChangesInSiteCommand::fromArray($command); - $this->view->assign('value', [ - 'success' => [ - 'numberOfAffectedChanges' => $publishingResult->numberOfPublishedChanges, - 'baseWorkspaceName' => $workspace->getCurrentBaseWorkspaceName()?->value - ] - ]); + $result = $this->publishChangesInSiteCommandHandler + ->handle($command); + + $this->view->assign('value', $result); } catch (\Exception $e) { $this->view->assign('value', [ 'error' => [ @@ -243,29 +248,12 @@ public function publishChangesInDocumentAction(array $command): void $command['documentId'], $contentRepositoryId )->nodeAggregateId->value; - $command = PublishChangesInDocument::fromArray($command); + $command = PublishChangesInDocumentCommand::fromArray($command); - $contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId; + $result = $this->publishChangesInDocumentCommandHandler + ->handle($command); - try { - $workspace = $this->workspaceProvider->provideForWorkspaceName( - $command->contentRepositoryId, - $command->workspaceName - ); - $publishingResult = $workspace->publishChangesInDocument($command->documentId); - - $this->view->assign('value', [ - 'success' => [ - 'numberOfAffectedChanges' => $publishingResult->numberOfPublishedChanges, - 'baseWorkspaceName' => $workspace->getCurrentBaseWorkspaceName()?->value - ] - ]); - } catch (NodeAggregateCurrentlyDoesNotExist $e) { - throw new NodeAggregateCurrentlyDoesNotExist( - 'Node could not be published, probably because of a missing parentNode. Please check that the parentNode has been published.', - 1682762156 - ); - } + $this->view->assign('value', $result); } catch (\Exception $e) { $this->view->assign('value', [ 'error' => [