4
4
5
5
use Illuminate \Console \Command ;
6
6
use ScoutElastic \Facades \ElasticClient ;
7
- use ScoutElastic \Payloads \IndexPayload ;
7
+ use ScoutElastic \IndexConfigurator ;
8
+ use ScoutElastic \Migratable ;
8
9
use ScoutElastic \Console \Features \RequiresIndexConfiguratorArgument ;
10
+ use ScoutElastic \Payloads \RawPayload ;
9
11
10
12
class ElasticIndexDropCommand extends Command
11
13
{
@@ -29,16 +31,38 @@ class ElasticIndexDropCommand extends Command
29
31
public function handle ()
30
32
{
31
33
$ configurator = $ this ->getIndexConfigurator ();
34
+ $ indexName = $ this ->resolveIndexName ($ configurator );
32
35
33
- $ payload = (new IndexPayload ($ configurator ))
36
+ $ payload = (new RawPayload ())
37
+ ->set ('index ' , $ indexName )
34
38
->get ();
35
39
36
40
ElasticClient::indices ()
37
41
->delete ($ payload );
38
42
39
43
$ this ->info (sprintf (
40
44
'The index %s was deleted! ' ,
41
- $ configurator -> getName ()
45
+ $ indexName
42
46
));
43
47
}
48
+
49
+ /**
50
+ * @param IndexConfigurator $configurator
51
+ * @return string
52
+ */
53
+ protected function resolveIndexName ($ configurator )
54
+ {
55
+ if (in_array (Migratable::class, class_uses_recursive ($ configurator ))) {
56
+ $ payload = (new RawPayload ())
57
+ ->set ('name ' , $ configurator ->getWriteAlias ())
58
+ ->get ();
59
+
60
+ $ aliases = ElasticClient::indices ()
61
+ ->getAlias ($ payload );
62
+
63
+ return key ($ aliases );
64
+ } else {
65
+ return $ configurator ->getName ();
66
+ }
67
+ }
44
68
}
0 commit comments