Skip to content

Commit

Permalink
metadata: fix crash when datetime has invalid format
Browse files Browse the repository at this point in the history
For any reason if the date time is not in the correct format, the
entire scan process crashed.

Signed-off-by: Varun Patil <[email protected]>
  • Loading branch information
pulsejet committed Nov 14, 2023
1 parent 628fd82 commit d724e7a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/Listener/OriginalDateTimeMetadataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ public function handle(Event $event): void {
if ($metadata->hasKey('photos-exif') && array_key_exists('DateTimeOriginal', $metadata->getArray('photos-exif'))) {
$rawDateTimeOriginal = $metadata->getArray('photos-exif')['DateTimeOriginal'];
$dateTimeOriginal = DateTime::createFromFormat("Y:m:d G:i:s", $rawDateTimeOriginal);
$metadata->setInt('photos-original_date_time', $dateTimeOriginal->getTimestamp(), true);
return;
if ($dateTimeOriginal !== false) {
$metadata->setInt('photos-original_date_time', $dateTimeOriginal->getTimestamp(), true);
return;
}
}

// Try to parse the date out of the name.
Expand All @@ -79,8 +81,10 @@ public function handle(Event $event): void {
}

$dateTimeOriginal = DateTime::createFromFormat($format, $matches[1]);
$metadata->setInt('photos-original_date_time', $dateTimeOriginal->getTimestamp(), true);
return;
if ($dateTimeOriginal !== false) {
$metadata->setInt('photos-original_date_time', $dateTimeOriginal->getTimestamp(), true);
return;
}
}

// Fallback to the mtime.
Expand Down

0 comments on commit d724e7a

Please sign in to comment.