@@ -64,11 +64,6 @@ class NodeIndexCommandController extends CommandController
6464 */
6565 protected $ nodeTypeMappingBuilder ;
6666
67- /**
68- * @var integer
69- */
70- protected $ limit ;
71-
7267 /**
7368 * @Flow\Inject
7469 * @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface
@@ -226,7 +221,6 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
226221 $ this ->logger ->log (sprintf ('Indexing %snodes ... ' , ($ limit !== null ? 'the first ' . $ limit . ' ' : '' )), LOG_INFO );
227222
228223 $ count = 0 ;
229- $ this ->limit = $ limit ;
230224
231225 if ($ workspace === null && $ this ->settings ['indexAllWorkspaces ' ] === false ) {
232226 $ workspace = 'live ' ;
@@ -241,10 +235,10 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
241235 };
242236 if ($ workspace === null ) {
243237 foreach ($ this ->workspaceRepository ->findAll () as $ workspace ) {
244- $ count += $ this ->indexWorkspace ($ workspace ->getName ());
238+ $ count += $ this ->indexWorkspace ($ workspace ->getName (), $ limit , $ callback );
245239 }
246240 } else {
247- $ count = $ this ->indexWorkspace ($ workspace );
241+ $ count + = $ this ->indexWorkspace ($ workspace, $ limit , $ callback );
248242 }
249243
250244 $ this ->nodeIndexingManager ->flushQueues ();
@@ -266,81 +260,17 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
266260 public function cleanupCommand ()
267261 {
268262 try {
269- $ removedIndices = $ this ->nodeIndexer ->removeOldIndices ();
270- if (count ($ removedIndices ) > 0 ) {
271- if (count ($ removedIndices ) === 1 ) {
272- $ this ->logger ->log ('Removed old index ' . current ($ removedIndices ) . '. ' );
273- } else {
274- $ this ->logger ->log ('Removed old indices ' . implode (', ' , $ removedIndices ) . '. ' );
263+ $ indicesToBeRemoved = $ this ->nodeIndexer ->removeOldIndices ();
264+ if (count ($ indicesToBeRemoved ) > 0 ) {
265+ foreach ($ indicesToBeRemoved as $ indexToBeRemoved ) {
266+ $ this ->logger ->log ('Removing old index ' . $ indexToBeRemoved );
275267 }
276268 } else {
277269 $ this ->logger ->log ('Nothing to remove. ' );
278270 }
279271 } catch (\Flowpack \ElasticSearch \Transfer \Exception \ApiException $ exception ) {
280272 $ response = json_decode ($ exception ->getResponse ());
281- $ this ->logger ->log (sprintf ('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s" ' , $ response ->status , $ response ->error ->type , $ response ->error ->reason ));
282- }
283- }
284-
285- /**
286- * @param string $workspaceName
287- * @return int
288- */
289- protected function indexWorkspace ($ workspaceName )
290- {
291- $ indexedNodes = 0 ;
292- $ combinations = $ this ->contentDimensionCombinator ->getAllAllowedCombinations ();
293- if ($ combinations === []) {
294- $ indexedNodes += $ this ->indexWorkspaceWithDimensions ($ workspaceName );
295- } else {
296- foreach ($ combinations as $ combination ) {
297- $ indexedNodes += $ this ->indexWorkspaceWithDimensions ($ workspaceName , $ combination );
298- }
299- }
300-
301- return $ indexedNodes ;
302- }
303-
304- /**
305- * @param string $workspaceName
306- * @param array $dimensions
307- * @return int
308- */
309- protected function indexWorkspaceWithDimensions ($ workspaceName , array $ dimensions = [])
310- {
311- $ indexedNodes = 0 ;
312- $ context = $ this ->contextFactory ->create (['workspaceName ' => $ workspaceName , 'dimensions ' => $ dimensions ]);
313- $ rootNode = $ context ->getRootNode ();
314-
315- $ indexedNodes += $ this ->traverseNodes ($ rootNode );
316-
317- if ($ dimensions === []) {
318- $ this ->outputLine ('Workspace " ' . $ workspaceName . '" without dimensions done. (Indexed ' . $ indexedNodes . ' nodes) ' );
319- } else {
320- $ this ->outputLine ('Workspace " ' . $ workspaceName . '" and dimensions " ' . json_encode ($ dimensions ) . '" done. (Indexed ' . $ indexedNodes . ' nodes) ' );
321- }
322-
323- return $ indexedNodes ;
324- }
325-
326- /**
327- * @param NodeInterface $currentNode
328- * @param integer $traversedUntilNow
329- * @return integer Indexed nodes in this traversal
330- */
331- protected function traverseNodes (NodeInterface $ currentNode , $ traversedUntilNow = 0 )
332- {
333- if ($ this ->limit !== null && $ traversedUntilNow > $ this ->limit ) {
334- return $ traversedUntilNow ;
273+ $ this ->logger ->log (sprintf ('Nothing removed. ElasticSearch responded with status %s, saying "%s" ' , $ response ->status , $ response ->error ));
335274 }
336-
337- $ this ->nodeIndexingManager ->indexNode ($ currentNode );
338- $ traversedUntilNow ++;
339-
340- foreach ($ currentNode ->getChildNodes () as $ childNode ) {
341- $ traversedUntilNow = $ this ->traverseNodes ($ childNode , $ traversedUntilNow );
342- }
343-
344- return $ traversedUntilNow ;
345275 }
346276}
0 commit comments