-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Exception because of calling DateTime::timestamp with array #75
Comments
followup, I investigated some more. Apparently, in the affected file, the CreateDate looks like this:
output:
We have date and time separated by comma. In the extension ExifToolService::extractMetadataFromLocalFile exiftool is called with -j which will create json output and this creates an array for this CreateDate:
output: (json)
I confirmed by debugging that the created metadata in extractMetadataFromLocalFile contains several arrays (for "CreateDate", "For") and otherwise contains strings, int and float. So, we should either expect various data types (not just string) or make sure the datatypes are always string. |
Could you test this patch and see if that helps? diff --git a/Classes/Utility/DateTime.php b/Classes/Utility/DateTime.php
index dd92997..4b27297 100644
--- a/Classes/Utility/DateTime.php
+++ b/Classes/Utility/DateTime.php
@@ -25,12 +25,15 @@ class DateTime
/**
* Converts a date/time into its Unix timestamp.
*
- * @param string|null $str
+ * @param string|array|null $str
* @return int|null
*/
- public static function timestamp(?string $str = null): ?int
+ public static function timestamp($str = null): ?int
{
- if ($str === null) {
+ if (is_array($str)) {
+ $str = implode(' ', $str);
+ }
+ if (!is_string($str)) {
return null;
}
if (preg_match('/^\d{4}:\d{2}:\d{2} \d{2}:\d{2}:\d{2}$/', $str)) { |
I don't have the file anymore. But looking at the code, it should fix it. Also, newer versions of tools should probably not produce this kind of output. For example, I tested with Gimp and this was written:
When trying to write a date with comma, my latest exiftool will not allow it:
As mentioned before, some of the files which were extracted were pretty old. |
timestamp() expects a string or null, but may be called with array by AbstractExtractionService:
Impact:
Reason of problem
entry is returned as array (because CreationDate in the metadata in the file (as returned by exiftool) contains date and time separated by comma, e.g.
"7/18/01, 12:51 PM"
) and exiftool -j and subsequent json_decode will create an array for this entry, not a string. (see next comment)Source Code
DateTime::timestamp:
public static function timestamp(?string $str = null): ?int
AbstractExtractionService:
Log
Stack trace:
The text was updated successfully, but these errors were encountered: