@@ -177,17 +177,25 @@ protected function isAliasExists($name)
177177 }
178178
179179 /**
180- * @param string $name
180+ * @param $name
181+ * @return array
181182 */
182- protected function deleteAlias ($ name )
183+ protected function getAlias ($ name )
183184 {
184- $ indices = ElasticClient::indices ();
185-
186185 $ getPayload = (new RawPayload ())
187186 ->set ('name ' , $ name )
188187 ->get ();
189188
190- $ aliases = $ indices ->getAlias ($ getPayload );
189+ return ElasticClient::indices ()
190+ ->getAlias ($ getPayload );
191+ }
192+
193+ /**
194+ * @param string $name
195+ */
196+ protected function deleteAlias ($ name )
197+ {
198+ $ aliases = $ this ->getAlias ($ name );
191199
192200 if (empty ($ aliases )) {
193201 return ;
@@ -199,7 +207,8 @@ protected function deleteAlias($name)
199207 ->set ('name ' , $ name )
200208 ->get ();
201209
202- $ indices ->deleteAlias ($ deletePayload );
210+ ElasticClient::indices ()
211+ ->deleteAlias ($ deletePayload );
203212
204213 $ this ->info (sprintf (
205214 'The %s alias for the %s index was deleted. ' ,
@@ -247,19 +256,38 @@ protected function importDocumentsToTargetIndex()
247256
248257 protected function deleteSourceIndex ()
249258 {
250- $ sourceIndexConfigurator = $ this ->getModel ()
259+ $ sourceIndexConfigurator = $ this
260+ ->getModel ()
251261 ->getIndexConfigurator ();
252262
253- $ payload = ( new IndexPayload ($ sourceIndexConfigurator))
254- -> get ( );
263+ if ( $ this -> isAliasExists ($ sourceIndexConfigurator-> getName ())) {
264+ $ aliases = $ this -> getAlias ( $ sourceIndexConfigurator -> getName () );
255265
256- ElasticClient::indices ()
257- ->delete ($ payload );
266+ foreach ($ aliases as $ index => $ alias ) {
267+ $ payload = (new RawPayload ())
268+ ->set ('index ' , $ index )
269+ ->get ();
258270
259- $ this ->info (sprintf (
260- 'The %s index was removed. ' ,
261- $ sourceIndexConfigurator ->getName ()
262- ));
271+ ElasticClient::indices ()
272+ ->delete ($ payload );
273+
274+ $ this ->info (sprintf (
275+ 'The %s index was removed. ' ,
276+ $ index
277+ ));
278+ }
279+ } else {
280+ $ payload = (new IndexPayload ($ sourceIndexConfigurator ))
281+ ->get ();
282+
283+ ElasticClient::indices ()
284+ ->delete ($ payload );
285+
286+ $ this ->info (sprintf (
287+ 'The %s index was removed. ' ,
288+ $ sourceIndexConfigurator ->getName ()
289+ ));
290+ }
263291 }
264292
265293 public function handle ()
0 commit comments