Added a separate storage_file_name column to the Photo class

This commit is contained in:
Andy Heathershaw 2016-09-06 19:47:25 +01:00
parent 484f5d8fb2
commit 626cd5b2ec
9 changed files with 48 additions and 15 deletions

View File

@ -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)

View File

@ -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();

View File

@ -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))

View File

@ -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
]);
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddPhotoStorageFileColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photos', function (Blueprint $table) {
$table->string('storage_file_name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photos', function (Blueprint $table) {
$table->dropColumn('storage_file_name');
});
}
}

View File

@ -1,7 +1,7 @@
<?php
return [
'actions_panel' => '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',

View File

@ -7,7 +7,7 @@
<div class="col-xs-12">
@if (count($albums) == 0)
<div class="text-center">
<h3>@lang('admin.no_albums_title')</h3>
<h4 class="text-danger"><b>@lang('admin.no_albums_title')</b></h4>
<p>@lang('admin.no_albums_text')</p>
<p style="margin-top: 40px;">
<a href="{{ route('albums.create') }}" class="btn btn-lg btn-success">@lang('admin.create_album')</a>

View File

@ -21,7 +21,7 @@
<div role="tabpanel" class="tab-pane active" id="photos-tab">
@if ($album->photos()->count() == 0)
<div class="text-center" style="margin-top: 30px;">
<p><b class="text-danger">@lang('admin.album_no_photos_p1')</b></p>
<h4 class="text-danger"><b>@lang('admin.album_no_photos_p1')</b></h4>
<p>@lang('admin.album_no_photos_p2')</p>
<p style="margin-top: 30px;"><button id="upload-button" class="btn btn-lg btn-success">@lang('admin.album_no_photos_button')</button></p>
</div>

View File

@ -39,7 +39,7 @@
<tbody>
<tr>
<td class="metadata_name">File name:</td>
<td class="metadata_value">{{ $photo->name }}</td>
<td class="metadata_value">{{ $photo->file_name }}</td>
</tr>
@if (strlen($photo->taken_at) > 0)