Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/Command/Pull/PullDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 30 additions & 1 deletion tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
Loading