Skip to content

Fix Issue #19872 - checking if image is in media directory #21131

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

Conversation

Bartlomiejsz
Copy link
Contributor

@Bartlomiejsz Bartlomiejsz commented Feb 11, 2019

Description (*)

Issue #19872 (closed) is still not fixed on develop branch.
On develop when image is added from media gallery while configuring category, it's path is saved as /media/path_to_file, but while Magento tries to check if this image is placed in media it compares it's path with pub/media/ instead of media/.

Fixed Issues (if relevant)

  1. Magento 2.3 category edit page "Select from gallery" button not working. #19872: Magento 2.3 category edit page "Select from gallery" button not working.
  2. Assigning Catalog Image from Gallery, then Saving Twice, Clears Image #22092

Manual testing scenarios (*)

  1. Go to category add/edit form
  2. Edit Category Image attribute using Select from Gallery option
  3. Save category
  4. Check if Category Image is visible in backoffice for this category

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Feb 11, 2019

CLA assistant check
All committers have signed the CLA.

@magento-engcom-team
Copy link
Contributor

Hi @Bartlomiejsz. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@Bartlomiejsz
Copy link
Contributor Author

@magento-engcom-team give me 2.3-develop instance

@magento-engcom-team
Copy link
Contributor

Hi @Bartlomiejsz. Thank you for your request. I'm working on Magento 2.3-develop instance for you

@magento-engcom-team
Copy link
Contributor

Hi @Bartlomiejsz, here is your Magento instance.
Admin access: https://i-21131-2-3-develop.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@Bartlomiejsz
Copy link
Contributor Author

@magento-engcom-team give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @Bartlomiejsz. Thank you for your request. I'm working on Magento instance for you

@magento-engcom-team
Copy link
Contributor

Hi @Bartlomiejsz, here is your new Magento instance.
Admin access: https://pr-21131.instances.magento-community.engineering/admin
Login: admin Password: 123123q

@dmytro-ch dmytro-ch self-requested a review February 11, 2019 19:40
@dmytro-ch dmytro-ch self-assigned this Feb 11, 2019
@dmytro-ch
Copy link
Contributor

@magento-engcom-team give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch. Thank you for your request. I'm working on Magento instance for you

@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch, here is your new Magento instance.
Admin access: https://pr-21131.instances.magento-community.engineering/admin
Login: admin Password: 123123q

@dmytro-ch
Copy link
Contributor

Hi @Bartlomiejsz,
thank you for your contribution.
I colud not reproduce the issue on test instance in 2.3-develop branch.
Also, the current solution does not work on test instance.

screen recording 2019-02-14 at 8 31 01 pm

Could you please make sure the issue is not related to your local envronment configuration?

Thank you!

@Bartlomiejsz
Copy link
Contributor Author

@dmytro-ch that's right, I also noticed, that the issue doesn't appear on github-generated instance of Magento.

But I think this is related to location of Magento instance. If it is located in root directory (which is not recommended due to security, but I think still this is used by github-generated instance) the issue doesn't occur. But if Magento is installed in recommended pub/ directory, the issue occurs.
So it is my local environment configuration indeed, but also all environments that are installed according to Magento recommendations I think...

@dmytro-ch
Copy link
Contributor

@Bartlomiejsz I was also thinking about that and tested the issue locally in 2.3-develop branch for both configurations /root and /pub.
As result, each time I got the same problem as you described, even when the document root is set to root Magento 2 directory. So I guess, this is not the reason of the issue.

However, after switching to PHP 7.2 the issue is not reproducible anymore.
Could you please check your current PHP version?

Thank you!

@Bartlomiejsz
Copy link
Contributor Author

Bartlomiejsz commented Feb 15, 2019

@dmytro-ch I'm currently running on 7.1.25, but I had same issue on instance running on 7.2.14

@Bartlomiejsz
Copy link
Contributor Author

@magento-engcom-team give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @Bartlomiejsz. Thank you for your request. I'm working on Magento instance for you

