Another attempted bug fix

This commit is contained in:
Josef Citrine 2016-11-21 01:33:30 +00:00
parent f85b1ecdeb
commit 0e6afe372b
2 changed files with 11 additions and 3 deletions

View file

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

View file

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