Skip to content

Commit

Permalink
TASK: Add command handlers for all Publish-related commands
Browse files Browse the repository at this point in the history
This includes the following tasks;
- Move `PublishChangesInDocument` ->
`PublishChangesInDocument\PublishChangesInDocumentCommand`
- Create `PublishChangesInDocumentCommandHandler`
- Move `PublishChangesInSite` ->
`PublishChangesInSite\PublishChangesInSiteCommand`
- Create `PublishChangesInSiteCommandHandler`
  • Loading branch information
grebaldi committed Apr 22, 2024
1 parent b6a420a commit c31231f
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@

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;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Neos.Neos 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\Neos\Ui\Application\PublishChangesInDocument;

use Neos\ContentRepository\Core\SharedModel\Exception\NodeAggregateCurrentlyDoesNotExist;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Workspace\WorkspaceProvider;
use Neos\Neos\Ui\Application\Shared\PublishSucceeded;

/**
* The application layer level command handler to perform publication of
* all changes recorded for a given document
*
* @internal for communication within the Neos UI only
*/
#[Flow\Scope("singleton")]
final class PublishChangesInDocumentCommandHandler
{
#[Flow\Inject]
protected WorkspaceProvider $workspaceProvider;

/**
* @throws NodeAggregateCurrentlyDoesNotExist
*/
public function handle(PublishChangesInDocumentCommand $command): PublishSucceeded
{
try {
$workspace = $this->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
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@

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;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Neos.Neos.Ui 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\Neos\Ui\Application\PublishChangesInSite;

use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Workspace\WorkspaceProvider;
use Neos\Neos\Ui\Application\Shared\PublishSucceeded;

/**
* The application layer level command handler to perform publication of
* all changes recorded for a given site
*
* @internal for communication within the Neos UI only
*/
#[Flow\Scope("singleton")]
final class PublishChangesInSiteCommandHandler
{
#[Flow\Inject]
protected WorkspaceProvider $workspaceProvider;

public function handle(PublishChangesInSiteCommand $command): PublishSucceeded
{
$workspace = $this->workspaceProvider->provideForWorkspaceName(
$command->contentRepositoryId,
$command->workspaceName
);
$publishingResult = $workspace->publishChangesInSite($command->siteId);

return new PublishSucceeded(
numberOfAffectedChanges: $publishingResult->numberOfPublishedChanges,
baseWorkspaceName: $workspace->getCurrentBaseWorkspaceName()?->value
);
}
}
37 changes: 37 additions & 0 deletions Classes/Application/Shared/PublishSucceeded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Neos.Neos.Ui 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\Neos\Ui\Application\Shared;

use Neos\Flow\Annotations as Flow;

/**
* @internal for communication within the Neos UI only
*/
#[Flow\Proxy(false)]
final readonly class PublishSucceeded implements \JsonSerializable
{
public function __construct(
public int $numberOfAffectedChanges,
public ?string $baseWorkspaceName
) {
}

public function jsonSerialize(): mixed
{
return [
'success' => get_object_vars($this)
];
}
}
62 changes: 25 additions & 37 deletions Classes/Controller/BackendServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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' => [
Expand Down

0 comments on commit c31231f

Please sign in to comment.