55
66use Flowpack \SimpleSearch \Domain \Service \IndexInterface ;
77use Flowpack \SimpleSearch \Exception ;
8- use Neos \ContentRepository \Domain \Model \NodeInterface ;
9- use Neos \ContentRepository \Domain \Repository \NodeDataRepository ;
10- use Neos \ContentRepository \Domain \Repository \WorkspaceRepository ;
11- use Neos \ContentRepository \Domain \Service \ContextFactoryInterface ;
12- use Neos \ContentRepository \Exception \NodeException ;
8+ use Neos \ContentRepository \Core \DimensionSpace \DimensionSpacePoint ;
9+ use Neos \ContentRepository \Core \DimensionSpace \DimensionSpacePointSet ;
10+ use Neos \ContentRepository \Core \Projection \ContentGraph \Filter \FindDescendantNodesFilter ;
11+ use Neos \ContentRepository \Core \Projection \ContentGraph \Node ;
12+ use Neos \ContentRepository \Core \SharedModel \ContentRepository \ContentRepositoryId ;
13+ use Neos \ContentRepository \Core \SharedModel \Workspace \WorkspaceName ;
1314use Neos \ContentRepository \Search \Exception \IndexingException ;
15+ use Neos \ContentRepositoryRegistry \ContentRepositoryRegistry ;
1416use Neos \ContentRepository \Search \Indexer \NodeIndexerInterface ;
1517use Neos \Eel \Exception as EelException ;
1618use Neos \Flow \Annotations as Flow ;
1719use Neos \Flow \Cli \CommandController ;
18- use Neos \Neos \Domain \Service \ContentDimensionPresetSourceInterface ;
20+ use Neos \Neos \Domain \Service \NodeTypeNameFactory ;
21+ use Neos \Neos \Domain \SubtreeTagging \NeosVisibilityConstraints ;
1922
2023/**
2124 * Provides CLI features for index handling
@@ -36,34 +39,8 @@ class NodeIndexCommandController extends CommandController
3639 */
3740 protected $ indexClient ;
3841
39- /**
40- * @Flow\Inject
41- * @var WorkspaceRepository
42- */
43- protected $ workspaceRepository ;
44-
45- /**
46- * @Flow\Inject
47- * @var NodeDataRepository
48- */
49- protected $ nodeDataRepository ;
50-
51- /**
52- * @Flow\Inject
53- * @var ContextFactoryInterface
54- */
55- protected $ contextFactory ;
56-
57- /**
58- * @Flow\Inject
59- * @var ContentDimensionPresetSourceInterface
60- */
61- protected $ contentDimensionPresetSource ;
62-
63- /**
64- * @var integer
65- */
66- protected $ indexedNodes ;
42+ #[Flow \Inject]
43+ protected ContentRepositoryRegistry $ contentRepositoryRegistry ;
6744
6845 /**
6946 * Index all nodes.
@@ -75,15 +52,18 @@ class NodeIndexCommandController extends CommandController
7552 * @return void
7653 * @throws Exception
7754 */
78- public function buildCommand (string $ workspace = null ): void
55+ public function buildCommand (string $ contentRepository = ' default ' , ? string $ workspace = null ): void
7956 {
80- $ this ->indexedNodes = 0 ;
57+ $ contentRepositoryId = ContentRepositoryId::fromString ($ contentRepository );
58+ $ contentRepository = $ this ->contentRepositoryRegistry ->get ($ contentRepositoryId );
59+
8160 if ($ workspace === null ) {
82- foreach ($ this -> workspaceRepository -> findAll () as $ workspaceInstance ) {
83- $ this ->indexWorkspace ($ workspaceInstance ->getName () );
61+ foreach ($ contentRepository -> findWorkspaces () as $ workspaceInstance ) {
62+ $ this ->indexWorkspace ($ contentRepositoryId , $ workspaceInstance ->workspaceName );
8463 }
8564 } else {
86- $ this ->indexWorkspace ($ workspace );
65+ $ workspaceName = WorkspaceName::fromString ($ workspace );
66+ $ this ->indexWorkspace ($ contentRepositoryId , $ workspaceName );
8767 }
8868 $ this ->outputLine ('Finished indexing. ' );
8969 }
@@ -92,44 +72,47 @@ public function buildCommand(string $workspace = null): void
9272 * @param string $workspaceName
9373 * @throws Exception
9474 */
95- protected function indexWorkspace (string $ workspaceName ): void
75+ protected function indexWorkspace (ContentRepositoryId $ contentRepositoryId , WorkspaceName $ workspaceName ): void
9676 {
97- $ dimensionCombinations = $ this ->nodeIndexer ->calculateDimensionCombinations ();
98- if ($ dimensionCombinations !== []) {
99- foreach ($ dimensionCombinations as $ combination ) {
100- $ context = $ this ->contextFactory ->create (['workspaceName ' => $ workspaceName , 'dimensions ' => $ combination ]);
101- $ rootNode = $ context ->getRootNode ();
102-
103- $ this ->traverseNodes ($ rootNode );
104- $ rootNode ->getContext ()->getFirstLevelNodeCache ()->flush ();
105- $ this ->outputLine ('Workspace " ' . $ workspaceName . '" and dimensions " ' . json_encode ($ combination ) . '" done. (Indexed ' . $ this ->indexedNodes . ' nodes) ' );
106- $ this ->indexedNodes = 0 ;
107- }
108- } else {
109- $ context = $ this ->contextFactory ->create (['workspaceName ' => $ workspaceName ]);
110- $ rootNode = $ context ->getRootNode ();
77+ $ dimensionSpacePoints = $ this ->nodeIndexer ->calculateDimensionCombinations ($ contentRepositoryId );
78+ if ($ dimensionSpacePoints ->isEmpty ()) {
79+ $ dimensionSpacePoints = DimensionSpacePointSet::fromArray ([DimensionSpacePoint::createWithoutDimensions ()]);
80+ }
11181
112- $ this -> traverseNodes ( $ rootNode );
113- $ this ->outputLine ( ' Workspace " ' . $ workspaceName . ' " without dimensions done. (Indexed ' . $ this -> indexedNodes . ' nodes) ' );
114- $ this ->indexedNodes = 0 ;
82+ foreach ( $ dimensionSpacePoints as $ dimensionSpacePoint ) {
83+ $ indexedNodes = $ this ->indexWorkspaceInDimension ( $ contentRepositoryId , $ workspaceName, $ dimensionSpacePoint );
84+ $ this ->outputLine ( ' Workspace " ' . $ workspaceName . ' " and dimensions " ' . json_encode ( $ dimensionSpacePoint ) . ' " done. (Indexed ' . $ indexedNodes . ' nodes) ' ) ;
11585 }
11686 }
11787
11888 /**
119- * @param NodeInterface $currentNode
89+ * @param Node $currentNode
12090 * @throws Exception
12191 */
122- protected function traverseNodes ( NodeInterface $ currentNode ): void
92+ protected function indexWorkspaceInDimension ( ContentRepositoryId $ contentRepositoryId , WorkspaceName $ workspaceName , DimensionSpacePoint $ dimensionSpacePoint ): int
12393 {
124- try {
125- $ this ->nodeIndexer ->indexNode ($ currentNode , null , false );
126- } catch (NodeException |IndexingException |EelException $ exception ) {
127- throw new Exception (sprintf ('Error during indexing of node %s (%s) ' , $ currentNode ->findNodePath (), (string ) $ currentNode ->getNodeAggregateIdentifier ()), 1579170291 , $ exception );
128- }
129- $ this ->indexedNodes ++;
130- foreach ($ currentNode ->findChildNodes () as $ childNode ) {
131- $ this ->traverseNodes ($ childNode );
94+ $ contentRepository = $ this ->contentRepositoryRegistry ->get ($ contentRepositoryId );
95+ $ contentGraph = $ contentRepository ->getContentGraph ($ workspaceName );
96+
97+ $ rootNodeAggregate = $ contentGraph ->findRootNodeAggregateByType (NodeTypeNameFactory::forSites ());
98+ $ subgraph = $ contentGraph ->getSubgraph ($ dimensionSpacePoint , NeosVisibilityConstraints::excludeRemoved ());
99+
100+ $ rootNode = $ subgraph ->findNodeById ($ rootNodeAggregate ->nodeAggregateId );
101+ $ indexedNodes = 0 ;
102+
103+ $ this ->nodeIndexer ->indexNode ($ rootNode , null , false );
104+ $ indexedNodes ++;
105+
106+ foreach ($ subgraph ->findDescendantNodes ($ rootNode ->aggregateId , FindDescendantNodesFilter::create ()) as $ descendantNode ) {
107+ try {
108+ $ this ->nodeIndexer ->indexNode ($ descendantNode , null , false );
109+ $ indexedNodes ++;
110+ } catch (IndexingException |EelException $ exception ) {
111+ throw new Exception (sprintf ('Error during indexing of node %s ' , (string )$ descendantNode ->aggregateId ), 1579170291 , $ exception );
112+ };
132113 }
114+
115+ return $ indexedNodes ;
133116 }
134117
135118 /**
0 commit comments