* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; use Doctrine\ODM\MongoDB\Mapping\MappingException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * Show information about mapped documents * * @author Benjamin Eberlei * @author Jonathan H. Wage */ class InfoDoctrineODMCommand extends DoctrineODMCommand { protected function configure() { $this ->setName('doctrine:mongodb:mapping:info') ->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.') ->setDescription('Show basic information about all mapped documents.') ->setHelp(<<doctrine:mapping:info shows basic information about which documents exist and possibly if their mapping information contains errors or not. ./app/console doctrine:mapping:info If you are using multiple document managers you can pick your choice with the --dm option: ./app/console doctrine:mapping:info --dm=default EOT ); } protected function execute(InputInterface $input, OutputInterface $output) { $documentManagerName = $input->getOption('dm') ? $input->getOption('dm') : $this->container->getParameter('doctrine.odm.mongodb.default_document_manager'); $documentManagerService = sprintf('doctrine.odm.mongodb.%s_document_manager', $documentManagerName); /* @var $documentManager Doctrine\ODM\MongoDB\DocumentManager */ $documentManager = $this->container->get($documentManagerService); $documentClassNames = $documentManager->getConfiguration() ->getMetadataDriverImpl() ->getAllClassNames(); if (!$entityClassNames) { throw new \Exception( 'You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles. '. 'Create a class inside the Document namespace of any of your bundles and provide '. 'mapping information for it with Annotations directly in the classes doc blocks '. 'or with XML/YAML in your bundles Resources/config/doctrine/metadata/mongodb directory.' ); } $output->write(sprintf("Found %d documents mapped in document manager %s:\n", count($documentClassNames), $documentManagerName), true); foreach ($documentClassNames AS $documentClassName) { try { $cm = $documentManager->getClassMetadata($documentClassName); $output->write("[OK] " . $documentClassName, true); } catch(MappingException $e) { $output->write("[FAIL] " . $documentClassName, true); $output->write("" . $e->getMessage()."", true); $output->write("", true); } } } }