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

[5.1] Ensure isMediaFile defaults to all supported formats when mediatypes is not specified #43640

Closed
wants to merge 2 commits into from
Closed

[5.1] Ensure isMediaFile defaults to all supported formats when mediatypes is not specified #43640

wants to merge 2 commits into from

Conversation

mattelkins-bluefrontier
Copy link
Contributor

@mattelkins-bluefrontier mattelkins-bluefrontier commented Jun 10, 2024

Summary of Changes

  • If mediatypes is not specified in the input, fallback to an explodable string of all supported formats (0,1,2,3) rather than images only (0).
  • Remove a redundant if statement - count($mediaTypes) is never === 0.

Testing Instructions

  1. Download the following file: Example MP4
  2. Upload the video file in to the root of the media library - by default, the path to the file should be: local-images:/file_example_MP4_480_1_5MG.mp4
  3. In a custom component or module, call \Joomla\Component\Media\Administrator\Model\FileModel::getFileInformation('local-images:/file_example_MP4_480_1_5MG.mp4');

Actual result BEFORE applying this Pull Request

With mediatypes not present or empty in the input object, calling FileModel::getFileInformation() with a path to anything other than an image file will generate an InvalidPathException.

The exception is thrown by ApiModel::getFile(), and will also be thrown if this function is called directly with a separate adapter and path.

The exception is triggered due to the fact that ApiModel::isMediaFile() will return false for a non-image file if mediatypes is not present or is empty in the input object. Without mediatypes, allowed formats will be limited to images only, rather than images, audio files, videos and documents.

Expected result AFTER applying this Pull Request

FileModel::getFileInformation() (and ApiModel::getFile()) will return an object containing file information for image and non-image files, assuming the referenced file exists at the location specified by the path.

(The namespace for all classes mentioned above is: Joomla\Component\Media\Administrator\Model.)

Link to documentations

No documentation changes for docs.joomla.org needed.
No documentation changes for manual.joomla.org needed.

@mattelkins-bluefrontier mattelkins-bluefrontier marked this pull request as ready for review June 10, 2024 18:44
@bembelimen
Copy link
Contributor

Thanks for the contribution @mattelkins-bluefrontier

I see one issue here: if you remove the if then you have a different behaviour to before when sending an empty string as mediatypes:

Before PR:

after the if you still have all types selected

After PR:

after the if, it's still an empty sting

Reason

$input->get(...) only returns the default value if the value is not set at all, but an empty string counts as not empty with isset.

Also please check the XML if you change default values.

@Quy Quy added the Updates Requested Indicates that this pull request needs an update from the author and should not be tested. label Aug 12, 2024
@mattelkins-bluefrontier mattelkins-bluefrontier closed this by deleting the head repository Aug 14, 2024
@mattelkins-bluefrontier
Copy link
Contributor Author

Thanks for your feedback, @bembelimen. I'll reopen this against 5.2-dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Updates Requested Indicates that this pull request needs an update from the author and should not be tested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants