Skip to content

[Fixed: #31396] Data/Schema Patches getAliases() not working as expected #31635

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 7 commits into
base: 2.4-develop
Choose a base branch
from
Open
Changes from 2 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
28 changes: 20 additions & 8 deletions lib/internal/Magento/Framework/Setup/Patch/PatchApplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,9 @@ public function applyDataPatch($moduleName = null)
} else {
try {
$this->moduleDataSetup->getConnection()->beginTransaction();
$dataPatch->apply();
$this->patchHistory->fixPatch(get_class($dataPatch));
foreach ($dataPatch->getAliases() as $patchAlias) {
$this->patchHistory->fixPatch($patchAlias);
if (!$this->checkPatchAliases($dataPatch)) {
$dataPatch->apply();
$this->patchHistory->fixPatch(get_class($dataPatch));
}
$this->moduleDataSetup->getConnection()->commit();
} catch (\Exception $e) {
Expand Down Expand Up @@ -238,10 +237,9 @@ public function applySchemaPatch($moduleName = null)
* @var SchemaPatchInterface $schemaPatch
*/
$schemaPatch = $this->patchFactory->create($schemaPatch, ['schemaSetup' => $this->schemaSetup]);
$schemaPatch->apply();
$this->patchHistory->fixPatch(get_class($schemaPatch));
foreach ($schemaPatch->getAliases() as $patchAlias) {
$this->patchHistory->fixPatch($patchAlias);
if (!$this->checkPatchAliases($schemaPatch)) {
$schemaPatch->apply();
$this->patchHistory->fixPatch(get_class($schemaPatch));

Choose a reason for hiding this comment

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

@Usik2203 We should still also loop over every alias and mark them as applied. In the case where a patch file is renamed (e.g. changing the namespace of a module), if we install the new version and only mark the new name as installed, rolling back to before the change will result in the same patch applying a second time. If we mark all aliases as installed, then it will prevent that from happening.

}
} catch (\Exception $e) {
throw new SetupException(
Expand Down Expand Up @@ -292,4 +290,18 @@ public function revertDataPatches($moduleName = null)
}
}
}

/**
* Checks is patch was applied with current alias name
*
* @param DataPatchInterface|SchemaPatchInterface $dataPatch
* @return bool
*/
private function checkPatchAliases($dataPatch): bool
{
foreach ($dataPatch->getAliases() as $patchAlias) {
return $this->patchHistory->isApplied($patchAlias);
}
return false;
}
}