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
26 changes: 25 additions & 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 Expand Up @@ -2075,6 +2075,30 @@ protected function runDrushCacheClear(Closure $outputCallback, Checklist $checkl
}
}

/**
* @throws \Acquia\Cli\Exception\AcquiaCliException
*/
protected function runDrushDatabaseUpdates(Closure $outputCallback, Checklist $checklist): void
{
if ($this->getDrushDatabaseConnectionStatus()) {
$checklist->addItem('Applying pending database updates via Drush');
$process = $this->localMachineHelper->execute([
'drush',
'updatedb',
'--yes',
'--no-interaction',
'--verbose',
], $outputCallback, $this->dir, false);
if (!$process->isSuccessful()) {
throw new AcquiaCliException('Unable to apply database updates via Drush. {message}', ['message' => $process->getErrorOutput()]);
}
// @infection-ignore-all
$checklist->completePreviousItem();
} else {
$this->logger->notice('Drush does not have an active database connection. Skipping updatedb');
}
}

/**
* @throws \Acquia\Cli\Exception\AcquiaCliException
*/
Expand Down
6 changes: 4 additions & 2 deletions src/Command/Pull/PullDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$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->runDrushDatabaseUpdates($outputCallback, $this->checklist);
$this->runDrushSqlSanitize($outputCallback, $this->checklist);
$this->runDrushCacheClear($outputCallback, $this->checklist);
}

return Command::SUCCESS;
Expand Down
16 changes: 16 additions & 0 deletions tests/phpunit/src/Commands/Pull/PullCommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ protected function mockExecuteDrushCacheRebuild(
->shouldBeCalled();
}

protected function mockExecuteDrushUpdateDb(
ObjectProphecy $localMachineHelper,
ObjectProphecy $process
): void {
$localMachineHelper
->execute([
'drush',
'updatedb',
'--yes',
'--no-interaction',
'--verbose',
], Argument::type('callable'), $this->projectDir, false)
->willReturn($process->reveal())
->shouldBeCalled();
}

protected function mockExecuteDrushSqlSanitize(
ObjectProphecy $localMachineHelper,
ObjectProphecy $process
Expand Down
8 changes: 7 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,9 @@ public function testPullDatabases(): void
$this->mockExecuteDrushExists($localMachineHelper);
$this->mockExecuteDrushStatus($localMachineHelper, $this->projectDir);
$process = $this->mockProcess();
$this->mockExecuteDrushCacheRebuild($localMachineHelper, $process);
$this->mockExecuteDrushUpdateDb($localMachineHelper, $process);
$this->mockExecuteDrushSqlSanitize($localMachineHelper, $process);
$this->mockExecuteDrushCacheRebuild($localMachineHelper, $process);

$this->executeCommand([
'--no-scripts' => false,
Expand All @@ -86,6 +87,11 @@ public function testPullDatabases(): void
$this->assertStringContainsString('[0] Dev, dev (vcs: master)', $output);
$this->assertStringContainsString('Choose a database [my_db (default)]:', $output);
$this->assertStringContainsString('Using a database backup that is 1', $output);

$checklistReflection = new \ReflectionProperty($this->command, 'checklist');
$checklist = $checklistReflection->getValue($this->command);
$checklistMessages = array_column($checklist->getItems(), 'message');
$this->assertContains('Applying pending database updates via Drush', $checklistMessages);
}

public function testPullProdDatabase(): void
Expand Down
Loading