| Total Complexity | 4 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | final class CreateWriteIndex |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var ImportSource |
||
| 19 | */ |
||
| 20 | private $source; |
||
| 21 | /** |
||
| 22 | * @var Index |
||
| 23 | */ |
||
| 24 | private $index; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param ImportSource $source |
||
| 28 | * @param Index $index |
||
| 29 | */ |
||
| 30 | 16 | public function __construct(ImportSource $source, Index $index) |
|
| 31 | { |
||
| 32 | 16 | $this->source = $source; |
|
| 33 | 16 | $this->index = $index; |
|
| 34 | 16 | } |
|
| 35 | |||
| 36 | 14 | public function handle(Client $elasticsearch): void |
|
| 37 | { |
||
| 38 | 14 | $source = $this->source; |
|
| 39 | 14 | $this->index->addAlias(new WriteAlias(new DefaultAlias($source->searchableAs()))); |
|
| 40 | |||
| 41 | 14 | $params = new Create( |
|
| 42 | 14 | $this->index->name(), |
|
| 43 | 14 | $this->index->config() |
|
| 44 | ); |
||
| 45 | |||
| 46 | 14 | $elasticsearch->indices()->create($params->toArray()); |
|
| 47 | 14 | } |
|
| 48 | |||
| 49 | 13 | public function title(): string |
|
| 50 | { |
||
| 51 | 13 | return 'Create write index'; |
|
| 52 | } |
||
| 53 | |||
| 54 | 13 | public function estimate(): int |
|
| 57 | } |
||
| 58 | } |
||
| 59 |