|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace Spameri\Elastic\Commands; |
| 4 | + |
| 5 | + |
| 6 | +class TypeToNewIndex extends \Symfony\Component\Console\Command\Command |
| 7 | +{ |
| 8 | + |
| 9 | + /** |
| 10 | + * @var \Spameri\Elastic\Model\TypeToNewIndex\Migrate |
| 11 | + */ |
| 12 | + private $migrate; |
| 13 | + |
| 14 | + |
| 15 | + public function __construct( |
| 16 | + \Spameri\Elastic\Model\TypeToNewIndex\Migrate $migrate |
| 17 | + ) |
| 18 | + { |
| 19 | + parent::__construct(NULL); |
| 20 | + $this->migrate = $migrate; |
| 21 | + } |
| 22 | + |
| 23 | + |
| 24 | + /** |
| 25 | + * @example spameri:elastic:move-type oldIndex productType newIndex newIndexAlias -c |
| 26 | + */ |
| 27 | + protected function configure() : void |
| 28 | + { |
| 29 | + $this |
| 30 | + ->setName('spameri:elastic:move-type') |
| 31 | + ->setDescription('Move type to new index to separate data and prepare for deprecation of types is ES.') |
| 32 | + ->addArgument('indexFrom', \Symfony\Component\Console\Input\InputArgument::REQUIRED) |
| 33 | + ->addArgument('typeFrom', \Symfony\Component\Console\Input\InputArgument::REQUIRED) |
| 34 | + ->addArgument('indexTo', \Symfony\Component\Console\Input\InputArgument::REQUIRED) |
| 35 | + ->addArgument('aliasTo', \Symfony\Component\Console\Input\InputArgument::REQUIRED) |
| 36 | + ->addOption('allowClose', 'c', NULL, |
| 37 | + 'Allows command to close index for data transfer. After data is transferred index is opened and resumes normal operations. When open it needs to check changed files after move and sync remaining.', |
| 38 | + TRUE |
| 39 | + ) |
| 40 | + ; |
| 41 | + } |
| 42 | + |
| 43 | + protected function execute( |
| 44 | + \Symfony\Component\Console\Input\InputInterface $input |
| 45 | + , \Symfony\Component\Console\Output\OutputInterface $output |
| 46 | + ) |
| 47 | + { |
| 48 | + $output->writeln('Starting'); |
| 49 | + |
| 50 | + $indexFrom = $input->getArgument('indexFrom'); |
| 51 | + $typeFrom = $input->getArgument('typeFrom'); |
| 52 | + $indexTo = $input->getArgument('indexTo'); |
| 53 | + $aliasTo = $input->getArgument('aliasTo'); |
| 54 | + $allowClose = $input->getOption('allowClose'); |
| 55 | + |
| 56 | + $this->migrate->setOutput($output); |
| 57 | + $this->migrate->execute($indexFrom, $typeFrom, $indexTo, $aliasTo, $allowClose); |
| 58 | + |
| 59 | + $output->writeln('Done'); |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments