1010use Neos \Flow \Http \HttpRequestHandlerInterface ;
1111use Neos \Flow \Persistence \PersistenceManagerInterface ;
1212use Neos \Flow \Utility \Algorithms ;
13+ use Neos \Neos \Ui \ContentRepository \Service \NodeService ;
1314use 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 ;
1418use Netlogix \Neos \AsyncWorkspaceActions \Domain \Model \Job ;
1519use Netlogix \Neos \AsyncWorkspaceActions \Domain \Repository \JobRepository ;
1620use 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