@Bartlomiejsz
Copy link
Contributor Author

@magento-engcom-team give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @Bartlomiejsz. Thank you for your request. I'm working on Magento instance for you

@magento-engcom-team
Copy link
Contributor

Hi @Bartlomiejsz, here is your new Magento instance.
Admin access: https://pr-21131.instances.magento-community.engineering/admin
Login: admin Password: 123123q

@Bartlomiejsz
Copy link
Contributor Author

@dmytro-ch could you please recheck this one? Current solution should work no matter if installation is in root or pub directory

@magento-engcom-team
Copy link
Contributor

Hi @Bartlomiejsz. Thank you for your request. I'm working on Magento 2.3-develop instance for you

@magento-engcom-team
Copy link
Contributor

Hi @Bartlomiejsz, here is your Magento instance.
Admin access: https://i-21131-2-3-develop.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@Bartlomiejsz
Copy link
Contributor Author

Bartlomiejsz commented May 28, 2019

Hi @sivaschenko. I think I understand you're point, but there is one problem I think. Sorry, I haven't thought about this before.
This PR fixes a bit different problem than we discussed. The problem is not caused by different ways of storing paths for images, but it is caused by different document root placement for magento instance.
You're saying about changing way that path is stored - so it would be relative to media. But the issue would still occur then, because if Magento would be installed in pub/ directory media path would have to begin with /media/, and if it would be installed in root dir (one directory up from pub/) - media path would have to begin with /pub/media/ - and it works this way in for all files in pub/ - media, static etc.
And this /pub at the beginning of path is reason of issue here, not two different ways of storing this path.
So I assume you're point can be good - this could be changed, but this PR should be checked as fix for another issue in this area I believe.

Changing way of storing those paths is feature rather than fix in my opinion - I don't think this is the reason of any issue currently.

@sivaschenko
Copy link
Member

Hi @Bartlomiejsz , thanks for your response. Would you be able to add tests cases to \Magento\Catalog\Model\Category\FileInfo to cover both cases of paths for isExist and getMediaDirectoryPathRelativeToBaseDirectoryPath methods? I believe it will make things more clear.

@Bartlomiejsz
Copy link
Contributor Author

Bartlomiejsz commented May 29, 2019

Hi @sivaschenko, will work on it!

@Bartlomiejsz
Copy link
Contributor Author

Hi @sivaschenko, added tests. Especially important here are paths beginning with /pub/media - for installation at root directory and beginning with /media - for installation at /pub directory

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

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

Thanks for the tests @Bartlomiejsz

The only thing that is not covered by the fix is the custom pub directory path.

Please use $this->filesystem->getDirectoryRead(DirectoryList::PUB)->getRelativePath() to retrive the correct pub directory path

@Bartlomiejsz
Copy link
Contributor Author

Hi @sivaschenko, done

@magento-engcom-team
Copy link
Contributor

Hi @sivaschenko, thank you for the review.
ENGCOM-4591 has been created to process this Pull Request

@soleksii
Copy link

soleksii commented Jun 6, 2019

✔️ QA Passed

@magento-engcom-team magento-engcom-team merged commit d06fb10 into magento:2.3-develop Jun 7, 2019
@m2-assistant
Copy link

m2-assistant bot commented Jun 7, 2019

Hi @Bartlomiejsz, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

magento-engcom-team pushed a commit to okorshenko/magento2 that referenced this pull request Jun 7, 2019
@magento-engcom-team magento-engcom-team added this to the Release: 2.3.3 milestone Jun 7, 2019
@Bartlomiejsz Bartlomiejsz deleted the feature/fix_19872_category_image_path branch September 12, 2019 09:23
@wescey
Copy link

wescey commented Jan 10, 2020

Now when the selected image is saved (and is still there in backend), is it showing on frontend?

@duckchip
Copy link
Contributor

I have that same problem.
After applying this patch, i got a very weird path on the frontend. (Broken image)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants