setName('fos:elastica:reset') ->addOption('index', null, InputOption::VALUE_OPTIONAL, 'The index to reset') ->addOption('type', null, InputOption::VALUE_OPTIONAL, 'The type to reset') ->addOption('force', null, InputOption::VALUE_NONE, 'Force index deletion if same name as alias') ->setDescription('Reset search indexes') ; } /** * @see Symfony\Component\Console\Command\Command::initialize() */ protected function initialize(InputInterface $input, OutputInterface $output) { $this->indexManager = $this->getContainer()->get('fos_elastica.index_manager'); $this->resetter = $this->getContainer()->get('fos_elastica.resetter'); } /** * @see Symfony\Component\Console\Command\Command::execute() */ protected function execute(InputInterface $input, OutputInterface $output) { $index = $input->getOption('index'); $type = $input->getOption('type'); $force = (bool) $input->getOption('force'); if (null === $index && null !== $type) { throw new \InvalidArgumentException('Cannot specify type option without an index.'); } if (null !== $type) { $output->writeln(sprintf('Resetting %s/%s', $index, $type)); $this->resetter->resetIndexType($index, $type); } else { $indexes = null === $index ? array_keys($this->indexManager->getAllIndexes()) : array($index) ; foreach ($indexes as $index) { $output->writeln(sprintf('Resetting %s', $index)); $this->resetter->resetIndex($index, false, $force); } } } }