Skip to content
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

When image source is a URL, store the URL for use during extraction. #2072

Merged
merged 21 commits into from
Jun 24, 2021

Conversation

jarrettj
Copy link
Contributor

@jarrettj jarrettj commented May 7, 2021

When image source is a link store the link.

This is:

- [ ] a bugfix
- [x] a new feature

Checklist:

Why this change is needed?

Described in issue #1997.

When image source is a link store the link.
@jarrettj jarrettj changed the title Update Xlsx.php When image source is a link store the link for use during extraction. May 7, 2021
Add url mutator.
@jarrettj jarrettj changed the title When image source is a link store the link for use during extraction. When image source is a link, store the link for use during extraction. May 7, 2021
jarrettj added 4 commits May 7, 2021 09:45
php-cs-fixer fixes.
php-cs-fixer fixes.
phpcs fixes.
Update section on image extraction.
@jarrettj jarrettj changed the title When image source is a link, store the link for use during extraction. When image source is a URL, store the URL for use during extraction. May 7, 2021
@jarrettj jarrettj marked this pull request as ready for review May 7, 2021 08:22
*
* @var string
*/
private $url;
Copy link
Member

Choose a reason for hiding this comment

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

If you're storing the path in a separate property if it's a url, shouldn't the Writer also be modified to retrieve it correctly when an Xlsx file has been loaded and is then subsequently saved?

Does it really require a separate url property? Or would a flag indicating url be sufficient (with appropriate checking of that flag in the recipe?)

Copy link
Contributor Author

@jarrettj jarrettj May 31, 2021

Choose a reason for hiding this comment

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

A flag alone would not work. If you check the updated recipe.md file you would see what I need to do. If it is a URL I would then get the image content using the URL. If it was a flag I would not know what the URL is. This change is to allow me to extract images from an excel file when the source is not a path but a URL.

Regarding the Writer, not sure if adding an image by URL is needed? Feel that would be a seperate PR maybe? I don't require that feature at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

A URL is a path though.... I'm not simply suggesting to discard the URL value, but to store it in the $path property, and use a simple flag to indicate whether $path contains a simple filepath or a url

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! Cool, I can do that. Let me rework it and commit. Thanks Mark.

And on the Writer, would it be fine to not change that?

Regards.
Jarrett

Copy link
Member

Choose a reason for hiding this comment

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

You might want to test to confirm; but if you're using $path to store the source path whether it's a url or a file path, then the writer should simply write that path value back as it was in the original file

Copy link
Member

Choose a reason for hiding this comment

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

Do you have a sample test file that you could use to write a basic Read/Write/Re-read test with assertions to verify the image source?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, updated the code, onto the tests. Could you point me in the right direction on how to do the tests? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test for the reader, please have a look and see if it is sufficient. Thanks.

@MarkBaker MarkBaker merged commit 7959928 into PHPOffice:master Jun 24, 2021
@oleibman
Copy link
Collaborator

I have a question about URLImageTest. It reads a spreadsheet which is part of the test suite, and then fetches an image from a URL. That URL is not part of the test suite, and its contents can change at any time. The test certainly works now, but it may fail in future. Are we okay with this? In fact, are we okay with making a URL request part of the test suite, which I believe has not been the case till now? Or should we be doing something like mocking the result for file_get_contents on line 29?

@jarrettj
Copy link
Contributor Author

jarrettj commented Sep 13, 2021

Hey @oleibman .

Good day.

And sorry for the delay, missed your reply. I can definitely look at doing that instead.

On a side note, how does the release cycles work? Thought there would be a new update by now already.

Regards.
Jarrett

@jarrettj
Copy link
Contributor Author

Thanks for pulling this change in! Removes manual image uploads into our CMS. Keep up the great work :)

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

Successfully merging this pull request may close these issues.

3 participants