From 5188e4947c9a975f99394f68f3be4f854eeba3fe Mon Sep 17 00:00:00 2001 From: Peter Deltchev Date: Sat, 12 Sep 2015 21:33:56 -0700 Subject: [PATCH] Fixes T372 for all content types. Also fixes album and playlist downloads following T350. --- app/Album.php | 1 + app/AlbumDownloader.php | 6 ++++- app/Commands/CreateCommentCommand.php | 26 ++++++++++++++++---- app/Commands/EditAlbumCommand.php | 4 +-- app/Http/Controllers/AlbumsController.php | 4 +-- app/Http/Controllers/PlaylistsController.php | 3 ++- app/PlaylistDownloader.php | 6 ++++- 7 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/Album.php b/app/Album.php index 87904abb..223d74ec 100644 --- a/app/Album.php +++ b/app/Album.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\URL; use App\Traits\SlugTrait; +use Helpers; class Album extends Model { diff --git a/app/AlbumDownloader.php b/app/AlbumDownloader.php index 50ea54e4..384e9d64 100644 --- a/app/AlbumDownloader.php +++ b/app/AlbumDownloader.php @@ -1,5 +1,9 @@ addFile($notes, $directory . 'Album Notes.txt'); $zip->finalize(); } -} \ No newline at end of file +} diff --git a/app/Commands/CreateCommentCommand.php b/app/Commands/CreateCommentCommand.php index bd1eb7ec..8f7e6c7d 100644 --- a/app/Commands/CreateCommentCommand.php +++ b/app/Commands/CreateCommentCommand.php @@ -2,8 +2,11 @@ namespace App\Commands; +use App\Album; use App\Comment; +use App\Playlist; use App\Track; +use App\User; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; @@ -74,14 +77,27 @@ class CreateCommentCommand extends CommandBase $comment->$column = $this->_id; $comment->save(); - + // Recount the track's comments, if this is a track comment - if ($this->_type == 'track') { - $track = Track::find($this->_id); - $track->comment_count = Comment::where('track_id', $this->_id)->count(); - $track->save(); + if ($this->_type === 'track') { + $entity = Track::find($this->_id); + + } elseif ($this->_type === 'album') { + $entity = Album::find($this->_id); + + } elseif ($this->_type === 'playlist') { + $entity = Playlist::find($this->_id); + + } elseif ($this->_type === 'user') { + $entity = User::find($this->_id); + + } else { + App::abort(400, 'This comment is being added to an invalid entity!'); } + $entity->comment_count = Comment::where($column, $this->_id)->count(); + $entity->save(); + return CommandResponse::succeed(Comment::mapPublic($comment)); } } diff --git a/app/Commands/EditAlbumCommand.php b/app/Commands/EditAlbumCommand.php index b2c96ba1..9f594bc5 100644 --- a/app/Commands/EditAlbumCommand.php +++ b/app/Commands/EditAlbumCommand.php @@ -70,10 +70,10 @@ class EditAlbumCommand extends CommandBase $this->_album->syncTrackIds($trackIds); $this->_album->save(); - Album::whereId($this->_album->id)->update([ + Album::where('id', $this->_album->id)->update([ 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE album_id = ' . $this->_album->id . ')') ]); return CommandResponse::succeed(['real_cover_url' => $this->_album->getCoverUrl(Image::NORMAL)]); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/AlbumsController.php b/app/Http/Controllers/AlbumsController.php index 4a2dacc5..c8799ac5 100644 --- a/app/Http/Controllers/AlbumsController.php +++ b/app/Http/Controllers/AlbumsController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use AlbumDownloader; +use App\AlbumDownloader; use App; use App\Album; use App\ResourceLogItem; @@ -67,4 +67,4 @@ class AlbumsController extends Controller $downloader = new AlbumDownloader($album, $formatName); $downloader->download(); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/PlaylistsController.php b/app/Http/Controllers/PlaylistsController.php index 13ee0dac..a2a3214d 100644 --- a/app/Http/Controllers/PlaylistsController.php +++ b/app/Http/Controllers/PlaylistsController.php @@ -6,6 +6,7 @@ use App; use App\Playlist; use App\ResourceLogItem; use App\Track; +use App\PlaylistDownloader; use Auth; use Illuminate\Support\Facades\Redirect; use View; @@ -67,4 +68,4 @@ class PlaylistsController extends Controller $downloader = new PlaylistDownloader($playlist, $formatName); $downloader->download(); } -} \ No newline at end of file +} diff --git a/app/PlaylistDownloader.php b/app/PlaylistDownloader.php index 6194f3ba..c95778ce 100644 --- a/app/PlaylistDownloader.php +++ b/app/PlaylistDownloader.php @@ -1,5 +1,9 @@ addFile($m3u, $playlistDir . $this->_playlist->title . '.m3u'); $zip->finalize(); } -} \ No newline at end of file +}