From 48f43b3c04429e47b58b5512105a73845e9845cb Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Sat, 16 Sep 2017 09:02:25 +0100 Subject: [PATCH] #38: Made a few tweaks to the analysis function that doesn't delete the photo if it was previously analysed (i.e. it has a metadata version). Also if the original image contained Exif data (e.g. camera make), we no longer remove it if the re-analysed image doesn't (see #39) --- .../Controllers/Admin/PhotoController.php | 7 ++-- app/Services/PhotoService.php | 28 +++++++-------- ...9_15_141905_add_photo_exif_data_column.php | 34 +++++++++++++++++++ .../base/admin/album_metadata.blade.php | 12 ++++++- 4 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 database/migrations/2017_09_15_141905_add_photo_exif_data_column.php diff --git a/app/Http/Controllers/Admin/PhotoController.php b/app/Http/Controllers/Admin/PhotoController.php index f6f5692..3804dc9 100644 --- a/app/Http/Controllers/Admin/PhotoController.php +++ b/app/Http/Controllers/Admin/PhotoController.php @@ -59,8 +59,11 @@ class PhotoController extends Controller $result['is_successful'] = false; $result['message'] = $ex->getMessage(); - // Remove the photo if it cannot be analysed - $photo->delete(); + // Remove the photo if it cannot be analysed (only if there isn't currently a version of metadata) + if (is_null($photo->metadata_version)) + { + $photo->delete(); + } } return response()->json($result); diff --git a/app/Services/PhotoService.php b/app/Services/PhotoService.php index 8064fbd..1d515c9 100644 --- a/app/Services/PhotoService.php +++ b/app/Services/PhotoService.php @@ -108,10 +108,10 @@ class PhotoService if ($isExifDataFound) { $this->photo->metadata_version = self::METADATA_VERSION; - $this->photo->taken_at = $this->metadataDateTime($exifData); - $this->photo->camera_make = $this->metadataCameraMake($exifData); - $this->photo->camera_model = $this->metadataCameraModel($exifData); - $this->photo->camera_software = $this->metadataCameraSoftware($exifData); + $this->photo->taken_at = $this->metadataDateTime($exifData, $this->photo->taken_at); + $this->photo->camera_make = $this->metadataCameraMake($exifData, $this->photo->camera_make); + $this->photo->camera_model = $this->metadataCameraModel($exifData, $this->photo->camera_model); + $this->photo->camera_software = $this->metadataCameraSoftware($exifData, $this->photo->camera_software); } $this->photo->is_analysed = true; @@ -301,37 +301,37 @@ class PhotoService return $photoPath; } - private function metadataCameraMake(array $exifData) + private function metadataCameraMake(array $exifData, $originalValue = null) { if (isset($exifData['Make'])) { return $exifData['Make']; } - return null; + return $originalValue; } - private function metadataCameraModel(array $exifData) + private function metadataCameraModel(array $exifData, $originalValue = null) { if (isset($exifData['Model'])) { return $exifData['Model']; } - return null; + return $originalValue; } - private function metadataCameraSoftware(array $exifData) + private function metadataCameraSoftware(array $exifData, $originalValue = null) { if (isset($exifData['Software'])) { return $exifData['Software']; } - return null; + return $originalValue; } - private function metadataDateTime(array $exifData) + private function metadataDateTime(array $exifData, $originalValue = null) { $dateTime = null; if (isset($exifData['DateTimeOriginal'])) @@ -343,11 +343,11 @@ class PhotoService $dateTime = $exifData['DateTime']; } - if (!is_null($dateTime)) + if (is_null($dateTime)) { - $dateTime = preg_replace('/^([\d]{4}):([\d]{2}):([\d]{2})/', '$1-$2-$3', $dateTime); + return $originalValue; } - return $dateTime; + return preg_replace('/^([\d]{4}):([\d]{2}):([\d]{2})/', '$1-$2-$3', $dateTime); } } \ No newline at end of file diff --git a/database/migrations/2017_09_15_141905_add_photo_exif_data_column.php b/database/migrations/2017_09_15_141905_add_photo_exif_data_column.php new file mode 100644 index 0000000..812b112 --- /dev/null +++ b/database/migrations/2017_09_15_141905_add_photo_exif_data_column.php @@ -0,0 +1,34 @@ +longText('raw_exif_data'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('photos', function (Blueprint $table) + { + $table->dropColumn('raw_exif_data'); + }); + } +} diff --git a/resources/views/themes/base/admin/album_metadata.blade.php b/resources/views/themes/base/admin/album_metadata.blade.php index d99a6c3..1a9a5a3 100644 --- a/resources/views/themes/base/admin/album_metadata.blade.php +++ b/resources/views/themes/base/admin/album_metadata.blade.php @@ -31,4 +31,14 @@ -@endsection \ No newline at end of file +@endsection + +@push('scripts') + +@endpush \ No newline at end of file