-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Fix the correct removal of the images and the removal of all images in the catalog [Backport] #11153
Conversation
…rol structure' coding standard violations
This reverts commit 39e06b0.
@raumatbel Thank you for your contribution. We will merge your fixes to all branches shortly. |
$catalogPath = $this->mediaConfig->getBaseMediaPath(); | ||
$isFile = $this->mediaDirectory->isFile($catalogPath . $image['file']); | ||
// only delete physical files if they are not used by any other products and if this file exist | ||
if (!($this->resourceModel->countImageUses($image['file']) > 1) && $isFile) { |
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.
Check "$isFile" is more faster, so would be great to swap them.
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.
Can you explain me again? I don't understand well.
Do you want say me that I must not use the variable $isFile and I must specify it in the same line?.
if (!($this->resourceModel->countImageUses($image['file']) > 1) && $this->mediaDirectory->isFile($this->mediaConfig->getBaseMediaPath() . $image['file']);) {
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.
@raumatbel code if ($isFile && !($this->resourceModel->countImageUses($image['file']) > 1))
would be more optimal from performance perspective as if this is not a file then usage of image will not be checked.
I left up to you to make this fix or not as it may be considered as premature optimization. I think in code like this readability has higher priority.
…of all images in the catalog #11153
…of all images in the catalog #11153
Related with the PR#11147
Fix the correct removal of the images and the removal of all images in the catalog
Description
When you want remove image from admin panel, this file is not removed correctly.
If the path of the image saved in the table catalog_product_entity_media_gallery is empty, this remove all the catalog.
Manual testing scenarios
For the first case.
The file is not removed in pub/media/catalog/product/...
For the second case.
All the files are removed in pub/media/catalog/product/...
Contribution checklist