From 8589206f473f723797eaee8db8d6901d42bdd429 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 6 May 2024 11:59:07 -0400 Subject: [PATCH] Add skip-search-indexes option to schema CLI commands Currently, commands can either process all definitions (default behavior) or specify individual definitions. This allows the commands to rely on default behavior (e.g. $createOrder) but omit processing of search indexes, which may be more stringent requirements. Note: this is similar to the disable-validators option that already existed in UpdateCommand; however, #2634 suggests renaming that if additional "skip" options are introduced. --- .../MongoDB/Tools/Console/Command/Schema/CreateCommand.php | 5 +++++ .../ODM/MongoDB/Tools/Console/Command/Schema/DropCommand.php | 5 +++++ .../MongoDB/Tools/Console/Command/Schema/UpdateCommand.php | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/CreateCommand.php b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/CreateCommand.php index 8e395d938..4a237a1a1 100644 --- a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/CreateCommand.php +++ b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/CreateCommand.php @@ -41,6 +41,7 @@ protected function configure() ->addOption(self::COLLECTION, null, InputOption::VALUE_NONE, 'Create collections') ->addOption(self::INDEX, null, InputOption::VALUE_NONE, 'Create indexes') ->addOption(self::SEARCH_INDEX, null, InputOption::VALUE_NONE, 'Create search indexes') + ->addOption('skip-search-indexes', null, InputOption::VALUE_NONE, 'Skip processing of search indexes') ->addOption('background', null, InputOption::VALUE_NONE, sprintf('Create indexes in background (requires "%s" option)', self::INDEX)) ->setDescription('Create databases, collections and indexes for your documents'); } @@ -65,6 +66,10 @@ private function doExecute(InputInterface $input, OutputInterface $output): int self::SEARCH_INDEX => 'SearchIndex', }; + if ($option === self::SEARCH_INDEX && $input->getOption('skip-search-indexes')) { + continue; + } + try { if (isset($class)) { $this->{'processDocument' . $method}($sm, $class, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input), $background); diff --git a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/DropCommand.php b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/DropCommand.php index 7718a0373..4fdc74a89 100644 --- a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/DropCommand.php +++ b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/DropCommand.php @@ -43,6 +43,7 @@ protected function configure() ->addOption(self::COLLECTION, null, InputOption::VALUE_NONE, 'Drop collections') ->addOption(self::INDEX, null, InputOption::VALUE_NONE, 'Drop indexes') ->addOption(self::SEARCH_INDEX, null, InputOption::VALUE_NONE, 'Drop search indexes') + ->addOption('skip-search-indexes', null, InputOption::VALUE_NONE, 'Skip processing of search indexes') ->setDescription('Drop databases, collections and indexes for your documents'); } @@ -65,6 +66,10 @@ private function doExecute(InputInterface $input, OutputInterface $output): int self::SEARCH_INDEX => 'SearchIndex', }; + if ($option === self::SEARCH_INDEX && $input->getOption('skip-search-indexes')) { + continue; + } + try { if (is_string($class)) { $this->{'processDocument' . $method}($sm, $class, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input)); diff --git a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/UpdateCommand.php b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/UpdateCommand.php index 0f7cd9878..a4d0fc313 100644 --- a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/UpdateCommand.php +++ b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/UpdateCommand.php @@ -27,7 +27,7 @@ protected function configure() $this ->setName('odm:schema:update') ->addOption('class', 'c', InputOption::VALUE_OPTIONAL, 'Document class to process (default: all classes)') - ->addOption('disable-search-indexes', null, InputOption::VALUE_NONE, 'Do not update search indexes') + ->addOption('skip-search-indexes', null, InputOption::VALUE_NONE, 'Skip processing of search indexes') ->addOption('disable-validators', null, InputOption::VALUE_NONE, 'Do not update database-level validation rules') ->setDescription('Update indexes and validation rules for your documents'); } @@ -36,7 +36,7 @@ private function doExecute(InputInterface $input, OutputInterface $output): int { $class = $input->getOption('class'); $updateValidators = ! $input->getOption('disable-validators'); - $updateSearchIndexes = ! $input->getOption('disable-search-indexes'); + $updateSearchIndexes = ! $input->getOption('skip-search-indexes'); $sm = $this->getSchemaManager(); $isErrored = false;