Skip to content

Commit 5d4757a

Browse files
Merge pull request #8 from netlogix/bugfix/check-if-nodes-exist
BUGFIX: Don't try to publish non-existing nodes
2 parents 1e7102e + 4492019 commit 5d4757a

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

Classes/Aspect/WorkspaceControllerPublishAspect.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
use Neos\Flow\Http\HttpRequestHandlerInterface;
1111
use Neos\Flow\Persistence\PersistenceManagerInterface;
1212
use Neos\Flow\Utility\Algorithms;
13+
use Neos\Neos\Ui\ContentRepository\Service\NodeService;
1314
use Neos\Neos\Ui\Controller\BackendServiceController;
15+
use Neos\Neos\Ui\Domain\Model\Feedback\Messages\Success;
16+
use Neos\Neos\Ui\Domain\Model\FeedbackCollection;
17+
use Neos\Utility\ObjectAccess;
1418
use Netlogix\Neos\AsyncWorkspaceActions\Domain\Model\Job;
1519
use Netlogix\Neos\AsyncWorkspaceActions\Domain\Repository\JobRepository;
1620
use Netlogix\Neos\AsyncWorkspaceActions\Job\Workspace\Publish;
@@ -47,6 +51,18 @@ class WorkspaceControllerPublishAspect
4751
*/
4852
protected $bootstrap;
4953

54+
/**
55+
* @var NodeService
56+
* @Flow\Inject
57+
*/
58+
protected $nodeService;
59+
60+
/**
61+
* @var FeedbackCollection
62+
* @Flow\Inject
63+
*/
64+
protected $feedbackCollection;
65+
5066
/**
5167
* @var int
5268
* @Flow\InjectConfiguration(path="nodeThreshold")
@@ -64,7 +80,18 @@ public function publish(JoinPointInterface $joinPoint)
6480
$controller = $joinPoint->getProxy();
6581
assert($controller instanceof BackendServiceController);
6682

67-
$nodeContextPaths = $joinPoint->getMethodArgument('nodeContextPaths');
83+
$nodeContextPaths = $this->filterExistingContextPaths($joinPoint->getMethodArgument('nodeContextPaths'));
84+
if (count($nodeContextPaths) === 0) {
85+
$success = new Success();
86+
$success->setMessage('No nodes to publish');
87+
$this->feedbackCollection->add($success);
88+
89+
$view = ObjectAccess::getProperty($controller, 'view', true);
90+
$view->assign('value', $this->feedbackCollection);
91+
92+
return;
93+
}
94+
6895
$requestHandler = $this->bootstrap->getActiveRequestHandler();
6996

7097
if (!($requestHandler instanceof HttpRequestHandlerInterface) || count($nodeContextPaths) < $this->threshold) {
@@ -92,6 +119,11 @@ public function publish(JoinPointInterface $joinPoint)
92119
$this->redirectToPoll($controller, $job);
93120
}
94121

122+
private function filterExistingContextPaths(array $contextPaths): array
123+
{
124+
return array_values(array_filter($contextPaths, fn (string $contextPath) => $this->nodeService->getNodeFromContextPath($contextPath, null, null, true) !== null));
125+
}
126+
95127
private function redirectToPoll(BackendServiceController $controller, Job $job): void
96128
{
97129
$response = $controller->getControllerContext()->getResponse();

0 commit comments

Comments
 (0)