User tests: Successful: Unsuccessful:
\Joomla\Component\Media\Administrator\Model\FileModel->getFileInformation('local-images:/file_example_MP4_480_1_5MG.mp4');
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.
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.)
No documentation changes for docs.joomla.org needed.
No documentation changes for manual.joomla.org needed.
Category | ⇒ | Administration com_media |
Status | New | ⇒ | Pending |
- 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
@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 PR requires coding a custom module or component and not a mere easy PR test.
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
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.
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?
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.
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.
Labels |
Added:
PR-5.2-dev
|
This pull request has been automatically rebased to 5.3-dev.
Title |
|
Labels |
Added:
Feature
PR-5.3-dev
Removed: PR-5.2-dev |
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 thatexplode()
will return an array containing one empty value, i.e.: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.