Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lost configuration checking to deploy command. #5718

Open
wants to merge 3 commits into
base: 12.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/Commands/core/DeployCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Consolidation\SiteProcess\ProcessManager;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands;
use Drush\Commands\config\ConfigCommands;
use Drush\Commands\config\ConfigImportCommands;
use Drush\Commands\core\DeployHookCommands;
use Drush\Drush;
Expand All @@ -25,20 +26,49 @@ final class DeployCommands extends DrushCommands implements SiteAliasManagerAwar
* Run several commands after performing a code deployment.
*/
#[CLI\Command(name: self::DEPLOY)]
#[CLI\Option(name: 'ignore-mismatched-config', description: 'Proceed with config:import even if changes made by update hooks will be reverted.')]
#[CLI\Usage(name: 'drush deploy -v -y', description: 'Run updates with verbose logging and accept all prompts.')]
#[CLI\Version(version: '10.3')]
#[CLI\Topics(topics: [DocsCommands::DEPLOY])]
#[CLI\Bootstrap(level: DrupalBootLevels::FULL)]
public function deploy(): void
public function deploy(array $options = ['ignore-mismatched-config' => false]): void
{
$self = $this->siteAliasManager()->getSelf();
$redispatchOptions = Drush::redispatchOptions();
$manager = $this->processManager();

// Prepare custom options for checking configuration state.
$configStatusOptions = $redispatchOptions;
$configStatusOptions['format'] = 'json';
// Record the state of configuration before database updates.
$process = $manager->drush($self, ConfigCommands::STATUS, [], $configStatusOptions);
$process->mustRun();
$originalConfigDiff = $process->getOutputAsJson();

$this->logger()->notice("Database updates start.");
$process = $manager->drush($self, UpdateDBCommands::UPDATEDB, [], $redispatchOptions);
$process->mustRun($process->showRealtime());

// Record the state of configuration after database updates.
$process = $manager->drush($self, ConfigCommands::STATUS, [], $configStatusOptions);
$process->mustRun();
$newConfigDiff = $process->getOutputAsJson();

// Check for new changes to active configuration that would be lost
// during the subsequent configuration import.
if ($originalConfigDiff !== $newConfigDiff) {
$configDiff = array_diff(
array_keys($newConfigDiff),
array_keys($originalConfigDiff),
);
$this->logger()->warning(dt('The following config changes will be lost during config import: :config', [
':config' => implode(', ', $configDiff),
]));
if (!$options['ignore-mismatched-config']) {
throw new \RuntimeException('Update hooks altered config that is about to be reverted during config import. Use --ignore-mismatched-config to bypass this error. Aborting.');
}
}

$this->logger()->success("Config import start.");
$process = $manager->drush($self, ConfigImportCommands::IMPORT, [], $redispatchOptions);
$process->mustRun($process->showRealtime());
Comment on lines +52 to 74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not track what you explained in your last comment.
Here the second diff is created after the update hook has run but before the config import.

Expand Down