-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`
- Loading branch information
Showing
6 changed files
with
173 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Classes/Application/PublishChangesInDocument/PublishChangesInDocumentCommandHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Classes/Application/PublishChangesInSite/PublishChangesInSiteCommandHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters