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;
38-
3944 const BATCH_QUEUE_NAME = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer ' ;
4045 const LIVE_QUEUE_NAME = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer.Live ' ;
4146
47+ /**
48+ * @Flow\Inject
49+ * @var LoggerInterface
50+ */
51+ protected $ logger ;
52+
4253 /**
4354 * @var JobManager
4455 * @Flow\Inject
@@ -91,11 +102,12 @@ 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 Exception
106+ * @throws StopActionException
96107 * @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
108+ * @throws StopCommandException
97109 */
98- public function buildCommand ($ workspace = null )
110+ public function buildCommand (string $ workspace = null ): void
99111 {
100112 $ indexPostfix = time ();
101113 $ indexName = $ this ->createNextIndex ($ indexPostfix );
@@ -120,6 +132,7 @@ public function buildCommand($workspace = null)
120132 $ this ->outputLine ();
121133 $ this ->indexWorkspace ($ workspace , $ indexPostfix );
122134 }
135+
123136 $ updateAliasJob = new UpdateAliasJob ($ indexPostfix );
124137 $ this ->jobManager ->queue (self ::BATCH_QUEUE_NAME , $ updateAliasJob );
125138
@@ -134,9 +147,10 @@ public function buildCommand($workspace = null)
134147 * @param int $limit If set, only the given amount of jobs are processed (successful or not) before the script exits
135148 * @param bool $verbose Output debugging information
136149 * @return void
137- * @throws \Neos\Flow\Mvc\Exception\StopActionException
150+ * @throws StopActionException
151+ * @throws StopCommandException
138152 */
139- public function workCommand ($ queue = 'batch ' , $ exitAfter = null , $ limit = null , $ verbose = false )
153+ public function workCommand (string $ queue = 'batch ' , int $ exitAfter = null , int $ limit = null , $ verbose = false ): void
140154 {
141155 $ allowedQueues = [
142156 'batch ' => self ::BATCH_QUEUE_NAME ,
@@ -201,7 +215,7 @@ public function workCommand($queue = 'batch', $exitAfter = null, $limit = null,
201215 /**
202216 * Flush the index queue
203217 */
204- public function flushCommand ()
218+ public function flushCommand (): void
205219 {
206220 try {
207221 $ this ->queueManager ->getQueue (self ::BATCH_QUEUE_NAME )->flush ();
@@ -235,8 +249,9 @@ protected function outputSystemReport()
235249 /**
236250 * @param string $workspaceName
237251 * @param string $indexPostfix
252+ * @throws \Exception
238253 */
239- protected function indexWorkspace ($ workspaceName , $ indexPostfix )
254+ protected function indexWorkspace (string $ workspaceName , string $ indexPostfix ): void
240255 {
241256 $ this ->outputLine ('<info>++</info> Indexing %s workspace ' , [$ workspaceName ]);
242257 $ nodeCounter = 0 ;
@@ -277,30 +292,36 @@ protected function indexWorkspace($workspaceName, $indexPostfix)
277292 * @param string $indexPostfix
278293 * @return string
279294 * @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
295+ * @throws ConfigurationException
296+ * @throws \Flowpack\ElasticSearch\Exception
297+ * @throws \Neos\Flow\Http\Exception
280298 */
281- protected function createNextIndex ($ indexPostfix )
299+ protected function createNextIndex (string $ indexPostfix ): string
282300 {
283301 $ this ->nodeIndexer ->setIndexNamePostfix ($ indexPostfix );
284302 $ this ->nodeIndexer ->getIndex ()->create ();
285- $ this ->log (sprintf ('action=indexing step=index-created index=%s ' , $ this ->nodeIndexer ->getIndexName ()), LOG_INFO );
303+ $ this ->logger -> info (sprintf ('Index %s created ' , $ this ->nodeIndexer ->getIndexName ()), LogEnvironment:: fromMethodName ( __METHOD__ ) );
286304
287305 return $ this ->nodeIndexer ->getIndexName ();
288306 }
289307
290308 /**
291309 * Update Index Mapping
292310 *
311+ * @param string $indexPostfix
293312 * @return void
313+ * @throws ConfigurationException
294314 * @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
315+ * @throws \Flowpack\ElasticSearch\Exception
295316 */
296- protected function updateMapping ($ indexPostfix )
317+ protected function updateMapping (string $ indexPostfix ): void
297318 {
298319 $ nodeTypeMappingCollection = $ this ->nodeTypeMappingBuilder ->buildMappingInformation ($ this ->nodeIndexer ->getIndex ());
299320 foreach ($ nodeTypeMappingCollection as $ mapping ) {
300321 $ this ->nodeIndexer ->setIndexNamePostfix ($ indexPostfix );
301322 /** @var Mapping $mapping */
302323 $ mapping ->apply ();
303324 }
304- $ this ->log (sprintf ('action=indexing step=mapping- updated index= %s ' , $ this ->nodeIndexer ->getIndexName ()), LOG_INFO );
325+ $ this ->logger -> info (sprintf ('Mapping updated for index %s ' , $ this ->nodeIndexer ->getIndexName ()), LogEnvironment:: fromMethodName ( __METHOD__ ) );
305326 }
306327}
0 commit comments