From 626cd5b2ecdd0f0ef30e20a8092e07f8d594847c Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Tue, 6 Sep 2016 19:47:25 +0100 Subject: [PATCH] Added a separate storage_file_name column to the Photo class --- app/AlbumSources/LocalFilesystemSource.php | 6 ++-- .../Controllers/Admin/PhotoController.php | 10 +++--- .../Controllers/Gallery/PhotoController.php | 2 +- app/Photo.php | 5 ++- ...6_150902_add_photo_storage_file_column.php | 32 +++++++++++++++++++ resources/lang/en/admin.php | 2 +- .../themes/base/admin/list_albums.blade.php | 2 +- .../themes/base/admin/show_album.blade.php | 2 +- .../views/themes/base/gallery/photo.blade.php | 2 +- 9 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 database/migrations/2016_09_06_150902_add_photo_storage_file_column.php diff --git a/app/AlbumSources/LocalFilesystemSource.php b/app/AlbumSources/LocalFilesystemSource.php index f0b4efd..5fa266e 100644 --- a/app/AlbumSources/LocalFilesystemSource.php +++ b/app/AlbumSources/LocalFilesystemSource.php @@ -32,14 +32,14 @@ class LocalFilesystemSource implements IAlbumSource $thumbnail = $this->getOriginalsFolder(); } - return sprintf('%s/%s/%s', $this->getPathToAlbum($album), $thumbnail, $photo->file_name); + return sprintf('%s/%s/%s', $this->getPathToAlbum($album), $thumbnail, $photo->storage_file_name); } public function getUrlToPhoto(Album $album, Photo $photo, $thumbnail = null) { $photoUrl = route('downloadPhoto', [ 'albumUrlAlias' => $album->url_alias, - 'photoFilename' => $photo->file_name + 'photoFilename' => $photo->storage_file_name ]); if (!is_null($thumbnail)) @@ -53,7 +53,7 @@ class LocalFilesystemSource implements IAlbumSource public function saveThumbnail(Album $album, Photo $photo, $thumbnailInfo, $tempFilename) { $fileInfo = new File($tempFilename); - $fileInfo->move(sprintf('%s/%s', $this->getPathToAlbum($album), $thumbnailInfo['name']), $photo->file_name); + $fileInfo->move(sprintf('%s/%s', $this->getPathToAlbum($album), $thumbnailInfo['name']), $photo->storage_file_name); } public function saveUploadedPhoto(Album $album, File $uploadedFile) diff --git a/app/Http/Controllers/Admin/PhotoController.php b/app/Http/Controllers/Admin/PhotoController.php index 0100dd6..c2d98be 100644 --- a/app/Http/Controllers/Admin/PhotoController.php +++ b/app/Http/Controllers/Admin/PhotoController.php @@ -66,8 +66,9 @@ class PhotoController extends Controller $photo = new Photo(); $photo->album_id = $album->id; - $photo->name = $photoFile->getClientOriginalName(); - $photo->file_name = $savedFile->getFilename(); + $photo->name = pathinfo($photoFile->getClientOriginalName(), PATHINFO_FILENAME); + $photo->file_name = $photoFile->getClientOriginalName(); + $photo->storage_file_name = $savedFile->getFilename(); $photo->mime_type = $savedFile->getMimeType(); $photo->file_size = $savedFile->getSize(); $photo->save(); @@ -143,8 +144,9 @@ class PhotoController extends Controller $photo = new Photo(); $photo->album_id = $album->id; - $photo->name = $photoFile->getFilename(); - $photo->file_name = $savedFile->getFilename(); + $photo->name = pathinfo($photoFile->getFilename(), PATHINFO_FILENAME); + $photo->file_name = $photoFile->getFilename(); + $photo->storage_file_name = $savedFile->getFilename(); $photo->mime_type = $savedFile->getMimeType(); $photo->file_size = $savedFile->getSize(); $photo->save(); diff --git a/app/Http/Controllers/Gallery/PhotoController.php b/app/Http/Controllers/Gallery/PhotoController.php index 9c4beec..3498b2a 100644 --- a/app/Http/Controllers/Gallery/PhotoController.php +++ b/app/Http/Controllers/Gallery/PhotoController.php @@ -58,7 +58,7 @@ class PhotoController extends Controller { $photo = Photo::where([ ['album_id', $album->id], - ['file_name', $filename] + ['storage_file_name', $filename] ])->first(); if (is_null($photo)) diff --git a/app/Photo.php b/app/Photo.php index 260557a..b0bbfec 100644 --- a/app/Photo.php +++ b/app/Photo.php @@ -19,6 +19,7 @@ class Photo extends Model 'name', 'description', 'file_name', + 'storage_file_name', 'mime_type', 'file_size', 'metadata_version', @@ -46,9 +47,7 @@ class Photo extends Model public function thumbnailUrl($thumbnailName = null) { /** @var Album $album */ - //$album = Album::where('id', $this->album_id)->first(); $album = $this->album; - $albumSource = $album->getAlbumSource(); return $album->getAlbumSource()->getUrlToPhoto($album, $this, $thumbnailName); } @@ -57,7 +56,7 @@ class Photo extends Model { return route('viewPhoto', [ 'albumUrlAlias' => $this->album->url_alias, - 'photoFilename' => $this->file_name + 'photoFilename' => $this->storage_file_name ]); } } diff --git a/database/migrations/2016_09_06_150902_add_photo_storage_file_column.php b/database/migrations/2016_09_06_150902_add_photo_storage_file_column.php new file mode 100644 index 0000000..70befd1 --- /dev/null +++ b/database/migrations/2016_09_06_150902_add_photo_storage_file_column.php @@ -0,0 +1,32 @@ +string('storage_file_name'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('photos', function (Blueprint $table) { + $table->dropColumn('storage_file_name'); + }); + } +} diff --git a/resources/lang/en/admin.php b/resources/lang/en/admin.php index b6e483a..4946dd7 100644 --- a/resources/lang/en/admin.php +++ b/resources/lang/en/admin.php @@ -1,7 +1,7 @@ 'Actions', - 'album_no_photos_p1' => 'This album does not yet have any photos.', + 'album_no_photos_p1' => 'No photos in this album', 'album_no_photos_p2' => 'Click the "Upload photos" button below to get started.', 'album_no_photos_button' => 'Upload photos', 'album_photos_tab' => 'Photos', diff --git a/resources/views/themes/base/admin/list_albums.blade.php b/resources/views/themes/base/admin/list_albums.blade.php index 9138ea4..8ec6b57 100644 --- a/resources/views/themes/base/admin/list_albums.blade.php +++ b/resources/views/themes/base/admin/list_albums.blade.php @@ -7,7 +7,7 @@
@if (count($albums) == 0)
-

@lang('admin.no_albums_title')

+

@lang('admin.no_albums_title')

@lang('admin.no_albums_text')

@lang('admin.create_album') diff --git a/resources/views/themes/base/admin/show_album.blade.php b/resources/views/themes/base/admin/show_album.blade.php index 3f0f122..6b7920a 100644 --- a/resources/views/themes/base/admin/show_album.blade.php +++ b/resources/views/themes/base/admin/show_album.blade.php @@ -21,7 +21,7 @@

@if ($album->photos()->count() == 0)
-

@lang('admin.album_no_photos_p1')

+

@lang('admin.album_no_photos_p1')

@lang('admin.album_no_photos_p2')

diff --git a/resources/views/themes/base/gallery/photo.blade.php b/resources/views/themes/base/gallery/photo.blade.php index 4241aeb..d609bf6 100644 --- a/resources/views/themes/base/gallery/photo.blade.php +++ b/resources/views/themes/base/gallery/photo.blade.php @@ -39,7 +39,7 @@ File name: - {{ $photo->name }} + {{ $photo->file_name }} @if (strlen($photo->taken_at) > 0)