11<?php
22namespace Flowpack \ElasticSearch \ContentRepositoryAdaptor \Command ;
33
4- /* *
5- * This script belongs to the TYPO3 Flow package " Flowpack.ElasticSearch.ContentRepositoryAdaptor". *
6- * *
7- * It is free software; you can redistribute it and/or modify it under *
8- * the terms of the GNU Lesser General Public License, either version 3 *
9- * of the License, or (at your option) any later version. *
10- * *
11- * The TYPO3 project - inspiring people to share! *
12- * * /
4+ /*
5+ * This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package.
6+ *
7+ * (c) Contributors of the Neos Project - www.neos.io
8+ *
9+ * This package is Open Source Software. For the full copyright and license
10+ * information, please view the LICENSE file which was distributed with this
11+ * source code.
12+ */
1313
14+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Mapping \NodeTypeMappingBuilder ;
15+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Service \IndexWorkspaceTrait ;
1416use TYPO3 \Flow \Annotations as Flow ;
1517use TYPO3 \Flow \Cli \CommandController ;
16- use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Mapping \NodeTypeMappingBuilder ;
1718use TYPO3 \TYPO3CR \Domain \Model \NodeInterface ;
18- use TYPO3 \TYPO3CR \Domain \Service \ContentDimensionCombinator ;
19- use TYPO3 \TYPO3CR \Search \Indexer \NodeIndexingManager ;
2019
2120/**
2221 * Provides CLI features for index handling
2524 */
2625class NodeIndexCommandController extends CommandController
2726{
27+ use IndexWorkspaceTrait;
28+
2829 /**
2930 * @Flow\Inject
3031 * @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer
3132 */
3233 protected $ nodeIndexer ;
3334
34- /**
35- * @Flow\Inject
36- * @var NodeIndexingManager
37- */
38- protected $ nodeIndexingManager ;
39-
4035 /**
4136 * @Flow\Inject
4237 * @var \TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository
@@ -55,12 +50,6 @@ class NodeIndexCommandController extends CommandController
5550 */
5651 protected $ nodeFactory ;
5752
58- /**
59- * @Flow\Inject
60- * @var \TYPO3\TYPO3CR\Domain\Service\ContextFactory
61- */
62- protected $ contextFactory ;
63-
6453 /**
6554 * @Flow\Inject
6655 * @var \TYPO3\Neos\Domain\Service\ContentDimensionPresetSourceInterface
@@ -90,12 +79,6 @@ class NodeIndexCommandController extends CommandController
9079 */
9180 protected $ configurationManager ;
9281
93- /**
94- * @Flow\Inject
95- * @var ContentDimensionCombinator
96- */
97- protected $ contentDimensionCombinator ;
98-
9982 /**
10083 * @var array
10184 */
@@ -189,6 +172,13 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
189172 $ workspace = 'live ' ;
190173 }
191174
175+ $ callback = function ($ workspaceName , $ indexedNodes , $ dimensions ) {
176+ if ($ dimensions === []) {
177+ $ this ->outputLine ('Workspace " ' . $ workspaceName . '" without dimensions done. (Indexed ' . $ indexedNodes . ' nodes) ' );
178+ } else {
179+ $ this ->outputLine ('Workspace " ' . $ workspaceName . '" and dimensions " ' . json_encode ($ dimensions ) . '" done. (Indexed ' . $ indexedNodes . ' nodes) ' );
180+ }
181+ };
192182 if ($ workspace === null ) {
193183 foreach ($ this ->workspaceRepository ->findAll () as $ workspace ) {
194184 $ count += $ this ->indexWorkspace ($ workspace ->getName ());
@@ -232,13 +222,13 @@ public function cleanupCommand()
232222
233223 /**
234224 * @param string $workspaceName
235- * @return void
225+ * @return int
236226 */
237227 protected function indexWorkspace ($ workspaceName )
238228 {
239229 $ indexedNodes = 0 ;
240230 $ combinations = $ this ->contentDimensionCombinator ->getAllAllowedCombinations ();
241- if ($ combinations === array () ) {
231+ if ($ combinations === [] ) {
242232 $ indexedNodes += $ this ->indexWorkspaceWithDimensions ($ workspaceName );
243233 } else {
244234 foreach ($ combinations as $ combination ) {
@@ -252,17 +242,17 @@ protected function indexWorkspace($workspaceName)
252242 /**
253243 * @param string $workspaceName
254244 * @param array $dimensions
255- * @return void
245+ * @return int
256246 */
257- protected function indexWorkspaceWithDimensions ($ workspaceName , array $ dimensions = array () )
247+ protected function indexWorkspaceWithDimensions ($ workspaceName , array $ dimensions = [] )
258248 {
259249 $ indexedNodes = 0 ;
260- $ context = $ this ->contextFactory ->create (array ( 'workspaceName ' => $ workspaceName , 'dimensions ' => $ dimensions) );
250+ $ context = $ this ->contextFactory ->create ([ 'workspaceName ' => $ workspaceName , 'dimensions ' => $ dimensions] );
261251 $ rootNode = $ context ->getRootNode ();
262252
263253 $ indexedNodes += $ this ->traverseNodes ($ rootNode );
264254
265- if ($ dimensions === array () ) {
255+ if ($ dimensions === [] ) {
266256 $ this ->outputLine ('Workspace " ' . $ workspaceName . '" without dimensions done. (Indexed ' . $ indexedNodes . ' nodes) ' );
267257 } else {
268258 $ this ->outputLine ('Workspace " ' . $ workspaceName . '" and dimensions " ' . json_encode ($ dimensions ) . '" done. (Indexed ' . $ indexedNodes . ' nodes) ' );
0 commit comments