1 | <?php |
||
2 | namespace Triadev\Es\Console\Commands\Version; |
||
3 | |||
4 | use Triadev\Es\Contract\ElasticsearchAliasContract; |
||
5 | use Triadev\Es\Contract\ElasticsearchIndexContract; |
||
6 | use Illuminate\Console\Command; |
||
7 | |||
8 | class Overview extends Command |
||
9 | { |
||
10 | /** |
||
11 | * The name and signature of the console command. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $signature = 'triadev:es:version:overview |
||
16 | {index : Index}'; |
||
17 | |||
18 | /** |
||
19 | * The console command description. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $description = 'Get an overview of the version of an index.'; |
||
24 | |||
25 | /** |
||
26 | * Execute the console command. |
||
27 | * |
||
28 | * @param ElasticsearchIndexContract $elasticsearchIndex |
||
29 | * @param ElasticsearchAliasContract $elasticsearchAlias |
||
30 | */ |
||
31 | 1 | public function handle( |
|
32 | ElasticsearchIndexContract $elasticsearchIndex, |
||
33 | ElasticsearchAliasContract $elasticsearchAlias |
||
34 | ) { |
||
35 | 1 | $indices = $elasticsearchIndex->getVersionedIndices($this->argument('index')); |
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
36 | |||
37 | 1 | $headers = ['Name', 'Version', 'Active']; |
|
38 | |||
39 | 1 | $rows = []; |
|
40 | |||
41 | 1 | foreach ($indices as $index) { |
|
42 | 1 | if (preg_match('/(?<name>[a-z]+)_(?<version>[0-9]+.[0-9]+.[0-9]+)/', $index, $matches)) { |
|
43 | 1 | $rows[$matches['version']] = [ |
|
44 | 1 | $matches['name'], |
|
45 | 1 | $matches['version'], |
|
46 | 1 | $elasticsearchAlias->existAlias( |
|
47 | 1 | [$matches['name']], |
|
48 | 1 | [$matches['name']], |
|
49 | 1 | $matches['version'] |
|
50 | 1 | ) ? 'true' : 'false' |
|
51 | ]; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | 1 | $this->table($headers, $rows); |
|
56 | 1 | } |
|
57 | } |
||
58 |