-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[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
Usik2203
wants to merge
7
commits into
magento:2.4-develop
Choose a base branch
from
Usik2203:data-patch-fix
base: 2.4-develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f8bed9b
Fixed issue with Data/Schema patch applying
Usik2203 015ac91
minor fix
Usik2203 05aba68
Merge branch '2.4-develop' into data-patch-fix
Usik2203 fbca506
Merge branch '2.4-develop' into data-patch-fix
Usik2203 d88bd43
Fixed failed tests
Usik2203 13e4a2d
Fixed failed tests
Usik2203 391d60e
Merge branch '2.4-develop' into data-patch-fix
Usik2203 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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)); | ||
} | ||
} catch (\Exception $e) { | ||
throw new SetupException( | ||
|
@@ -292,4 +290,20 @@ 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 | ||
{ | ||
if ($dataPatchAliases = $dataPatch->getAliases()) { | ||
foreach ($dataPatchAliases as $patchAlias) { | ||
return $this->patchHistory->isApplied($patchAlias) ?? true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.