Skip to content

Commit

Permalink
Merge pull request #2128 from nextcloud/pulsejet/crash-fix-1
Browse files Browse the repository at this point in the history
metadata: fix crash when datetime has invalid format
  • Loading branch information
artonge authored Nov 14, 2023
2 parents 31d7734 + d724e7a commit cd41849
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 cd41849

Please sign in to comment.