1 | <?php |
||||
2 | namespace Triadev\Es\Console\Commands\Index; |
||||
3 | |||||
4 | use Triadev\Es\Business\Config\ConfigFacade; |
||||
5 | use Triadev\Es\Contract\ElasticsearchIndexContract; |
||||
6 | use Triadev\Es\Exception\Index\IndexNotFoundException; |
||||
7 | use Illuminate\Console\Command; |
||||
8 | use Log; |
||||
9 | |||||
10 | class Delete extends Command |
||||
11 | { |
||||
12 | use ConfigFacade; |
||||
13 | |||||
14 | /** |
||||
15 | * The name and signature of the console command. |
||||
16 | * |
||||
17 | * @var string |
||||
18 | */ |
||||
19 | protected $signature = 'triadev:es:index:delete |
||||
20 | {index : Index (_all for all)} |
||||
21 | {version : Version}'; |
||||
22 | |||||
23 | /** |
||||
24 | * The console command description. |
||||
25 | * |
||||
26 | * @var string |
||||
27 | */ |
||||
28 | protected $description = 'Delete one or more indices.'; |
||||
29 | |||||
30 | /** |
||||
31 | * Execute the console command. |
||||
32 | * |
||||
33 | * @param ElasticsearchIndexContract $elasticsearchAlias |
||||
34 | */ |
||||
35 | 1 | public function handle(ElasticsearchIndexContract $elasticsearchAlias) |
|||
36 | { |
||||
37 | 1 | $version = $this->argument('version'); |
|||
38 | |||||
39 | 1 | $indices = $this->getIndices(); |
|||
40 | |||||
41 | 1 | if ($this->argument('index') == '_all') { |
|||
42 | $index = array_keys($indices); |
||||
43 | } else { |
||||
44 | 1 | $index = explode(',', $this->argument('index')); |
|||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
45 | } |
||||
46 | |||||
47 | try { |
||||
48 | 1 | $result = $elasticsearchAlias->deleteIndex($index, $version); |
|||
0 ignored issues
–
show
It seems like
$version can also be of type string[] ; however, parameter $version of Triadev\Es\Contract\Elas...Contract::deleteIndex() does only seem to accept null|string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
49 | |||||
50 | 1 | Log::info('The indices could be deleted.', $result); |
|||
51 | } catch (IndexNotFoundException $e) { |
||||
52 | Log::error("The indices could not be found.", $index); |
||||
53 | } catch (\Exception $e) { |
||||
54 | Log::error(sprintf( |
||||
55 | "The indices could not be deleted: %s", |
||||
56 | $e->getMessage() |
||||
57 | ), $index); |
||||
58 | } |
||||
59 | 1 | } |
|||
60 | } |
||||
61 |