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