@@ -27,15 +27,17 @@ protected function configure()
27
27
$ this
28
28
->setName ('odm:schema:update ' )
29
29
->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 ' );
31
32
}
32
33
33
34
/**
34
35
* @return int
35
36
*/
36
37
protected function execute (InputInterface $ input , OutputInterface $ output )
37
38
{
38
- $ class = $ input ->getOption ('class ' );
39
+ $ class = $ input ->getOption ('class ' );
40
+ $ updateValidators = ! $ input ->getOption ('disable-validators ' );
39
41
40
42
$ sm = $ this ->getSchemaManager ();
41
43
$ isErrored = false ;
@@ -44,13 +46,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
44
46
if (is_string ($ class )) {
45
47
$ this ->processDocumentIndex ($ sm , $ class , $ this ->getMaxTimeMsFromInput ($ input ), $ this ->getWriteConcernFromInput ($ input ));
46
48
$ 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
+ }
49
54
} else {
50
55
$ this ->processIndex ($ sm , $ this ->getMaxTimeMsFromInput ($ input ), $ this ->getWriteConcernFromInput ($ input ));
51
56
$ 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
+ }
54
62
}
55
63
} catch (Throwable $ e ) {
56
64
$ output ->writeln ('<error> ' . $ e ->getMessage () . '</error> ' );
0 commit comments