Feature PR-5.3-dev Pending

User tests: Successful: Unsuccessful:

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).

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 (e.g. mod_test_43915.zip created by @degobbis), 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.

avatar joomla-cms-bot joomla-cms-bot - change - 14 Aug 2024
Category Administration com_media
avatar mattelkins-bluefrontier mattelkins-bluefrontier - open - 14 Aug 2024
avatar mattelkins-bluefrontier mattelkins-bluefrontier - change - 14 Aug 2024
Status New Pending
avatar mattelkins-bluefrontier
mattelkins-bluefrontier - comment - 14 Aug 2024

Reopened against 5.2-dev after accidentally closing #43640 because I'm an idiot. ?‍♂️

This PR incorporates feedback from @bembelimen in this comment.

In the scenario where mediatypes is an empty string, ...->getInput()->getString() will return an empty string rather than the specified default value, the consequence of which is that explode() will return an array containing one empty value, i.e.:

array (
    0 => ''
)

array_filter() is used to remove all empty values from the array. The following \count($mediaTypes) === 0 will then be true, and $mediaTypes will be set to an array containing all supported file formats.

avatar fgsw
fgsw - comment - 16 Aug 2024
  1. 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

Using PR or not got: "Unable to upload file."

Test System Information:

Sample Data – Testing
PHP Built On Darwin Air.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64 x86_64
Database Type mysql
Database Version 8.0.35
Database Collation utf8mb4_unicode_ci
Database Connection Collation utf8mb4_0900_ai_ci
Database Connection Encryption None
Database Server Supports Connection Encryption Yes
PHP Version 8.3.8
Web Server Apache/2.4.58 (Unix) OpenSSL/1.1.1u mod_fastcgi/mod_fastcgi-SNAP-0910052141
WebServer to PHP Interface cgi-fcgi
Joomla! Version Joomla! 5.2.0-alpha4-dev Development [ Uthabiti ] 23-July-2024 16:01 GMT
Joomla Backward Compatibility Plugin Disabled
User Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:129.0) Gecko/20100101 Firefox/129.0

avatar crommie
crommie - comment - 24 Aug 2024

@mattelkins-bluefrontier could you elaborate on #3 of the testing instruction ("In a custom component or module, call \Joomla\Component\Media\Administrator\Model\FileModel::getFileInformation('local-images:/file_example_MP4_480_1_5MG.mp4');")? How do you do that?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43915.

avatar exlemor
exlemor - comment - 24 Aug 2024

This PR requires coding a custom module or component and not a mere easy PR test.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43915.

avatar degobbis
degobbis - comment - 24 Aug 2024

Please correct Your testing instructions, calling the methode \Joomla\Component\Media\Administrator\Model\FileModel::getFileInformation('local-images:/file_example_MP4_480_1_5MG.mp4'); statically is not more possible.
I also have created a module to testing this:
mod_test_43915.zip

avatar degobbis degobbis - test_item - 24 Aug 2024 - Tested successfully
avatar degobbis
degobbis - comment - 24 Aug 2024

I have tested this item ✅ successfully on 72f667f

Calling the method statically is not more possible, so using my test module will reproduce the error.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43915.

avatar brianteeman
brianteeman - comment - 24 Aug 2024

Calling the method statically is not more possible, so using my test module will reproduce the error.

That means this is a breaking change then doesnt it?

avatar degobbis
degobbis - comment - 24 Aug 2024

That means this is a breaking change then doesnt it?

I revoke my statement that it cannot be called up statically, it does work.
I tested the call when I had not yet uploaded the file and therefore got an error that made me think it was because of that.

I just tested it again successfully with the static call.
Sorry for the confusion.

avatar brianteeman
brianteeman - comment - 24 Aug 2024

@degobbis thanks for clarifying that

avatar mattelkins-bluefrontier mattelkins-bluefrontier - change - 27 Aug 2024
The description was changed
avatar mattelkins-bluefrontier mattelkins-bluefrontier - edited - 27 Aug 2024
avatar mattelkins-bluefrontier
mattelkins-bluefrontier - comment - 27 Aug 2024

Many thanks for all of your comments, and especially to @degobbis for the example module. I've updated the PR description accordingly.

My apologies for the confusion around getFileInformation() - it is not a static method in the FileModel class. This was my mistake - I used the PHPDoc FQSEN in the line of code I provided.

avatar mattelkins-bluefrontier mattelkins-bluefrontier - change - 27 Aug 2024
Labels Added: PR-5.2-dev
avatar HLeithner
HLeithner - comment - 2 Sep 2024

This pull request has been automatically rebased to 5.3-dev.

avatar HLeithner HLeithner - change - 2 Sep 2024
Title
[5.2] Ensure isMediaFile defaults to all supported formats when mediatypes is not specified
[5.3] Ensure isMediaFile defaults to all supported formats when mediatypes is not specified
avatar HLeithner HLeithner - edited - 2 Sep 2024
avatar mattelkins-bluefrontier mattelkins-bluefrontier - change - 23 Sep 2024
Labels Added: Feature PR-5.3-dev
Removed: PR-5.2-dev

Add a Comment

Login with GitHub to post a comment