11<?php
2+
3+ declare (strict_types=1 );
4+
25namespace Flowpack \ElasticSearch \ContentRepositoryAdaptor \Command ;
36
47/*
1114 * source code.
1215 */
1316
14- use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Driver \ NodeTypeMappingBuilderInterface ;
17+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Exception as CRAException ;
1518use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Indexer \Error \ErrorInterface ;
19+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Driver \NodeTypeMappingBuilderInterface ;
20+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Indexer \NodeIndexer ;
1621use Flowpack \ElasticSearch \ContentRepositoryAdaptor \LoggerInterface ;
1722use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Service \ErrorHandlingService ;
1823use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Service \IndexWorkspaceTrait ;
@@ -51,8 +56,7 @@ class NodeIndexCommandController extends CommandController
5156 protected $ errorHandlingService ;
5257
5358 /**
54- * @Flow\Inject
55- * @var NodeIndexerInterface
59+ * @var NodeIndexer
5660 */
5761 protected $ nodeIndexer ;
5862
@@ -103,13 +107,22 @@ class NodeIndexCommandController extends CommandController
103107 */
104108 protected $ settings ;
105109
110+ /**
111+ * @param NodeIndexerInterface $nodeIndexer
112+ * @return void
113+ */
114+ public function injectNodeIndexer (NodeIndexerInterface $ nodeIndexer ): void
115+ {
116+ $ this ->nodeIndexer = $ nodeIndexer ;
117+ }
118+
106119 /**
107120 * Called by the Flow object framework after creating the object and resolving all dependencies.
108121 *
109122 * @param integer $cause Creation cause
110123 * @throws InvalidConfigurationTypeException
111124 */
112- public function initializeObject ($ cause )
125+ public function initializeObject (int $ cause ): void
113126 {
114127 if ($ cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED ) {
115128 $ this ->settings = $ this ->configurationManager ->getConfiguration (ConfigurationManager::CONFIGURATION_TYPE_SETTINGS , 'Neos.ContentRepository.Search ' );
@@ -120,8 +133,9 @@ public function initializeObject($cause)
120133 * Show the mapping which would be sent to the ElasticSearch server
121134 *
122135 * @return void
136+ * @throws CRAException
123137 */
124- public function showMappingCommand ()
138+ public function showMappingCommand (): void
125139 {
126140 $ nodeTypeMappingCollection = $ this ->nodeTypeMappingBuilder ->buildMappingInformation ($ this ->nodeIndexer ->getIndex ());
127141 foreach ($ nodeTypeMappingCollection as $ mapping ) {
@@ -159,7 +173,7 @@ public function showMappingCommand()
159173 * @return void
160174 * @throws StopActionException
161175 */
162- public function indexNodeCommand ($ identifier , $ workspace = null )
176+ public function indexNodeCommand (string $ identifier , string $ workspace = null ): void
163177 {
164178 if ($ workspace === null && $ this ->settings ['indexAllWorkspaces ' ] === false ) {
165179 $ workspace = 'live ' ;
@@ -201,8 +215,8 @@ public function indexNodeCommand($identifier, $workspace = null)
201215 };
202216
203217 if ($ workspace === null ) {
204- foreach ($ this ->workspaceRepository ->findAll () as $ workspace ) {
205- $ indexInWorkspace ($ identifier , $ workspace );
218+ foreach ($ this ->workspaceRepository ->findAll () as $ workspaceToIndex ) {
219+ $ indexInWorkspace ($ identifier , $ workspaceToIndex );
206220 }
207221 } else {
208222 /** @var Workspace $workspaceInstance */
@@ -220,28 +234,30 @@ public function indexNodeCommand($identifier, $workspace = null)
220234 *
221235 * This command (re-)indexes all nodes contained in the content repository and sets the schema beforehand.
222236 *
223- * @param integer $limit Amount of nodes to index at maximum
224- * @param boolean $update if TRUE, do not throw away the index at the start. Should *only be used for development*.
237+ * @param int $limit Amount of nodes to index at maximum
238+ * @param bool $update if TRUE, do not throw away the index at the start. Should *only be used for development*.
225239 * @param string $workspace name of the workspace which should be indexed
226240 * @param string $postfix Index postfix, index with the same postfix will be deleted if exist
227241 * @return void
242+ * @throws ApiException
228243 * @throws StopActionException
244+ * @throws CRAException
229245 */
230- public function buildCommand ($ limit = null , $ update = false , $ workspace = null , $ postfix = '' )
246+ public function buildCommand (int $ limit = null , bool $ update = false , string $ workspace = null , string $ postfix = '' ): void
231247 {
232248 if ($ workspace !== null && $ this ->workspaceRepository ->findByIdentifier ($ workspace ) === null ) {
233249 $ this ->logger ->log ('The given workspace ( ' . $ workspace . ') does not exist. ' , LOG_ERR );
234250 $ this ->quit (1 );
235251 }
236252
237253 if ($ update === true ) {
238- $ this ->logger ->log ('!!! Update Mode (Development) active! ' , LOG_INFO );
254+ $ this ->logger ->log ('!!! Update Mode (Development) active! ' );
239255 } else {
240256 $ this ->createNewIndex ($ postfix );
241257 }
242258 $ this ->applyMapping ();
243259
244- $ this ->logger ->log (sprintf ('Indexing %snodes ... ' , ($ limit !== null ? 'the first ' . $ limit . ' ' : '' )), LOG_INFO );
260+ $ this ->logger ->log (sprintf ('Indexing %snodes ... ' , ($ limit !== null ? 'the first ' . $ limit . ' ' : '' )));
245261
246262 $ count = 0 ;
247263
@@ -257,8 +273,8 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
257273 }
258274 };
259275 if ($ workspace === null ) {
260- foreach ($ this ->workspaceRepository ->findAll () as $ workspace ) {
261- $ count += $ this ->indexWorkspace ($ workspace ->getName (), $ limit , $ callback );
276+ foreach ($ this ->workspaceRepository ->findAll () as $ workspaceToIndex ) {
277+ $ count += $ this ->indexWorkspace ($ workspaceToIndex ->getName (), $ limit , $ callback );
262278 }
263279 } else {
264280 $ count += $ this ->indexWorkspace ($ workspace , $ limit , $ callback );
@@ -289,8 +305,9 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
289305 * Clean up old indexes (i.e. all but the current one)
290306 *
291307 * @return void
308+ * @throws CRAException
292309 */
293- public function cleanupCommand ()
310+ public function cleanupCommand (): void
294311 {
295312 try {
296313 $ indicesToBeRemoved = $ this ->nodeIndexer ->removeOldIndices ();
@@ -316,30 +333,32 @@ public function cleanupCommand()
316333 *
317334 * @param string $postfix
318335 * @return void
336+ * @throws CRAException
319337 */
320- protected function createNewIndex (string $ postfix )
338+ protected function createNewIndex (string $ postfix ): void
321339 {
322- $ this ->nodeIndexer ->setIndexNamePostfix ($ postfix ?: time ());
340+ $ this ->nodeIndexer ->setIndexNamePostfix ($ postfix ?: ( string ) time ());
323341 if ($ this ->nodeIndexer ->getIndex ()->exists () === true ) {
324342 $ this ->logger ->log (sprintf ('Deleted index with the same postfix (%s)! ' , $ postfix ), LOG_WARNING );
325343 $ this ->nodeIndexer ->getIndex ()->delete ();
326344 }
327345 $ this ->nodeIndexer ->getIndex ()->create ();
328- $ this ->logger ->log ('Created index ' . $ this ->nodeIndexer ->getIndexName (), LOG_INFO );
346+ $ this ->logger ->log ('Created index ' . $ this ->nodeIndexer ->getIndexName ());
329347 }
330348
331349 /**
332350 * Apply the mapping to the current index.
333351 *
334352 * @return void
353+ * @throws CRAException
335354 */
336- protected function applyMapping ()
355+ protected function applyMapping (): void
337356 {
338357 $ nodeTypeMappingCollection = $ this ->nodeTypeMappingBuilder ->buildMappingInformation ($ this ->nodeIndexer ->getIndex ());
339358 foreach ($ nodeTypeMappingCollection as $ mapping ) {
340359 /** @var Mapping $mapping */
341360 $ mapping ->apply ();
342361 }
343- $ this ->logger ->log ('Updated Mapping. ' , LOG_INFO );
362+ $ this ->logger ->log ('Updated Mapping. ' );
344363 }
345364}
0 commit comments