Skip to content

Magento 2 Recipe: Fix import needed after deployment failure during upgrade #4180#4181

Open
carlos-reynosa wants to merge 4 commits intodeployphp:masterfrom
carlos-reynosa:patch-2-4180
Open

Magento 2 Recipe: Fix import needed after deployment failure during upgrade #4180#4181
carlos-reynosa wants to merge 4 commits intodeployphp:masterfrom
carlos-reynosa:patch-2-4180

Conversation

@carlos-reynosa
Copy link
Copy Markdown
Contributor

@carlos-reynosa carlos-reynosa commented Mar 7, 2026

Pull request to ensure that if the magento deployment fails and the release is reverted the configuration is properly imported. Deployments mail fail during upgrade and after new configuration has been imported.

  1. Added deploy:magento:failed task to group post deployment failure tasks for magento 2
  2. Ensure to check config status and import configuration if deployment reverts and fails.
  • [ x] Bug fix #…?
  • [ x] New feature?
  • BC breaks?
  • Tests added?
  • Docs added?

Fixes #4180

  Please, regenerate docs by running next command:
  $ php bin/docgen

@carlos-reynosa carlos-reynosa changed the title Magento 2 Recipe Setup Upgrade Task Should be Non Interactive #4178 Magento 2 Recipe: Fix import needed after deployment failure during upgrade #4180 Mar 7, 2026
@carlos-reynosa carlos-reynosa marked this pull request as ready for review March 7, 2026 22:17
@antonmedv antonmedv requested a review from Copilot April 1, 2026 16:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a dedicated Magento 2 post-failure hook so that additional recovery steps (config import + maintenance disable) run when a deployment fails—intended to keep Magento configuration consistent after a failed upgrade/deploy attempt.

Changes:

  • Replaces the direct magento:maintenance:disable failure hook with a new grouped task deploy:magento:failed.
  • Adds deploy:magento:failed task to run magento:config:import and then disable maintenance mode.
  • Regenerates Magento 2 recipe documentation to include the new task and updated source line references.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
recipe/magento2.php Introduces deploy:magento:failed and wires it to deploy:failed for Magento-specific recovery steps.
docs/recipe/magento2.md Updates autogenerated docs to reflect the new task and shifted source line numbers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +377 to 381
task('deploy:magento:failed', [
'magento:config:import',
'magento:maintenance:disable',
]);

Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

deploy:magento:failed runs magento:config:import, but that task resolves {{bin/magento}} via {{release_or_current_path}}. On failures that occur before deploy:symlink, the {{deploy_path}}/release symlink still exists and points to the new/failed release (see recipe/deploy/release.php + recipe/deploy/symlink.php), so the config status/import will run against the failed release instead of the still-active current release—this doesn’t restore configuration after a failed upgrade.
Consider making the failure path explicitly run config status/import against {{current_path}} (or otherwise ensure release_or_current_path resolves to current_path here) and guard it so the deploy:failed hook remains best-effort even if Magento isn’t runnable in the release directory.

Suggested change
task('deploy:magento:failed', [
'magento:config:import',
'magento:maintenance:disable',
]);
task('deploy:magento:failed', function () {
$hadReleaseOrCurrentPath = false;
$originalReleaseOrCurrentPath = null;
if (has('release_or_current_path')) {
$hadReleaseOrCurrentPath = true;
$originalReleaseOrCurrentPath = get('release_or_current_path');
}
// Ensure that config import on failure is run against the active current release,
// not the (possibly broken) new release.
set('release_or_current_path', '{{current_path}}');
try {
invoke('magento:config:import');
} catch (RunException $exception) {
// Best-effort: ignore failures during rollback config import.
} catch (GracefulShutdownException $exception) {
// Best-effort: ignore failures during rollback config import.
}
// Restore original release_or_current_path configuration if it existed before.
if ($hadReleaseOrCurrentPath) {
set('release_or_current_path', $originalReleaseOrCurrentPath);
}
try {
invoke('magento:maintenance:disable');
} catch (RunException $exception) {
// Best-effort: ignore failures when disabling maintenance mode on failure.
} catch (GracefulShutdownException $exception) {
// Best-effort: ignore failures when disabling maintenance mode on failure.
}
});

Copilot uses AI. Check for mistakes.
after('deploy:failed', 'deploy:magento:failed');

//Run Magento Deployment Failure Tasks
desc('Run magento post deployment failure tasks.');
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

Minor grammar/style: desc('Run magento post deployment failure tasks.') reads a bit awkwardly and uses inconsistent capitalization vs other Magento task descriptions in this recipe. Consider rephrasing (e.g., “Run Magento post-deployment failure tasks”) so the generated docs/help text is polished.

Suggested change
desc('Run magento post deployment failure tasks.');
desc('Run Magento post-deployment failure tasks');

Copilot uses AI. Check for mistakes.
after('deploy:failed', 'magento:maintenance:disable');
after('deploy:failed', 'deploy:magento:failed');

//Run Magento Deployment Failure Tasks
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

The inline //Run Magento Deployment Failure Tasks comment is being pulled into the autogenerated docs as a separate paragraph (see the new “Run Magento Deployment Failure Tasks” line in docs/recipe/magento2.md), which makes the docs a bit redundant/noisy. Consider either removing this comment or converting it into a clearer desc(...)/documentation text so docgen output stays clean.

Suggested change
//Run Magento Deployment Failure Tasks

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants