Skip to content

Commit

Permalink
Merge pull request #422 from doctrine/mapping-info-validate
Browse files Browse the repository at this point in the history
make doctrine mapping info command validate the metadata
  • Loading branch information
dbu committed Feb 15, 2014
2 parents 1de8515 + 8a4c255 commit 8d20f48
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace Doctrine\ODM\PHPCR\Tools\Console\Command;

use Doctrine\ODM\PHPCR\DocumentManager;
use Doctrine\ODM\PHPCR\Mapping\MappingException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -37,17 +38,16 @@ protected function configure()
->setName('doctrine:phpcr:mapping:info')
->setDescription('Shows basic information about all mapped documents')
->setHelp(<<<EOT
The <info>doctrine:phpcr:mapping:info</info> shows basic information about which
The <info>%command.name%</info> shows basic information about which
documents exist and possibly if their mapping information contains errors or
not.
<info>php app/console doctrine:phpcr:mapping:info</info>
EOT
);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var $documentManager DocumentManager */
$documentManager = $this->getHelper('phpcr')->getDocumentManager();

$documentClassNames = $documentManager->getConfiguration()
Expand All @@ -56,28 +56,33 @@ protected function execute(InputInterface $input, OutputInterface $output)

if (!$documentClassNames) {
throw new \LogicException(
'You do not have any mapped Doctrine PHPCR ODM documents'
'You do not have any mapped Doctrine PHPCR ODM documents according to the current configuration. '.
'If you have entities or mapping files you should check your mapping configuration for errors.'
);
}

$output->writeln(sprintf("Found <info>%d</info> documents mapped in document manager:", count($documentClassNames)));

$failure = false;

foreach ($documentClassNames as $documentClassName) {
try {
$documentManager->getClassMetadata($documentClassName);
$output->writeln(sprintf("<info>[OK]</info> %s", $documentClassName));
} catch (MappingException $e) {
$message = $e->getMessage();
while ($e->getPrevious()) {
$e = $e->getPrevious();
$message .= "\n".$e->getMessage();
$output->writeln("<error>[FAIL]</error> ".$documentClassName);
$output->writeln(sprintf("<comment>%s</comment>", $e->getMessage()));

if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
$this->getApplication()->renderException($e, $output);
}

$output->writeln("<error>[FAIL]</error> ".$documentClassName);
$output->writeln(sprintf("<comment>%s</comment>", $message));
$output->writeln('');

$failure = true;
}
}

return 0;
return $failure ? 1 : 0;
}
}

0 comments on commit 8d20f48

Please sign in to comment.