| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the FOSElasticaBundle package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace FOS\ElasticaBundle\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use FOS\ElasticaBundle\Index\IndexManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use FOS\ElasticaBundle\Index\Resetter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Symfony\Component\Console\Command\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Symfony\Component\Console\Input\InputOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * Reset search indexes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | class ResetCommand extends Command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     protected static $defaultName = 'fos:elastica:reset'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     private $indexManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     private $resetter; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     public function __construct( | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         IndexManager $indexManager, | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         Resetter $resetter | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         parent::__construct(); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         $this->indexManager = $indexManager; | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         $this->resetter = $resetter; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     protected function configure() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 3 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 3 |  |         $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 3 |  |             ->setName('fos:elastica:reset') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 3 |  |             ->addOption('index', null, InputOption::VALUE_OPTIONAL, 'The index to reset') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 3 |  |             ->addOption('type', null, InputOption::VALUE_OPTIONAL, 'The type to reset') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             ->addOption('force', null, InputOption::VALUE_NONE, 'Force index deletion if same name as alias') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 3 |  |             ->setDescription('Reset search indexes') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 3 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $index = $input->getOption('index'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 3 |  |         $type = $input->getOption('type'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 3 |  |         $force = (bool) $input->getOption('force'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 3 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         if (null === $index && null !== $type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             throw new \InvalidArgumentException('Cannot specify type option without an index.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 3 |  |         if (null !== $type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             $output->writeln(sprintf('<info>Resetting</info> <comment>%s/%s</comment>', $index, $type)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 3 |  |             $this->resetter->resetIndexType($index, $type); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 3 |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 3 |  |             $indexes = null === $index | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 ? array_keys($this->indexManager->getAllIndexes()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 3 |  |                 : [$index] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             foreach ($indexes as $index) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 3 |  |                 $output->writeln(sprintf('<info>Resetting</info> <comment>%s</comment>', $index)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 1 |  |                 $this->resetter->resetIndex($index, false, $force); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 1 |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 2 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |  |