forked from doctrine/DoctrineMongoDBBundle
/
InfoDoctrineODMCommand.php
84 lines (71 loc) · 3.3 KB
/
InfoDoctrineODMCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*
* This file is part of the Doctrine MongoDBBundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Doctrine\Bundle\MongoDBBundle\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Show information about mapped documents
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
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(<<<EOT
The <info>doctrine:mongodb:mapping:info</info> shows basic information about which
documents exist and possibly if their mapping information contains errors or not.
<info>./app/console doctrine:mongodb:mapping:info</info>
If you are using multiple document managers you can pick your choice with the <info>--dm</info> option:
<info>./app/console doctrine:mongodb:mapping:info --dm=default</info>
EOT
);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$documentManagerName = $input->getOption('dm') ?
$input->getOption('dm') :
$this->getContainer()->get('doctrine.odm.mongodb')->getDefaultManagerName();
/* @var $documentManager Doctrine\ODM\MongoDB\DocumentManager */
$documentManager = $this->getContainer()->get('doctrine.odm.mongodb')->getManager($documentManagerName);
$documentClassNames = $documentManager->getConfiguration()
->getMetadataDriverImpl()
->getAllClassNames();
if (!$documentClassNames) {
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 <info>%d</info> documents mapped in document manager <info>%s</info>:\n",
count($documentClassNames), $documentManagerName), true);
foreach ($documentClassNames AS $documentClassName) {
try {
$cm = $documentManager->getClassMetadata($documentClassName);
$output->write("<info>[OK]</info> " . $documentClassName, true);
} catch(\Exception $e) {
$output->write("<error>[FAIL]</error> " . $documentClassName, true);
$output->write("<comment>" . $e->getMessage()."</comment>", true);
$output->write("", true);
}
}
}
}