Skip to content

Do not reapply patches in case it got already applied with one of it's aliases #40025

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

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Open
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
36 changes: 27 additions & 9 deletions lib/internal/Magento/Framework/Setup/Patch/PatchApplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ public function applyDataPatch($moduleName = null)
new Phrase("Patch %1 should implement DataPatchInterface", [get_class($dataPatch)])
);
}
/**
* If the patch was already applied before with a name from its aliases,we fix the new name as well but
* skip it's installation, otherwise we fix the alias name in history.
*/
foreach ($dataPatch->getAliases() as $patchAlias) {
if ($this->patchHistory->isApplied($patchAlias)) {
$this->patchHistory->fixPatch(get_class($dataPatch));

continue 2;
}

$this->patchHistory->fixPatch($patchAlias);
}
if ($dataPatch instanceof NonTransactionableInterface) {
$dataPatch->apply();
$this->patchHistory->fixPatch(get_class($dataPatch));
Expand All @@ -161,11 +174,6 @@ public function applyDataPatch($moduleName = null)
$this->moduleDataSetup->getConnection()->beginTransaction();
$dataPatch->apply();
$this->patchHistory->fixPatch(get_class($dataPatch));
foreach ($dataPatch->getAliases() as $patchAlias) {
if (!$this->patchHistory->isApplied($patchAlias)) {
$this->patchHistory->fixPatch($patchAlias);
}
}
$this->moduleDataSetup->getConnection()->commit();
} catch (\Exception $e) {
$this->moduleDataSetup->getConnection()->rollBack();
Expand Down Expand Up @@ -240,13 +248,23 @@ public function applySchemaPatch($moduleName = null)
* @var SchemaPatchInterface $schemaPatch
*/
$schemaPatch = $this->patchFactory->create($schemaPatch, ['schemaSetup' => $this->schemaSetup]);
$schemaPatch->apply();
$this->patchHistory->fixPatch(get_class($schemaPatch));

/**
* If the patch was already applied before with a name from its aliases, we fix the new name as well but
* skip it's installation, otherwise we fix the alias name in history.
*/
foreach ($schemaPatch->getAliases() as $patchAlias) {
if (!$this->patchHistory->isApplied($patchAlias)) {
$this->patchHistory->fixPatch($patchAlias);
if ($this->patchHistory->isApplied($patchAlias)) {
$this->patchHistory->fixPatch(get_class($schemaPatch));

continue 2;
}

$this->patchHistory->fixPatch($patchAlias);
}

$schemaPatch->apply();
$this->patchHistory->fixPatch(get_class($schemaPatch));
} catch (\Exception $e) {
$schemaPatchClass = is_object($schemaPatch) ? get_class($schemaPatch) : $schemaPatch;
throw new SetupException(
Expand Down