diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index 8c217f6d3..b9ea204a0 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -2025,8 +2025,8 @@ protected function getOutputCallback(OutputInterface $output, Checklist $checkli protected function executeAllScripts(Closure $outputCallback, Checklist $checklist): void { $this->runComposerScripts($outputCallback, $checklist); - $this->runDrushCacheClear($outputCallback, $checklist); $this->runDrushSqlSanitize($outputCallback, $checklist); + $this->runDrushCacheClear($outputCallback, $checklist); } /** diff --git a/src/Command/Pull/PullDatabaseCommand.php b/src/Command/Pull/PullDatabaseCommand.php index 7027e6677..cfe823a96 100644 --- a/src/Command/Pull/PullDatabaseCommand.php +++ b/src/Command/Pull/PullDatabaseCommand.php @@ -30,6 +30,12 @@ protected function configure(): void InputOption::VALUE_NONE, 'Do not run any additional scripts after the database is pulled. E.g., drush cache-rebuild, drush sql-sanitize, etc.' ) + ->addOption( + 'no-cache-clear', + null, + InputOption::VALUE_NONE, + 'Do not run drush cache-rebuild after pulling the database. Useful when pending update hooks must run before cache can be cleared.' + ) ->addOption( 'on-demand', null, @@ -59,15 +65,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int $onDemand = $input->hasOption('on-demand') && $input->getOption('on-demand'); $noImport = $input->hasOption('no-import') && $input->getOption('no-import'); $multipleDbs = $input->hasOption('multiple-dbs') && $input->getOption('multiple-dbs'); + $noCacheClear = $input->hasOption('no-cache-clear') && $input->getOption('no-cache-clear'); // $noImport implies $noScripts. $noScripts = $noImport || $noScripts; $this->setDirAndRequireProjectCwd($input); $sourceEnvironment = $this->determineEnvironment($input, $output, true); $this->pullDatabase($input, $output, $sourceEnvironment, $onDemand, $noImport, $multipleDbs); + $outputCallback = $this->getOutputCallback($output, $this->checklist); if (!$noScripts) { - $this->runDrushCacheClear($this->getOutputCallback($output, $this->checklist), $this->checklist); - $this->runDrushSqlSanitize($this->getOutputCallback($output, $this->checklist), $this->checklist); + $this->runDrushSqlSanitize($outputCallback, $this->checklist); + } + if (!$noScripts && !$noCacheClear) { + $this->runDrushCacheClear($outputCallback, $this->checklist); } return Command::SUCCESS; diff --git a/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php b/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php index 2aff85856..3207ff525 100644 --- a/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php +++ b/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php @@ -71,8 +71,8 @@ public function testPullDatabases(): void $this->mockExecuteDrushExists($localMachineHelper); $this->mockExecuteDrushStatus($localMachineHelper, $this->projectDir); $process = $this->mockProcess(); - $this->mockExecuteDrushCacheRebuild($localMachineHelper, $process); $this->mockExecuteDrushSqlSanitize($localMachineHelper, $process); + $this->mockExecuteDrushCacheRebuild($localMachineHelper, $process); $this->executeCommand([ '--no-scripts' => false, @@ -770,4 +770,33 @@ public function testGetSiteInstanceDatabaseCatchBlock(): void // Assert null is returned when exception is caught. $this->assertNull($result); } + + public function testPullDatabaseNoCacheClear(): void + { + $localMachineHelper = $this->mockLocalMachineHelper(); + $this->output->setVerbosity(BufferedOutput::VERBOSITY_NORMAL); + $this->mockExecuteMySqlConnect($localMachineHelper, true); + $environment = $this->mockGetEnvironment(); + $sshHelper = $this->mockSshHelper(); + $this->mockListSites($sshHelper); + $this->mockGetBackup($environment); + $this->mockExecuteMySqlListTables($localMachineHelper, 'drupal'); + $fs = $this->prophet->prophesize(Filesystem::class); + $this->mockExecuteMySqlDropDb($localMachineHelper, true, $fs); + $this->mockExecuteMySqlImport($localMachineHelper, true, true, 'my_db', 'my_dbdev', 'drupal'); + $fs->remove(Argument::type('string'))->shouldBeCalled(); + $localMachineHelper->getFilesystem()->willReturn($fs)->shouldBeCalled(); + $this->mockExecuteDrushExists($localMachineHelper); + $this->mockExecuteDrushStatus($localMachineHelper, $this->projectDir); + $process = $this->mockProcess(); + // sql:sanitize must still run; cache:rebuild must NOT (no mock means any call would fail). + $this->mockExecuteDrushSqlSanitize($localMachineHelper, $process); + + $this->executeCommand([ + '--no-cache-clear' => true, + ], self::inputChooseEnvironment()); + + $output = $this->getDisplay(); + $this->assertStringContainsString('Choose a database [my_db (default)]:', $output); + } }