| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the FOSElasticaBundle package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) FriendsOfSymfony <https://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 | 6 |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         IndexManager $indexManager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         Resetter $resetter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 6 |  |         parent::__construct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 6 |  |         $this->indexManager = $indexManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 6 |  |         $this->resetter = $resetter; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 39 | 6 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 6 |  |     protected function configure() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 6 |  |             ->setName('fos:elastica:reset') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 6 |  |             ->addOption('index', null, InputOption::VALUE_OPTIONAL, 'The index to reset') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 6 |  |             ->addOption('force', null, InputOption::VALUE_NONE, 'Force index deletion if same name as alias') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 6 |  |             ->setDescription('Reset search indexes') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         ; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 | 6 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 2 |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 2 |  |         $indexes = (null !== $index = $input->getOption('index')) ? [$index] : \array_keys($this->indexManager->getAllIndexes()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 2 |  |         $force = (bool) $input->getOption('force'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 2 |  |         foreach ($indexes as $index) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 2 |  |             $output->writeln(\sprintf('<info>Resetting</info> <comment>%s</comment>', $index)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 2 |  |             $this->resetter->resetIndex($index, false, $force); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 2 |  |         return 0; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 63 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |  |