|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Apisearch Bundle. |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + * |
| 9 | + * Feel free to edit as you please, and have fun. |
| 10 | + * |
| 11 | + * @author Marc Morera <yuhu@mmoreram.com> |
| 12 | + */ |
| 13 | + |
| 14 | +declare(strict_types=1); |
| 15 | + |
| 16 | +namespace Apisearch\Command; |
| 17 | + |
| 18 | +use Apisearch\Model\Index; |
| 19 | +use Symfony\Component\Console\Helper\Table; |
| 20 | +use Symfony\Component\Console\Input\InputArgument; |
| 21 | +use Symfony\Component\Console\Input\InputInterface; |
| 22 | +use Symfony\Component\Console\Output\OutputInterface; |
| 23 | + |
| 24 | +/** |
| 25 | + * Class PrintIndicesCommand. |
| 26 | + */ |
| 27 | +class PrintIndicesCommand extends WithAppRepositoryBucketCommand |
| 28 | +{ |
| 29 | + /** |
| 30 | + * Configures the current command. |
| 31 | + */ |
| 32 | + protected function configure() |
| 33 | + { |
| 34 | + $this |
| 35 | + ->setName('apisearch:print-indices') |
| 36 | + ->setDescription('Print all indices') |
| 37 | + ->addArgument( |
| 38 | + 'app-name', |
| 39 | + InputArgument::REQUIRED, |
| 40 | + 'App name' |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Dispatch domain event. |
| 46 | + * |
| 47 | + * @param InputInterface $input |
| 48 | + * @param OutputInterface $output |
| 49 | + * |
| 50 | + * @return mixed|null |
| 51 | + */ |
| 52 | + protected function runCommand(InputInterface $input, OutputInterface $output) |
| 53 | + { |
| 54 | + $appName = $input->getArgument('app-name'); |
| 55 | + $indices = $this |
| 56 | + ->repositoryBucket |
| 57 | + ->findRepository($appName) |
| 58 | + ->getIndices(); |
| 59 | + |
| 60 | + $table = new Table($output); |
| 61 | + $table->setHeaders(['UUID', 'App Id', 'Is Ok?', 'Doc Count', 'Size']); |
| 62 | + /** |
| 63 | + * @var Index $index |
| 64 | + */ |
| 65 | + foreach ($indices as $index) { |
| 66 | + $table->addRow([ |
| 67 | + $index->getUUID()->composeUUID(), |
| 68 | + $index->getAppUUID()->composeUUID(), |
| 69 | + $index->isOK() ? 'Yes' : 'No', |
| 70 | + $index->getDocCount(), |
| 71 | + $index->getSize(), |
| 72 | + ]); |
| 73 | + } |
| 74 | + $table->render(); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Dispatch domain event. |
| 79 | + * |
| 80 | + * @return string |
| 81 | + */ |
| 82 | + protected function getHeader(): string |
| 83 | + { |
| 84 | + return 'Print indices'; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Get success message. |
| 89 | + * |
| 90 | + * @param InputInterface $input |
| 91 | + * @param mixed $result |
| 92 | + * |
| 93 | + * @return string |
| 94 | + */ |
| 95 | + protected function getSuccessMessage( |
| 96 | + InputInterface $input, |
| 97 | + $result |
| 98 | + ): string { |
| 99 | + return ''; |
| 100 | + } |
| 101 | +} |
0 commit comments