1919use Neos \ContentRepository \Core \CommandHandler \CommandInterface ;
2020use Neos \ContentRepository \Core \CommandHandler \CommandSimulatorFactory ;
2121use Neos \ContentRepository \Core \ContentRepository ;
22+ use Neos \ContentRepository \Core \DimensionSpace \DimensionSpacePointSet ;
2223use Neos \ContentRepository \Core \EventStore \DecoratedEvent ;
2324use Neos \ContentRepository \Core \EventStore \EventNormalizer ;
2425use Neos \ContentRepository \Core \EventStore \Events ;
2526use Neos \ContentRepository \Core \EventStore \EventsToPublish ;
27+ use Neos \ContentRepository \Core \Feature \Common \EmbedsAffectedDimensionSpacePoints ;
28+ use Neos \ContentRepository \Core \Feature \Common \EmbedsNodeAggregateId ;
2629use Neos \ContentRepository \Core \Feature \Common \PublishableToWorkspaceInterface ;
2730use Neos \ContentRepository \Core \Feature \Common \RebasableToOtherWorkspaceInterface ;
2831use Neos \ContentRepository \Core \Feature \ContentStreamClosing \Event \ContentStreamWasClosed ;
4649use Neos \ContentRepository \Core \Feature \WorkspacePublication \Command \DiscardWorkspace ;
4750use Neos \ContentRepository \Core \Feature \WorkspacePublication \Command \PublishIndividualNodesFromWorkspace ;
4851use Neos \ContentRepository \Core \Feature \WorkspacePublication \Command \PublishWorkspace ;
52+ use Neos \ContentRepository \Core \Feature \WorkspacePublication \Dto \NodeIdsToPublishOrDiscard ;
53+ use Neos \ContentRepository \Core \Feature \WorkspacePublication \Dto \NodeIdToPublishOrDiscard ;
4954use Neos \ContentRepository \Core \Feature \WorkspacePublication \Event \WorkspaceWasDiscarded ;
5055use Neos \ContentRepository \Core \Feature \WorkspacePublication \Event \WorkspaceWasPartiallyDiscarded ;
5156use Neos \ContentRepository \Core \Feature \WorkspacePublication \Event \WorkspaceWasPartiallyPublished ;
5964use Neos \ContentRepository \Core \SharedModel \Exception \ContentStreamIsClosed ;
6065use Neos \ContentRepository \Core \SharedModel \Exception \WorkspaceDoesNotExist ;
6166use Neos \ContentRepository \Core \SharedModel \Exception \WorkspaceHasNoBaseWorkspaceName ;
67+ use Neos \ContentRepository \Core \SharedModel \Node \NodeAggregateId ;
6268use Neos \ContentRepository \Core \SharedModel \Workspace \ContentStreamId ;
6369use Neos \ContentRepository \Core \SharedModel \Workspace \Workspace ;
6470use Neos \ContentRepository \Core \SharedModel \Workspace \WorkspaceName ;
@@ -599,6 +605,8 @@ private function handleDiscardIndividualNodesFromWorkspace(
599605 return ;
600606 }
601607
608+ $ nodesToDiscard = $ this ->extractNodeAggregateIdsAndAffectedDimensionSpacePoints ($ commandsToDiscard );
609+
602610 yield $ this ->closeContentStream (
603611 $ workspace ->currentContentStreamId ,
604612 $ workspaceContentStreamVersion
@@ -644,7 +652,7 @@ static function ($handle) use ($commandsToKeep): void {
644652 $ command ->workspaceName ,
645653 $ command ->newContentStreamId ,
646654 $ workspace ->currentContentStreamId ,
647- $ command -> nodesToDiscard ,
655+ $ nodesToDiscard ,
648656 )
649657 ),
650658 ExpectedVersion::ANY ()
@@ -659,6 +667,41 @@ static function ($handle) use ($commandsToKeep): void {
659667 yield $ this ->removeContentStreamWithoutConstraintChecks ($ workspace ->currentContentStreamId );
660668 }
661669
670+ private function extractNodeAggregateIdsAndAffectedDimensionSpacePoints (RebaseableCommands $ commands ): NodeIdsToPublishOrDiscard
671+ {
672+ /** @var array<string,DimensionSpacePointSet> $affectedDimensionSpacePointsByNodeAggregateId */
673+ $ affectedDimensionSpacePointsByNodeAggregateId = [];
674+ foreach ($ commands as $ command ) {
675+ $ event = $ this ->eventNormalizer ->denormalize ($ command ->originalEvent );
676+ assert ($ event instanceof EmbedsNodeAggregateId);
677+ if (!$ event instanceof EmbedsAffectedDimensionSpacePoints) {
678+ // todo fix change node type and rename case!!! either event must contain all dsp or we need to use the variation graph here?
679+ // -> all dimension would be forward compatible if we ever allow node type change for one dsp ...
680+ continue ;
681+ }
682+ $ affectedDimensionSpacePoints = $ affectedDimensionSpacePointsByNodeAggregateId [$ event ->getNodeAggregateId ()->value ] ?? null ;
683+
684+ $ affectedDimensionSpacePointsByNodeAggregateId [$ event ->getNodeAggregateId ()->value ] =
685+ $ affectedDimensionSpacePoints !== null
686+ ? $ affectedDimensionSpacePoints ->getUnion ($ event ->getAffectedDimensionSpacePoints ())
687+ : $ event ->getAffectedDimensionSpacePoints ();
688+
689+ }
690+
691+ $ nodeAggregateIdsWithDimension = [];
692+ foreach ($ affectedDimensionSpacePointsByNodeAggregateId as $ nodeId => $ affectedDimensionSpacePoints ) {
693+ foreach ($ affectedDimensionSpacePoints as $ dimensionSpacePoint ) {
694+ $ nodeAggregateIdsWithDimension [] = new NodeIdToPublishOrDiscard (
695+ NodeAggregateId::fromString ($ nodeId ),
696+ $ dimensionSpacePoint
697+ );
698+ }
699+ }
700+
701+ // todo optimise format like: [{NodeAggregateId -> DimensionSpacePointSet}] and rename collection to NodeAggregateIdsWithDimensionSpacePoints (less clumsy) ... in the event this happened already ... no TO ...!
702+ return NodeIdsToPublishOrDiscard::create (...$ nodeAggregateIdsWithDimension );
703+ }
704+
662705 /**
663706 * @throws BaseWorkspaceDoesNotExist
664707 * @throws WorkspaceDoesNotExist
0 commit comments