| Conditions | 4 |
| Paths | 4 |
| Total Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | public function handle(): int |
||
| 33 | { |
||
| 34 | $indexName = $this->argument('index-name'); |
||
| 35 | |||
| 36 | if (!$this->argumentIsValid($indexName)) { |
||
| 37 | return self::FAILURE; |
||
| 38 | } |
||
| 39 | |||
| 40 | if (!$this->client->indices()->exists([ |
||
| 41 | 'index' => $indexName, |
||
| 42 | ])) { |
||
| 43 | $this->output->writeln( |
||
| 44 | sprintf( |
||
| 45 | '<error>Index %s doesn\'t exists and cannot be deleted.</error>', |
||
| 46 | $indexName |
||
| 47 | ) |
||
| 48 | ); |
||
| 49 | |||
| 50 | return self::FAILURE; |
||
| 51 | } |
||
| 52 | |||
| 53 | try { |
||
| 54 | $this->client->indices()->delete([ |
||
| 55 | 'index' => $this->argument('index-name'), |
||
| 56 | ]); |
||
| 57 | } catch (Throwable $exception) { |
||
| 58 | $this->output->writeln( |
||
| 59 | sprintf( |
||
| 60 | '<error>Error deleting index %s, exception message: %s.</error>', |
||
| 61 | $indexName, |
||
| 62 | $exception->getMessage() |
||
| 63 | ) |
||
| 64 | ); |
||
| 65 | |||
| 66 | return self::FAILURE; |
||
| 67 | } |
||
| 68 | |||
| 69 | $this->output->writeln( |
||
| 70 | sprintf( |
||
| 71 | '<info>Index %s deleted.</info>', |
||
| 72 | $indexName |
||
| 73 | ) |
||
| 74 | ); |
||
| 75 | |||
| 76 | return self::SUCCESS; |
||
| 77 | } |
||
| 78 | |||
| 95 |