diff --git a/app/Commands/EditTrackCommand.php b/app/Commands/EditTrackCommand.php index 8fe02289..ebfc27d9 100644 --- a/app/Commands/EditTrackCommand.php +++ b/app/Commands/EditTrackCommand.php @@ -179,9 +179,9 @@ class EditTrackCommand extends CommandBase } if (isset($this->_input['hwc_submit']) && new \DateTime() < new \DateTime("2016-12-18 00:00:00")) { - $playlist = Playlist::where('id', 658)->first(); + $playlist = Playlist::where('user_id', 22549)->first(); - if ($this->_input['hwc_submit'] === true) { + if ($this->_input['hwc_submit'] == true) { if (!$playlist->tracks()->get()->contains($track)) { $songIndex = $playlist->trackCount() + 1; $playlist->tracks()->attach($track, ['position' => $songIndex]); @@ -191,6 +191,14 @@ class EditTrackCommand extends CommandBase 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')') ]); } + } else { + if ($playlist->tracks()->get()->contains($track)) { + $playlist->tracks()->detach($track); + + Playlist::whereId($playlist->id)->update([ + 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')') + ]); + } } } diff --git a/app/Models/Track.php b/app/Models/Track.php index 0d32cd41..ca798fe4 100644 --- a/app/Models/Track.php +++ b/app/Models/Track.php @@ -534,7 +534,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable $returnValue['username'] = User::whereId($track->user_id)->first()->username; // Seasonal - $returnValue['hwc_submit'] = Playlist::where('id', 658)->first()->tracks()->get()->contains($track); + $returnValue['hwc_submit'] = Playlist::where('user_id', 22549)->first()->tracks()->get()->contains($track); return $returnValue; }