1212 */
1313
1414use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Indexer \Error \ErrorInterface ;
15+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Driver \NodeTypeMappingBuilderInterface ;
1516use Flowpack \ElasticSearch \ContentRepositoryAdaptor \LoggerInterface ;
16- use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Mapping \NodeTypeMappingBuilder ;
1717use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Service \ErrorHandlingService ;
1818use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Service \IndexWorkspaceTrait ;
1919use Flowpack \ElasticSearch \Domain \Model \Mapping ;
2323use Neos \ContentRepository \Domain \Repository \NodeDataRepository ;
2424use Neos \ContentRepository \Domain \Repository \WorkspaceRepository ;
2525use Neos \ContentRepository \Domain \Service \ContentDimensionPresetSourceInterface ;
26- use Neos \ContentRepository \Domain \Service \Context ;
27- use Neos \ContentRepository \Domain \Service \ContextFactoryInterface ;
2826use Neos \ContentRepository \Search \Indexer \NodeIndexerInterface ;
2927use Neos \Flow \Annotations as Flow ;
3028use Neos \Flow \Cli \CommandController ;
3129use Neos \Flow \Configuration \ConfigurationManager ;
30+ use Neos \Flow \Configuration \Exception \InvalidConfigurationTypeException ;
31+ use Neos \Flow \Mvc \Exception \StopActionException ;
3232use Neos \Flow \ObjectManagement \ObjectManagerInterface ;
33+ use Neos \Neos \Controller \CreateContentContextTrait ;
3334use Symfony \Component \Yaml \Yaml ;
3435
3536/**
@@ -41,6 +42,8 @@ class NodeIndexCommandController extends CommandController
4142{
4243 use IndexWorkspaceTrait;
4344
45+ use CreateContentContextTrait;
46+
4447 /**
4548 * @Flow\Inject
4649 * @var ErrorHandlingService
@@ -79,7 +82,7 @@ class NodeIndexCommandController extends CommandController
7982
8083 /**
8184 * @Flow\Inject
82- * @var NodeTypeMappingBuilder
85+ * @var NodeTypeMappingBuilderInterface
8386 */
8487 protected $ nodeTypeMappingBuilder ;
8588
@@ -95,12 +98,6 @@ class NodeIndexCommandController extends CommandController
9598 */
9699 protected $ configurationManager ;
97100
98- /**
99- * @Flow\Inject
100- * @var ContextFactoryInterface
101- */
102- protected $ contextFactory ;
103-
104101 /**
105102 * @var array
106103 */
@@ -110,6 +107,7 @@ class NodeIndexCommandController extends CommandController
110107 * Called by the Flow object framework after creating the object and resolving all dependencies.
111108 *
112109 * @param integer $cause Creation cause
110+ * @throws InvalidConfigurationTypeException
113111 */
114112 public function initializeObject ($ cause )
115113 {
@@ -159,6 +157,7 @@ public function showMappingCommand()
159157 * @param string $identifier
160158 * @param string $workspace
161159 * @return void
160+ * @throws StopActionException
162161 */
163162 public function indexNodeCommand ($ identifier , $ workspace = null )
164163 {
@@ -226,8 +225,9 @@ public function indexNodeCommand($identifier, $workspace = null)
226225 * @param string $workspace name of the workspace which should be indexed
227226 * @param string $postfix Index postfix, index with the same postfix will be deleted if exist
228227 * @return void
228+ * @throws StopActionException
229229 */
230- public function buildCommand ($ limit = null , $ update = false , $ workspace = null , $ postfix = null )
230+ public function buildCommand ($ limit = null , $ update = false , $ workspace = null , $ postfix = '' )
231231 {
232232 if ($ workspace !== null && $ this ->workspaceRepository ->findByIdentifier ($ workspace ) === null ) {
233233 $ this ->logger ->log ('The given workspace ( ' . $ workspace . ') does not exist. ' , LOG_ERR );
@@ -303,33 +303,12 @@ public function cleanupCommand()
303303 }
304304 } catch (ApiException $ exception ) {
305305 $ response = json_decode ($ exception ->getResponse ());
306- $ this ->logger ->log (sprintf ('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s" ' , $ response ->status , $ response ->error ->type , $ response ->error ->reason ));
307- }
308- }
309-
310- /**
311- * Create a ContentContext based on the given workspace name
312- *
313- * @param string $workspaceName Name of the workspace to set for the context
314- * @param array $dimensions Optional list of dimensions and their values which should be set
315- * @return Context
316- */
317- protected function createContentContext ($ workspaceName , array $ dimensions = [])
318- {
319- $ contextProperties = [
320- 'workspaceName ' => $ workspaceName ,
321- 'invisibleContentShown ' => true ,
322- 'inaccessibleContentShown ' => true
323- ];
324-
325- if ($ dimensions !== []) {
326- $ contextProperties ['dimensions ' ] = $ dimensions ;
327- $ contextProperties ['targetDimensions ' ] = array_map (function ($ dimensionValues ) {
328- return array_shift ($ dimensionValues );
329- }, $ dimensions );
306+ if ($ response ->error instanceof \stdClass) {
307+ $ this ->logger ->log (sprintf ('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s" ' , $ response ->status , $ response ->error ->type , $ response ->error ->reason ));
308+ } else {
309+ $ this ->logger ->log (sprintf ('Nothing removed. ElasticSearch responded with status %s, saying "%s" ' , $ response ->status , $ response ->error ));
310+ }
330311 }
331-
332- return $ this ->contextFactory ->create ($ contextProperties );
333312 }
334313
335314 /**
@@ -338,7 +317,7 @@ protected function createContentContext($workspaceName, array $dimensions = [])
338317 * @param string $postfix
339318 * @return void
340319 */
341- protected function createNewIndex ($ postfix )
320+ protected function createNewIndex (string $ postfix )
342321 {
343322 $ this ->nodeIndexer ->setIndexNamePostfix ($ postfix ?: time ());
344323 if ($ this ->nodeIndexer ->getIndex ()->exists () === true ) {
0 commit comments