Total Complexity | 6 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
15 | final class SwitchToNewAndRemoveOldIndex |
||
16 | { |
||
17 | /** |
||
18 | * @var Model |
||
19 | */ |
||
20 | private $searchable; |
||
21 | /** |
||
22 | * @var Index |
||
23 | */ |
||
24 | private $index; |
||
25 | |||
26 | /** |
||
27 | * @param Model $searchable |
||
28 | */ |
||
29 | 10 | public function __construct(Model $searchable, Index $index) |
|
33 | 10 | } |
|
34 | |||
35 | 9 | public function handle(Client $elasticsearch): void |
|
36 | { |
||
37 | /** @var Searchable $searchable */ |
||
38 | 9 | $searchable = $this->searchable; |
|
39 | 9 | $params = Get::anyIndex($searchable->searchableAs()); |
|
40 | 9 | $response = $elasticsearch->indices()->getAliases($params->toArray()); |
|
41 | |||
42 | 9 | $params = new Update(); |
|
43 | 9 | foreach ($response as $indexName => $alias) { |
|
44 | 9 | if ($indexName != $this->index->name()) { |
|
45 | 2 | $params->removeIndex($indexName); |
|
46 | } else { |
||
47 | 9 | $params->add((string) $indexName, $searchable->searchableAs()); |
|
48 | } |
||
49 | } |
||
50 | 9 | $elasticsearch->indices()->updateAliases($params->toArray()); |
|
51 | 9 | } |
|
52 | |||
53 | 8 | public function estimate(): int |
|
56 | } |
||
57 | |||
58 | 8 | public function title(): string |
|
61 | } |
||
62 | } |
||
63 |