1212 */
1313
1414use Flowpack \ElasticSearch \Annotations \Indexable ;
15+ use Flowpack \ElasticSearch \Domain \Factory \ClientFactory ;
1516use Flowpack \ElasticSearch \Domain \Model \Client ;
1617use Flowpack \ElasticSearch \Domain \Model \Index ;
18+ use Flowpack \ElasticSearch \Indexer \Object \IndexInformer ;
1719use Flowpack \ElasticSearch \Indexer \Object \ObjectIndexer ;
18- use Neos \Flow \Annotations as Flow ;
1920use Neos \Error \Messages \Error ;
2021use Neos \Error \Messages \Result as ErrorResult ;
22+ use Neos \Flow \Annotations as Flow ;
23+ use Neos \Flow \Cli \CommandController ;
2124use Neos \Flow \Exception ;
25+ use Neos \Flow \Persistence \PersistenceManagerInterface ;
2226
2327/**
2428 * Provides CLI features for index handling
2529 *
2630 * @Flow\Scope("singleton")
2731 */
28- class IndexCommandController extends \ Neos \ Flow \ Cli \ CommandController
32+ class IndexCommandController extends CommandController
2933{
3034 /**
3135 * @Flow\Inject
32- * @var \Flowpack\ElasticSearch\Domain\Factory\ ClientFactory
36+ * @var ClientFactory
3337 */
3438 protected $ clientFactory ;
3539
3640 /**
3741 * @Flow\Inject
38- * @var \Flowpack\ElasticSearch\Indexer\Object\ IndexInformer
42+ * @var IndexInformer
3943 */
4044 protected $ indexInformer ;
4145
4246 /**
4347 * @Flow\Inject
44- * @var \Neos\Flow\Persistence\ PersistenceManagerInterface
48+ * @var PersistenceManagerInterface
4549 */
4650 protected $ persistenceManager ;
4751
4852 /**
4953 * @Flow\Inject
50- * @var \Flowpack\ElasticSearch\Indexer\Object\ ObjectIndexer
54+ * @var ObjectIndexer
5155 */
5256 protected $ objectIndexer ;
5357
@@ -61,21 +65,21 @@ class IndexCommandController extends \Neos\Flow\Cli\CommandController
6165 public function createCommand ($ indexName , $ clientName = null )
6266 {
6367 if (!in_array ($ indexName , $ this ->indexInformer ->getAllIndexNames ())) {
64- $ this ->outputFormatted ("The index <b>%s</b> is not configured in the current application " , array ( $ indexName) );
68+ $ this ->outputFormatted ("The index <b>%s</b> is not configured in the current application " , [ $ indexName] );
6569 $ this ->quit (1 );
6670 }
6771
6872 $ client = $ this ->clientFactory ->create ($ clientName );
6973 try {
7074 $ index = new Index ($ indexName , $ client );
7175 if ($ index ->exists ()) {
72- $ this ->outputFormatted ("The index <b>%s</b> exists " , array ( $ indexName) );
76+ $ this ->outputFormatted ("The index <b>%s</b> exists " , [ $ indexName] );
7377 $ this ->quit (1 );
7478 }
7579 $ index ->create ();
76- $ this ->outputFormatted ("Index <b>%s</b> created with success " , array ( $ indexName) );
80+ $ this ->outputFormatted ("Index <b>%s</b> created with success " , [ $ indexName] );
7781 } catch (Exception $ exception ) {
78- $ this ->outputFormatted ("Unable to create an index named: <b>%s</b> " , array ( $ indexName) );
82+ $ this ->outputFormatted ("Unable to create an index named: <b>%s</b> " , [ $ indexName] );
7983 $ this ->quit (1 );
8084 }
8185 }
@@ -90,21 +94,21 @@ public function createCommand($indexName, $clientName = null)
9094 public function updateSettingsCommand ($ indexName , $ clientName = null )
9195 {
9296 if (!in_array ($ indexName , $ this ->indexInformer ->getAllIndexNames ())) {
93- $ this ->outputFormatted ("The index <b>%s</b> is not configured in the current application " , array ( $ indexName) );
97+ $ this ->outputFormatted ("The index <b>%s</b> is not configured in the current application " , [ $ indexName] );
9498 $ this ->quit (1 );
9599 }
96100
97101 $ client = $ this ->clientFactory ->create ($ clientName );
98102 try {
99103 $ index = new Index ($ indexName , $ client );
100104 if (!$ index ->exists ()) {
101- $ this ->outputFormatted ("The index <b>%s</b> does not exists " , array ( $ indexName) );
105+ $ this ->outputFormatted ("The index <b>%s</b> does not exists " , [ $ indexName] );
102106 $ this ->quit (1 );
103107 }
104108 $ index ->updateSettings ();
105- $ this ->outputFormatted ("Index settings <b>%s</b> updated with success " , array ( $ indexName) );
109+ $ this ->outputFormatted ("Index settings <b>%s</b> updated with success " , [ $ indexName] );
106110 } catch (Exception $ exception ) {
107- $ this ->outputFormatted ("Unable to update settings for <b>%s</b> index " , array ( $ indexName) );
111+ $ this ->outputFormatted ("Unable to update settings for <b>%s</b> index " , [ $ indexName] );
108112 $ this ->quit (1 );
109113 }
110114 }
@@ -119,21 +123,21 @@ public function updateSettingsCommand($indexName, $clientName = null)
119123 public function deleteCommand ($ indexName , $ clientName = null )
120124 {
121125 if (!in_array ($ indexName , $ this ->indexInformer ->getAllIndexNames ())) {
122- $ this ->outputFormatted ("The index <b>%s</b> is not configured in the current application " , array ( $ indexName) );
126+ $ this ->outputFormatted ("The index <b>%s</b> is not configured in the current application " , [ $ indexName] );
123127 $ this ->quit (1 );
124128 }
125129
126130 $ client = $ this ->clientFactory ->create ($ clientName );
127131 try {
128132 $ index = new Index ($ indexName , $ client );
129133 if (!$ index ->exists ()) {
130- $ this ->outputFormatted ("The index <b>%s</b> does not exists " , array ( $ indexName) );
134+ $ this ->outputFormatted ("The index <b>%s</b> does not exists " , [ $ indexName] );
131135 $ this ->quit (1 );
132136 }
133137 $ index ->delete ();
134- $ this ->outputFormatted ("Index <b>%s</b> deleted with success " , array ( $ indexName) );
138+ $ this ->outputFormatted ("Index <b>%s</b> deleted with success " , [ $ indexName] );
135139 } catch (Exception $ exception ) {
136- $ this ->outputFormatted ("Unable to delete an index named: <b>%s</b> " , array ( $ indexName) );
140+ $ this ->outputFormatted ("Unable to delete an index named: <b>%s</b> " , [ $ indexName] );
137141 $ this ->quit (1 );
138142 }
139143 }
@@ -148,20 +152,20 @@ public function deleteCommand($indexName, $clientName = null)
148152 public function refreshCommand ($ indexName , $ clientName = null )
149153 {
150154 if (!in_array ($ indexName , $ this ->indexInformer ->getAllIndexNames ())) {
151- $ this ->outputFormatted ("The index <b>%s</b> is not configured in the current application " , array ( $ indexName) );
155+ $ this ->outputFormatted ("The index <b>%s</b> is not configured in the current application " , [ $ indexName] );
152156 }
153157
154158 $ client = $ this ->clientFactory ->create ($ clientName );
155159 try {
156160 $ index = new Index ($ indexName , $ client );
157161 if (!$ index ->exists ()) {
158- $ this ->outputFormatted ("The index <b>%s</b> does not exists " , array ( $ indexName) );
162+ $ this ->outputFormatted ("The index <b>%s</b> does not exists " , [ $ indexName] );
159163 $ this ->quit (1 );
160164 }
161165 $ index ->refresh ();
162- $ this ->outputFormatted ("Index <b>%s</b> refreshed with success " , array ( $ indexName) );
166+ $ this ->outputFormatted ("Index <b>%s</b> refreshed with success " , [ $ indexName] );
163167 } catch (Exception $ exception ) {
164- $ this ->outputFormatted ("Unable to refresh an index named: <b>%s</b> " , array ( $ indexName) );
168+ $ this ->outputFormatted ("Unable to refresh an index named: <b>%s</b> " , [ $ indexName] );
165169 $ this ->quit (1 );
166170 }
167171 }
@@ -175,9 +179,9 @@ public function showConfiguredTypesCommand()
175179 {
176180 $ classesAndAnnotations = $ this ->indexInformer ->getClassesAndAnnotations ();
177181 $ this ->outputFormatted ("<b>Available document type</b> " );
178- /** @var $annotation \Flowpack\ElasticSearch\Annotations\ Indexable */
182+ /** @var $annotation Indexable */
179183 foreach ($ classesAndAnnotations as $ className => $ annotation ) {
180- $ this ->outputFormatted ("%s " , array ( $ className) , 4 );
184+ $ this ->outputFormatted ("%s " , [ $ className] , 4 );
181185 }
182186 }
183187
@@ -198,27 +202,36 @@ public function statusCommand($object = null, $conductUpdate = false, $clientNam
198202 $ classesAndAnnotations = $ this ->indexInformer ->getClassesAndAnnotations ();
199203 if ($ object !== null ) {
200204 if (!isset ($ classesAndAnnotations [$ object ])) {
201- $ this ->outputFormatted ("Error: Object '<b>%s</b>' is not configured correctly, check the Indexable annotation. " , array ( $ object) );
205+ $ this ->outputFormatted ("Error: Object '<b>%s</b>' is not configured correctly, check the Indexable annotation. " , [ $ object] );
202206 $ this ->quit (1 );
203207 }
204- $ classesAndAnnotations = array ( $ object => $ classesAndAnnotations [$ object ]) ;
208+ $ classesAndAnnotations = [ $ object => $ classesAndAnnotations [$ object ]] ;
205209 }
206210 array_walk ($ classesAndAnnotations , function (Indexable $ annotation , $ className ) use ($ result , $ client , $ conductUpdate ) {
207- $ this ->outputFormatted ("Object \x1b[33m%s \x1b[0m " , array ($ className ), 4 );
208- $ this ->outputFormatted ("Index <b>%s</b> Type <b>%s</b> " , array ($ annotation ->indexName , $ annotation ->typeName ), 8 );
211+ $ this ->outputFormatted ("Object \x1b[33m%s \x1b[0m " , [$ className ], 4 );
212+ $ this ->outputFormatted ("Index <b>%s</b> Type <b>%s</b> " , [
213+ $ annotation ->indexName ,
214+ $ annotation ->typeName ,
215+ ], 8 );
209216 $ count = $ client ->findIndex ($ annotation ->indexName )->findType ($ annotation ->typeName )->count ();
210217 if ($ count === null ) {
211- $ result ->forProperty ($ className )->addError (new Error ('ElasticSearch was unable to retrieve a count for the type "%s" at index "%s". Probably these don \' exist. ' , 1340289921 , array ($ annotation ->typeName , $ annotation ->indexName )));
218+ $ result ->forProperty ($ className )->addError (new Error ('ElasticSearch was unable to retrieve a count for the type "%s" at index "%s". Probably these don \' exist. ' , 1340289921 , [
219+ $ annotation ->typeName ,
220+ $ annotation ->indexName ,
221+ ]));
212222 }
213- $ this ->outputFormatted ("Documents in Search: <b>%s</b> " , array ( $ count !== null ? $ count : "\x1b[41mError \x1b[0m " ) , 8 );
223+ $ this ->outputFormatted ("Documents in Search: <b>%s</b> " , [ $ count !== null ? $ count : "\x1b[41mError \x1b[0m " ] , 8 );
214224
215225 try {
216226 $ count = $ this ->persistenceManager ->createQueryForType ($ className )->count ();
217227 } catch (\Exception $ exception ) {
218228 $ count = null ;
219- $ result ->forProperty ($ className )->addError (new Error ('The persistence backend was unable to retrieve a count for the type "%s". The exception message was "%s". ' , 1340290088 , array ($ className , $ exception ->getMessage ())));
229+ $ result ->forProperty ($ className )->addError (new Error ('The persistence backend was unable to retrieve a count for the type "%s". The exception message was "%s". ' , 1340290088 , [
230+ $ className ,
231+ $ exception ->getMessage (),
232+ ]));
220233 }
221- $ this ->outputFormatted ("Documents in Persistence: <b>%s</b> " , array ( $ count !== null ? $ count : "\x1b[41mError \x1b[0m " ) , 8 );
234+ $ this ->outputFormatted ("Documents in Persistence: <b>%s</b> " , [ $ count !== null ? $ count : "\x1b[41mError \x1b[0m " ] , 8 );
222235 if (!$ result ->forProperty ($ className )->hasErrors ()) {
223236 $ states = $ this ->getModificationsNeededStatesAndIdentifiers ($ client , $ className );
224237 if ($ conductUpdate ) {
@@ -229,34 +242,37 @@ public function statusCommand($object = null, $conductUpdate = false, $clientNam
229242 $ this ->objectIndexer ->indexObject ($ this ->persistenceManager ->getObjectByIdentifier ($ identifier , $ className ));
230243 $ inserted ++;
231244 } catch (\Exception $ exception ) {
232- $ result ->forProperty ($ className )->addError (new Error ('An error occurred while trying to add an object to the ElasticSearch backend. The exception message was "%s". ' , 1340356330 , array ( $ exception ->getMessage ()) ));
245+ $ result ->forProperty ($ className )->addError (new Error ('An error occurred while trying to add an object to the ElasticSearch backend. The exception message was "%s". ' , 1340356330 , [ $ exception ->getMessage ()] ));
233246 }
234247 }
235248 foreach ($ states [ObjectIndexer::ACTION_TYPE_UPDATE ] as $ identifier ) {
236249 try {
237250 $ this ->objectIndexer ->indexObject ($ this ->persistenceManager ->getObjectByIdentifier ($ identifier , $ className ));
238251 $ updated ++;
239252 } catch (\Exception $ exception ) {
240- $ result ->forProperty ($ className )->addError (new Error ('An error occurred while trying to update an object to the ElasticSearch backend. The exception message was "%s". ' , 1340358590 , array ( $ exception ->getMessage ()) ));
253+ $ result ->forProperty ($ className )->addError (new Error ('An error occurred while trying to update an object to the ElasticSearch backend. The exception message was "%s". ' , 1340358590 , [ $ exception ->getMessage ()] ));
241254 }
242255 }
243- $ this ->outputFormatted ("Objects inserted: <b>%s</b> " , array ( $ inserted) , 8 );
244- $ this ->outputFormatted ("Objects updated: <b>%s</b> " , array ( $ updated) , 8 );
256+ $ this ->outputFormatted ("Objects inserted: <b>%s</b> " , [ $ inserted] , 8 );
257+ $ this ->outputFormatted ("Objects updated: <b>%s</b> " , [ $ updated] , 8 );
245258 } else {
246- $ this ->outputFormatted ("Modifications needed: <b>create</b> %d, <b>update</b> %d " , array (count ($ states [ObjectIndexer::ACTION_TYPE_CREATE ]), count ($ states [ObjectIndexer::ACTION_TYPE_UPDATE ])), 8 );
259+ $ this ->outputFormatted ("Modifications needed: <b>create</b> %d, <b>update</b> %d " , [
260+ count ($ states [ObjectIndexer::ACTION_TYPE_CREATE ]),
261+ count ($ states [ObjectIndexer::ACTION_TYPE_UPDATE ]),
262+ ], 8 );
247263 }
248264 }
249265 });
250266
251267 if ($ result ->hasErrors ()) {
252268 $ this ->outputLine ();
253269 $ this ->outputLine ('The following errors occurred: ' );
254- /** @var $error \Neos\Error\Messages\ Error */
270+ /** @var $error Error */
255271 foreach ($ result ->getFlattenedErrors () as $ className => $ errors ) {
256272 foreach ($ errors as $ error ) {
257273 $ this ->outputLine ();
258- $ this ->outputFormatted ("<b> \x1b[41mError \x1b[0m</b> for \x1b[33m%s \x1b[0m: " , array ( $ className) , 8 );
259- $ this ->outputFormatted ((string )$ error , array () , 4 );
274+ $ this ->outputFormatted ("<b> \x1b[41mError \x1b[0m</b> for \x1b[33m%s \x1b[0m: " , [ $ className] , 8 );
275+ $ this ->outputFormatted ((string )$ error , [] , 4 );
260276 }
261277 }
262278 }
@@ -270,11 +286,11 @@ public function statusCommand($object = null, $conductUpdate = false, $clientNam
270286 protected function getModificationsNeededStatesAndIdentifiers (Client $ client , $ className )
271287 {
272288 $ query = $ this ->persistenceManager ->createQueryForType ($ className );
273- $ states = array (
274- ObjectIndexer::ACTION_TYPE_CREATE => array () ,
275- ObjectIndexer::ACTION_TYPE_UPDATE => array () ,
276- ObjectIndexer::ACTION_TYPE_DELETE => array () ,
277- ) ;
289+ $ states = [
290+ ObjectIndexer::ACTION_TYPE_CREATE => [] ,
291+ ObjectIndexer::ACTION_TYPE_UPDATE => [] ,
292+ ObjectIndexer::ACTION_TYPE_DELETE => [] ,
293+ ] ;
278294 foreach ($ query ->execute () as $ object ) {
279295 $ state = $ this ->objectIndexer ->objectIndexActionRequired ($ object , $ client );
280296 $ states [$ state ][] = $ this ->persistenceManager ->getIdentifierByObject ($ object );
0 commit comments