From 813f57e3d06a58abea9605bb297f199682f86b3e Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Fri, 26 Apr 2013 14:15:57 +0200 Subject: [PATCH] added purge command --- Command/PurgeCommand.php | 78 ++++++++++++++++++++++++++++++++++ Doctrine/RepositoryManager.php | 2 +- Manager/RepositoryManager.php | 2 +- Repository.php | 2 +- 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100755 Command/PurgeCommand.php diff --git a/Command/PurgeCommand.php b/Command/PurgeCommand.php new file mode 100755 index 0000000..3f5fa00 --- /dev/null +++ b/Command/PurgeCommand.php @@ -0,0 +1,78 @@ +setName('fos:elastica:purge') + ->addOption('index', null, InputOption::VALUE_OPTIONAL, 'The index to purge') + ->addOption('type', null, InputOption::VALUE_OPTIONAL, 'The type to purge') + ->setDescription('Purge 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'); + + 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->resetIndex($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); + } + } + } +} diff --git a/Doctrine/RepositoryManager.php b/Doctrine/RepositoryManager.php index 8224ffb..6ba6bf5 100644 --- a/Doctrine/RepositoryManager.php +++ b/Doctrine/RepositoryManager.php @@ -28,7 +28,7 @@ class RepositoryManager extends BaseManager * Return repository for entity * * Returns custom repository if one specified otherwise - * returns a basic respository. + * returns a basic repository. */ public function getRepository($entityName) { diff --git a/Manager/RepositoryManager.php b/Manager/RepositoryManager.php index 7701ec9..6459c19 100644 --- a/Manager/RepositoryManager.php +++ b/Manager/RepositoryManager.php @@ -33,7 +33,7 @@ class RepositoryManager implements RepositoryManagerInterface * Return repository for entity * * Returns custom repository if one specified otherwise - * returns a basic respository. + * returns a basic repository. */ public function getRepository($entityName) { diff --git a/Repository.php b/Repository.php index dde07c6..413f1e4 100644 --- a/Repository.php +++ b/Repository.php @@ -7,7 +7,7 @@ use FOS\ElasticaBundle\Finder\PaginatedFinderInterface; /** * @author Richard Miller * - * Basic respoitory to be extended to hold custom queries to be run + * Basic repository to be extended to hold custom queries to be run * in the finder. */ class Repository