2013-04-26 14:15:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FOS\ElasticaBundle\Command;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use FOS\ElasticaBundle\IndexManager;
|
|
|
|
use FOS\ElasticaBundle\Resetter;
|
|
|
|
|
|
|
|
/**
|
2015-03-12 11:20:00 +01:00
|
|
|
* Reset search indexes.
|
2013-04-26 14:15:57 +02:00
|
|
|
*/
|
2013-05-08 09:10:40 +02:00
|
|
|
class ResetCommand extends ContainerAwareCommand
|
2013-04-26 14:15:57 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var IndexManager
|
|
|
|
*/
|
|
|
|
private $indexManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Resetter
|
|
|
|
*/
|
|
|
|
private $resetter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Symfony\Component\Console\Command\Command::configure()
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
2013-05-08 09:10:40 +02:00
|
|
|
->setName('fos:elastica:reset')
|
|
|
|
->addOption('index', null, InputOption::VALUE_OPTIONAL, 'The index to reset')
|
|
|
|
->addOption('type', null, InputOption::VALUE_OPTIONAL, 'The type to reset')
|
2014-08-28 18:59:58 +02:00
|
|
|
->addOption('force', null, InputOption::VALUE_NONE, 'Force index deletion if same name as alias')
|
2013-05-08 09:10:40 +02:00
|
|
|
->setDescription('Reset search indexes')
|
2013-04-26 14:15:57 +02:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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)
|
|
|
|
{
|
2014-09-04 01:26:53 +02:00
|
|
|
$index = $input->getOption('index');
|
|
|
|
$type = $input->getOption('type');
|
|
|
|
$force = (bool) $input->getOption('force');
|
2013-04-26 14:15:57 +02:00
|
|
|
|
|
|
|
if (null === $index && null !== $type) {
|
|
|
|
throw new \InvalidArgumentException('Cannot specify type option without an index.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null !== $type) {
|
2013-06-18 09:52:44 +02:00
|
|
|
$output->writeln(sprintf('<info>Resetting</info> <comment>%s/%s</comment>', $index, $type));
|
2013-12-16 11:58:58 +01:00
|
|
|
$this->resetter->resetIndexType($index, $type);
|
2013-04-26 14:15:57 +02:00
|
|
|
} else {
|
|
|
|
$indexes = null === $index
|
|
|
|
? array_keys($this->indexManager->getAllIndexes())
|
|
|
|
: array($index)
|
|
|
|
;
|
|
|
|
|
|
|
|
foreach ($indexes as $index) {
|
|
|
|
$output->writeln(sprintf('<info>Resetting</info> <comment>%s</comment>', $index));
|
2014-08-28 18:59:58 +02:00
|
|
|
$this->resetter->resetIndex($index, false, $force);
|
2013-04-26 14:15:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|