11<?php
2+ declare (strict_types=1 );
3+
24namespace Flowpack \ElasticSearch \ContentRepositoryQueueIndexer \Command ;
35
46/*
1214 */
1315
1416use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Driver \NodeTypeMappingBuilderInterface ;
17+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Exception \ConfigurationException ;
1518use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Indexer \NodeIndexer ;
1619use Flowpack \ElasticSearch \ContentRepositoryQueueIndexer \Domain \Repository \NodeDataRepository ;
1720use Flowpack \ElasticSearch \ContentRepositoryQueueIndexer \IndexingJob ;
2427use Neos \ContentRepository \Domain \Repository \WorkspaceRepository ;
2528use Neos \Flow \Annotations as Flow ;
2629use Neos \Flow \Cli \CommandController ;
30+ use Neos \Flow \Cli \Exception \StopCommandException ;
31+ use Neos \Flow \Log \Utility \LogEnvironment ;
32+ use Neos \Flow \Mvc \Exception \StopActionException ;
2733use Neos \Flow \Persistence \PersistenceManagerInterface ;
2834use Neos \Utility \Files ;
35+ use Psr \Log \LoggerInterface ;
2936
3037/**
3138 * Provides CLI features for index handling
3441 */
3542class NodeIndexQueueCommandController extends CommandController
3643{
37- use LoggerTrait;
44+ protected const BATCH_QUEUE_NAME = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer ' ;
45+ public const LIVE_QUEUE_NAME = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer.Live ' ;
3846
39- const BATCH_QUEUE_NAME = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer ' ;
40- const LIVE_QUEUE_NAME = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer.Live ' ;
47+ /**
48+ * @Flow\Inject
49+ * @var LoggerInterface
50+ */
51+ protected $ logger ;
4152
4253 /**
4354 * @var JobManager
@@ -91,13 +102,17 @@ class NodeIndexQueueCommandController extends CommandController
91102 * Index all nodes by creating a new index and when everything was completed, switch the index alias.
92103 *
93104 * @param string $workspace
94- * @throws \Flowpack\JobQueue\Common\Exception
95- * @throws \Neos\Flow\Mvc\Exception\StopActionException
105+ * @throws ConfigurationException
106+ * @throws Exception
107+ * @throws StopCommandException
96108 * @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
109+ * @throws \Flowpack\ElasticSearch\Exception
110+ * @throws \Neos\Flow\Http\Exception
111+ * @throws \Exception
97112 */
98- public function buildCommand ($ workspace = null )
113+ public function buildCommand (string $ workspace = null ): void
99114 {
100- $ indexPostfix = time ();
115+ $ indexPostfix = ( string ) time ();
101116 $ indexName = $ this ->createNextIndex ($ indexPostfix );
102117 $ this ->updateMapping ($ indexPostfix );
103118
@@ -120,10 +135,11 @@ public function buildCommand($workspace = null)
120135 $ this ->outputLine ();
121136 $ this ->indexWorkspace ($ workspace , $ indexPostfix );
122137 }
138+
123139 $ updateAliasJob = new UpdateAliasJob ($ indexPostfix );
124140 $ this ->jobManager ->queue (self ::BATCH_QUEUE_NAME , $ updateAliasJob );
125141
126- $ this ->outputLine (" Indexing jobs created for queue %s with success ... " , [self ::BATCH_QUEUE_NAME ]);
142+ $ this ->outputLine (' Indexing jobs created for queue %s with success ... ' , [self ::BATCH_QUEUE_NAME ]);
127143 $ this ->outputSystemReport ();
128144 $ this ->outputLine ();
129145 }
@@ -134,9 +150,10 @@ public function buildCommand($workspace = null)
134150 * @param int $limit If set, only the given amount of jobs are processed (successful or not) before the script exits
135151 * @param bool $verbose Output debugging information
136152 * @return void
137- * @throws \Neos\Flow\Mvc\Exception\StopActionException
153+ * @throws StopActionException
154+ * @throws StopCommandException
138155 */
139- public function workCommand ($ queue = 'batch ' , $ exitAfter = null , $ limit = null , $ verbose = false )
156+ public function workCommand (string $ queue = 'batch ' , int $ exitAfter = null , int $ limit = null , $ verbose = false ): void
140157 {
141158 $ allowedQueues = [
142159 'batch ' => self ::BATCH_QUEUE_NAME ,
@@ -201,7 +218,7 @@ public function workCommand($queue = 'batch', $exitAfter = null, $limit = null,
201218 /**
202219 * Flush the index queue
203220 */
204- public function flushCommand ()
221+ public function flushCommand (): void
205222 {
206223 try {
207224 $ this ->queueManager ->getQueue (self ::BATCH_QUEUE_NAME )->flush ();
@@ -235,8 +252,9 @@ protected function outputSystemReport()
235252 /**
236253 * @param string $workspaceName
237254 * @param string $indexPostfix
255+ * @throws \Exception
238256 */
239- protected function indexWorkspace ($ workspaceName , $ indexPostfix )
257+ protected function indexWorkspace (string $ workspaceName , string $ indexPostfix ): void
240258 {
241259 $ this ->outputLine ('<info>++</info> Indexing %s workspace ' , [$ workspaceName ]);
242260 $ nodeCounter = 0 ;
@@ -277,30 +295,36 @@ protected function indexWorkspace($workspaceName, $indexPostfix)
277295 * @param string $indexPostfix
278296 * @return string
279297 * @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
298+ * @throws ConfigurationException
299+ * @throws \Flowpack\ElasticSearch\Exception
300+ * @throws \Neos\Flow\Http\Exception
280301 */
281- protected function createNextIndex ($ indexPostfix )
302+ protected function createNextIndex (string $ indexPostfix ): string
282303 {
283304 $ this ->nodeIndexer ->setIndexNamePostfix ($ indexPostfix );
284305 $ this ->nodeIndexer ->getIndex ()->create ();
285- $ this ->log (sprintf ('action=indexing step=index-created index=%s ' , $ this ->nodeIndexer ->getIndexName ()), LOG_INFO );
306+ $ this ->logger -> info (sprintf ('Index %s created ' , $ this ->nodeIndexer ->getIndexName ()), LogEnvironment:: fromMethodName ( __METHOD__ ) );
286307
287308 return $ this ->nodeIndexer ->getIndexName ();
288309 }
289310
290311 /**
291312 * Update Index Mapping
292313 *
314+ * @param string $indexPostfix
293315 * @return void
316+ * @throws ConfigurationException
294317 * @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
318+ * @throws \Flowpack\ElasticSearch\Exception
295319 */
296- protected function updateMapping ($ indexPostfix )
320+ protected function updateMapping (string $ indexPostfix ): void
297321 {
298322 $ nodeTypeMappingCollection = $ this ->nodeTypeMappingBuilder ->buildMappingInformation ($ this ->nodeIndexer ->getIndex ());
299323 foreach ($ nodeTypeMappingCollection as $ mapping ) {
300324 $ this ->nodeIndexer ->setIndexNamePostfix ($ indexPostfix );
301325 /** @var Mapping $mapping */
302326 $ mapping ->apply ();
303327 }
304- $ this ->log (sprintf ('action=indexing step=mapping- updated index= %s ' , $ this ->nodeIndexer ->getIndexName ()), LOG_INFO );
328+ $ this ->logger -> info (sprintf ('Mapping updated for index %s ' , $ this ->nodeIndexer ->getIndexName ()), LogEnvironment:: fromMethodName ( __METHOD__ ) );
305329 }
306330}
0 commit comments