-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[BUGFIX] Forward-port of #14861 for Magento 2.3 #19080
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
Merged
magento-engcom-team
merged 5 commits into
magento:2.3-develop
from
kanduvisla:GITHUB-14861-for-2.3
Dec 19, 2018
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3905580
[BUGFIX] Forward-port of #14861 for Magento 2.3
kanduvisla c2100db
[REFACTOR] Split the method to lower cyclomatic complexity
kanduvisla d904697
ENGCOM-3399: Static tests fixed.
p-bystritsky 9b919f9
Merge branch '2.3-develop' into GITHUB-14861-for-2.3
p-bystritsky 9cb7a89
ENGCOM-3399: Static tests fixed.
p-bystritsky 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
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.
Hi @kanduvisla. This point is not clear enough for me.
As far as I see, the new approach based on the loop reflects absolutely the same logic that was previously based on
array_search
. Is the difference in the strict types comparison (if yes, we could usestrict
parameter inarray_search
)?I might miss something, so any additional information is appreciated.
Thank you.
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.
Hi @rogyar ,
The problem with the previous implementation is not the fact that
array_search()
was used, but thatarray_column()
was used to get the$key
of$oldCategoryPositions
.array_column()
recreates the index, so the second time the loop was run, it could possibly return an index of0
, which could already have beenunset()
on$oldCategoryPositions()
, triggering an undefined index.This bug can be exposed by running the extra testcase I added to the unit test:
The above testcase is perfectly valid, because it is a simple swap of position, so it should trigger 2 updates. On the first run (in
$insertUpdate = $this->processCategoryLinks($categoryLinks, $oldCategoryLinks);
), the index ofcategory_id => 3
on$oldCategoryPositions
is0
. Coincidentally, this is also the same index returned by thearray_column()
-function. So$key = 0
and later onunset($oldCategoryPositions[$key]);
is done.Now comes the bug: on the second run (in
$deleteUpdate = $this->processCategoryLinks($oldCategoryLinks, $categoryLinks);
), thearray_column()
would still return0
(because of theunset()
earlier). However, since we've alreadyunset()
this one, theunset($oldCategoryPositions[$key]);
will now throw a notice, which in turn will trigger an exception further on.Even if you don't merge this PR, you can replicate this by adding the extra testcase to the unit test, and replace the last line:
to:
But I also updated the unit test to see if the proper CRUD operations are done.
Now as for your question: I don't know if
array_search()
can still be used since we're dealing with a multidimensional array. Perhaps some otherarray_*
-function could be used with something like a callback, but because the operation is quite a simple check and we do want to maintain our index I choose for aforeach
in aforeach
(forgive me lord for I have sinned).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.
Hi @rogyar ,
Any update on this?