1111 * The TYPO3 project - inspiring people to share! *
1212 * */
1313
14+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Service \IndexWorkspaceTrait ;
1415use TYPO3 \Flow \Annotations as Flow ;
1516use TYPO3 \Flow \Cli \CommandController ;
1617use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Mapping \NodeTypeMappingBuilder ;
17- use TYPO3 \TYPO3CR \Domain \Service \ContentDimensionCombinator ;
18- use TYPO3 \TYPO3CR \Search \Indexer \NodeIndexingManager ;
1918
2019/**
2120 * Provides CLI features for index handling
2423 */
2524class NodeIndexCommandController extends CommandController
2625{
26+ use IndexWorkspaceTrait;
27+
2728 /**
2829 * @Flow\Inject
2930 * @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer
3031 */
3132 protected $ nodeIndexer ;
3233
33- /**
34- * @Flow\Inject
35- * @var NodeIndexingManager
36- */
37- protected $ nodeIndexingManager ;
38-
3934 /**
4035 * @Flow\Inject
4136 * @var \TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository
@@ -54,12 +49,6 @@ class NodeIndexCommandController extends CommandController
5449 */
5550 protected $ nodeFactory ;
5651
57- /**
58- * @Flow\Inject
59- * @var \TYPO3\TYPO3CR\Domain\Service\ContextFactory
60- */
61- protected $ contextFactory ;
62-
6352 /**
6453 * @Flow\Inject
6554 * @var \TYPO3\Neos\Domain\Service\ContentDimensionPresetSourceInterface
@@ -72,21 +61,6 @@ class NodeIndexCommandController extends CommandController
7261 */
7362 protected $ nodeTypeMappingBuilder ;
7463
75- /**
76- * @var integer
77- */
78- protected $ indexedNodes ;
79-
80- /**
81- * @var integer
82- */
83- protected $ countedIndexedNodes ;
84-
85- /**
86- * @var integer
87- */
88- protected $ limit ;
89-
9064 /**
9165 * @Flow\Inject
9266 * @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface
@@ -99,12 +73,6 @@ class NodeIndexCommandController extends CommandController
9973 */
10074 protected $ configurationManager ;
10175
102- /**
103- * @Flow\Inject
104- * @var ContentDimensionCombinator
105- */
106- protected $ contentDimensionCombinator ;
107-
10876 /**
10977 * @var array
11078 */
@@ -192,23 +160,24 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
192160 $ this ->logger ->log (sprintf ('Indexing %snodes ... ' , ($ limit !== null ? 'the first ' . $ limit . ' ' : '' )), LOG_INFO );
193161
194162 $ count = 0 ;
195- $ this ->limit = $ limit ;
196- $ this ->indexedNodes = 0 ;
197- $ this ->countedIndexedNodes = 0 ;
198163
199164 if ($ workspace === null && $ this ->settings ['indexAllWorkspaces ' ] === false ) {
200165 $ workspace = 'live ' ;
201166 }
202167
168+ $ callback = function ($ workspaceName , $ indexedNodes , $ dimensions ) {
169+ if ($ dimensions === array ()) {
170+ $ this ->outputLine ('Workspace " ' . $ workspaceName . '" without dimensions done. (Indexed ' . $ indexedNodes . ' nodes) ' );
171+ } else {
172+ $ this ->outputLine ('Workspace " ' . $ workspaceName . '" and dimensions " ' . json_encode ($ dimensions ) . '" done. (Indexed ' . $ indexedNodes . ' nodes) ' );
173+ }
174+ };
203175 if ($ workspace === null ) {
204176 foreach ($ this ->workspaceRepository ->findAll () as $ workspace ) {
205- $ this ->indexWorkspace ($ workspace ->getName ());
206-
207- $ count = $ count + $ this ->countedIndexedNodes ;
177+ $ count += $ this ->indexWorkspace ($ workspace ->getName (), $ limit , $ callback );
208178 }
209179 } else {
210- $ this ->indexWorkspace ($ workspace );
211- $ count = $ count + $ this ->countedIndexedNodes ;
180+ $ count += $ this ->indexWorkspace ($ workspace , $ limit , $ callback );
212181 }
213182
214183 $ this ->nodeIndexingManager ->flushQueues ();
@@ -243,60 +212,4 @@ public function cleanupCommand()
243212 $ this ->logger ->log (sprintf ('Nothing removed. ElasticSearch responded with status %s, saying "%s" ' , $ response ->status , $ response ->error ));
244213 }
245214 }
246-
247- /**
248- * @param string $workspaceName
249- * @return void
250- */
251- protected function indexWorkspace ($ workspaceName )
252- {
253- $ combinations = $ this ->contentDimensionCombinator ->getAllAllowedCombinations ();
254- if ($ combinations === array ()) {
255- $ this ->indexWorkspaceWithDimensions ($ workspaceName );
256- } else {
257- foreach ($ combinations as $ combination ) {
258- $ this ->indexWorkspaceWithDimensions ($ workspaceName , $ combination );
259- }
260- }
261- }
262-
263- /**
264- * @param string $workspaceName
265- * @param array $dimensions
266- * @return void
267- */
268- protected function indexWorkspaceWithDimensions ($ workspaceName , array $ dimensions = array ())
269- {
270- $ context = $ this ->contextFactory ->create (array ('workspaceName ' => $ workspaceName , 'dimensions ' => $ dimensions ));
271- $ rootNode = $ context ->getRootNode ();
272-
273- $ this ->traverseNodes ($ rootNode );
274-
275- if ($ dimensions === array ()) {
276- $ this ->outputLine ('Workspace " ' . $ workspaceName . '" without dimensions done. (Indexed ' . $ this ->indexedNodes . ' nodes) ' );
277- } else {
278- $ this ->outputLine ('Workspace " ' . $ workspaceName . '" and dimensions " ' . json_encode ($ dimensions ) . '" done. (Indexed ' . $ this ->indexedNodes . ' nodes) ' );
279- }
280-
281- $ this ->countedIndexedNodes = $ this ->countedIndexedNodes + $ this ->indexedNodes ;
282- $ this ->indexedNodes = 0 ;
283- }
284-
285- /**
286- * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $currentNode
287- * @return void
288- */
289- protected function traverseNodes (\TYPO3 \TYPO3CR \Domain \Model \NodeInterface $ currentNode )
290- {
291- if ($ this ->limit !== null && $ this ->indexedNodes > $ this ->limit ) {
292- return ;
293- }
294-
295- $ this ->nodeIndexingManager ->indexNode ($ currentNode );
296- $ this ->indexedNodes ++;
297-
298- foreach ($ currentNode ->getChildNodes () as $ childNode ) {
299- $ this ->traverseNodes ($ childNode );
300- }
301- }
302215}
0 commit comments