resolves #2: photos can now be moved between albums. Started improving the bulk photo update to use a KnockoutJS view model to remove some of the logic from the view itself.

This commit is contained in:
Andy Heathershaw
2016-10-05 05:02:47 +01:00
parent 45277efbb8
commit 0e569562a4
11 changed files with 336 additions and 111 deletions
+27
View File
@@ -7,6 +7,7 @@ use App\AlbumSources\IAlbumSource;
use App\Helpers\ImageHelper;
use App\Helpers\ThemeHelper;
use App\Photo;
use Symfony\Component\HttpFoundation\File\File;
class PhotoService
{
@@ -118,6 +119,32 @@ class PhotoService
$this->regenerateThumbnails($originalPhotoResource);
}
public function changeAlbum(Album $newAlbum)
{
/** @var IAlbumSource $currentSource */
$currentSource = $this->photo->album->getAlbumSource();
$newSource = $newAlbum->getAlbumSource();
// Get the current photo's path
$file = new File($currentSource->getPathToPhoto($this->photo));
// Save to the new album
$newSource->saveUploadedPhoto($file, $this->photo->storage_file_name);
// Delete the original
$this->delete();
// Update the ID and new file name
$this->photo->album_id = $newAlbum->id;
$this->photo->save();
// Switch to the new album source
$this->albumSource = $newSource;
// Regenerate the thumbnails in the new album
$this->regenerateThumbnails();
}
public function delete()
{
// Remove all thumbnails first - so if any fail, we don't delete the original