| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Doctrine MongoDBBundle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * The code was originally distributed inside the Symfony framework. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * (c) Fabien Potencier <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * (c) Doctrine Project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | namespace Saxulum\DoctrineMongodbOdmCommands\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Symfony\Component\Console\Input\InputOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * Show information about mapped documents | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @author Benjamin Eberlei <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * @author Jonathan H. Wage <[email protected]> | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 26 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | class InfoDoctrineODMCommand extends DoctrineODMCommand | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     protected function configure() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             ->setName('doctrine:mongodb:mapping:info') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             ->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             ->setDescription('Show basic information about all mapped documents.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ->setHelp(<<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | The <info>doctrine:mongodb:mapping:info</info> shows basic information about which | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | documents exist and possibly if their mapping information contains errors or not. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |   <info>./app/console doctrine:mongodb:mapping:info</info> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | If you are using multiple document managers you can pick your choice with the <info>--dm</info> option: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |   <info>./app/console doctrine:mongodb:mapping:info --dm=default</info> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $documentManagerName = $input->getOption('dm') ? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $input->getOption('dm') : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             $this->getDefaultManagerName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         /* @var $documentManager \Doctrine\ODM\MongoDB\DocumentManager */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $documentManager = $this->getDocumentManager($documentManagerName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $documentClassNames = $documentManager->getConfiguration() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             ->getMetadataDriverImpl() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             ->getAllClassNames(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         if (!$documentClassNames) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             throw new \Exception( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 'You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles. '. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 'Create a class inside the Document namespace of any of your bundles and provide '. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                 'mapping information for it with Annotations directly in the classes doc blocks '. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 'or with XML/YAML in your bundles Resources/config/doctrine/metadata/mongodb directory.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $output->write(sprintf("Found <info>%d</info> documents mapped in document manager <info>%s</info>:\n", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             count($documentClassNames), $documentManagerName), true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         foreach ($documentClassNames AS $documentClassName) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                 $documentManager->getClassMetadata($documentClassName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 $output->write("<info>[OK]</info>   " . $documentClassName, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             } catch(\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 $output->write("<error>[FAIL]</error> " . $documentClassName, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                 $output->write("<comment>" . $e->getMessage()."</comment>", true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                 $output->write("", true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 84 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |  |