Fixes T372 for all content types. Also fixes album and playlist downloads following T350.

This commit is contained in:
Peter Deltchev 2015-09-12 21:33:56 -07:00
parent 01ebdf5ac0
commit 5188e4947c
7 changed files with 38 additions and 12 deletions

View file

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

View file

@ -1,5 +1,9 @@
<?php
namespace App;
use ZipStream;
class AlbumDownloader
{
private $_album;

View file

@ -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;
@ -76,12 +79,25 @@ class CreateCommentCommand extends CommandBase
$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));
}
}

View file

@ -70,7 +70,7 @@ 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 . ')')
]);

View file

@ -2,7 +2,7 @@
namespace App\Http\Controllers;
use AlbumDownloader;
use App\AlbumDownloader;
use App;
use App\Album;
use App\ResourceLogItem;

View file

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

View file

@ -1,5 +1,9 @@
<?php
namespace App;
use ZipStream;
class PlaylistDownloader
{
private $_playlist;