Skip to content

Commit 1a8b2c3

Browse files
authored
Merge pull request #2425 from ksowa/disable-validators
Added --disable-validators option to odm:schema:update command
2 parents bd5de8c + 0f7888f commit 1a8b2c3

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/UpdateCommand.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ protected function configure()
2727
$this
2828
->setName('odm:schema:update')
2929
->addOption('class', 'c', InputOption::VALUE_OPTIONAL, 'Document class to process (default: all classes)')
30-
->setDescription('Update indexes for your documents');
30+
->addOption('disable-validators', null, InputOption::VALUE_NONE, 'Do not update database-level validation rules')
31+
->setDescription('Update indexes and validation rules for your documents');
3132
}
3233

3334
/**
3435
* @return int
3536
*/
3637
protected function execute(InputInterface $input, OutputInterface $output)
3738
{
38-
$class = $input->getOption('class');
39+
$class = $input->getOption('class');
40+
$updateValidators = ! $input->getOption('disable-validators');
3941

4042
$sm = $this->getSchemaManager();
4143
$isErrored = false;
@@ -44,13 +46,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
4446
if (is_string($class)) {
4547
$this->processDocumentIndex($sm, $class, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input));
4648
$output->writeln(sprintf('Updated <comment>index(es)</comment> for <info>%s</info>', $class));
47-
$this->processDocumentValidator($sm, $class, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input));
48-
$output->writeln(sprintf('Updated <comment>validation</comment> for <info>%s</info>', $class));
49+
50+
if ($updateValidators) {
51+
$this->processDocumentValidator($sm, $class, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input));
52+
$output->writeln(sprintf('Updated <comment>validation</comment> for <info>%s</info>', $class));
53+
}
4954
} else {
5055
$this->processIndex($sm, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input));
5156
$output->writeln('Updated <comment>indexes</comment> for <info>all classes</info>');
52-
$this->processValidators($sm, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input));
53-
$output->writeln('Updated <comment>validation</comment> for <info>all classes</info>');
57+
58+
if ($updateValidators) {
59+
$this->processValidators($sm, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input));
60+
$output->writeln('Updated <comment>validation</comment> for <info>all classes</info>');
61+
}
5462
}
5563
} catch (Throwable $e) {
5664
$output->writeln('<error>' . $e->getMessage() . '</error>');

tests/Doctrine/ODM/MongoDB/Tests/Tools/Console/Command/Schema/UpdateCommandTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ public function testProcessValidator(): void
5353
$this->assertStringContainsString('Updated validation for Documents\SchemaValidated', $output);
5454
}
5555

56+
public function testDisabledValidatorProcessing(): void
57+
{
58+
$this->commandTester->execute(
59+
[
60+
'--class' => SchemaValidated::class,
61+
'--disable-validators' => true,
62+
]
63+
);
64+
$output = $this->commandTester->getDisplay();
65+
$this->assertStringNotContainsString('Updated validation for Documents\SchemaValidated', $output);
66+
}
67+
5668
public function testProcessValidators(): void
5769
{
5870
// Only load a subset of documents with legit annotations
@@ -62,4 +74,14 @@ public function testProcessValidators(): void
6274
$output = $this->commandTester->getDisplay();
6375
$this->assertStringContainsString('Updated validation for all classes', $output);
6476
}
77+
78+
public function testDisabledValidatorsProcessing(): void
79+
{
80+
// Only load a subset of documents with legit annotations
81+
$annotationDriver = AnnotationDriver::create(__DIR__ . '/../../../../../../../../Documents/Ecommerce');
82+
$this->dm->getConfiguration()->setMetadataDriverImpl($annotationDriver);
83+
$this->commandTester->execute(['--disable-validators' => true]);
84+
$output = $this->commandTester->getDisplay();
85+
$this->assertStringNotContainsString('Updated validation for all classes', $output);
86+
}
6587
}

0 commit comments

Comments
 (0)