1
0
mirror of synced 2025-01-30 12:01:44 +03:00

Teach orm:validate-schema to --skip-mapping and --skip-sync

Use --skip-mapping to not check if the current mapping informaiton
is valid or not.

Use --skip-sync to not check if the database schema is in line with
the current schema mapping.
This commit is contained in:
David Stensland 2013-11-11 18:12:28 -05:00
parent 0edf2bc585
commit e6be52af3a

View File

@ -21,6 +21,7 @@ namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\Tools\SchemaValidator; use Doctrine\ORM\Tools\SchemaValidator;
@ -45,7 +46,20 @@ class ValidateSchemaCommand extends Command
$this $this
->setName('orm:validate-schema') ->setName('orm:validate-schema')
->setDescription('Validate the mapping files.') ->setDescription('Validate the mapping files.')
->setHelp(<<<EOT ->addOption(
'skip-mapping',
null,
InputOption::VALUE_NONE,
'Skip the mapping validation check'
)
->addOption(
'skip-sync',
null,
InputOption::VALUE_NONE,
'Skip checking if the mapping is in sync with the database'
)
->setHelp(
<<<EOT
'Validate that the mapping files are correct and in sync with the database.' 'Validate that the mapping files are correct and in sync with the database.'
EOT EOT
); );
@ -57,12 +71,12 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$em = $this->getHelper('em')->getEntityManager(); $em = $this->getHelper('em')->getEntityManager();
$validator = new SchemaValidator($em); $validator = new SchemaValidator($em);
$errors = $validator->validateMapping();
$exit = 0; $exit = 0;
if ($errors) {
if ($input->getOption('skip-mapping')) {
$output->writeln('<comment>[Mapping] Skipped mapping check.</comment>');
} elseif ($errors = $validator->validateMapping()) {
foreach ($errors as $className => $errorMessages) { foreach ($errors as $className => $errorMessages) {
$output->writeln("<error>[Mapping] FAIL - The entity-class '" . $className . "' mapping is invalid:</error>"); $output->writeln("<error>[Mapping] FAIL - The entity-class '" . $className . "' mapping is invalid:</error>");
@ -78,7 +92,9 @@ EOT
$output->writeln('<info>[Mapping] OK - The mapping files are correct.</info>'); $output->writeln('<info>[Mapping] OK - The mapping files are correct.</info>');
} }
if (!$validator->schemaInSyncWithMetadata()) { if ($input->getOption('skip-sync')) {
$output->writeln('<comment>[Database] SKIPPED - The database was not checked for synchronicity.</comment>');
} elseif (!$validator->schemaInSyncWithMetadata()) {
$output->writeln('<error>[Database] FAIL - The database schema is not in sync with the current mapping file.</error>'); $output->writeln('<error>[Database] FAIL - The database schema is not in sync with the current mapping file.</error>');
$exit += 2; $exit += 2;
} else { } else {