From d01b24a91fac432813516f3da435adaf0da3e019 Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Sun, 15 May 2016 23:03:49 +0100 Subject: [PATCH] Admins can assign tracks to accounts --- app/Commands/EditTrackCommand.php | 15 +++++++++++++++ public/templates/directives/track-editor.html | 7 +++++++ .../scripts/app/directives/track-editor.coffee | 1 + resources/assets/scripts/app/services/auth.coffee | 2 +- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/Commands/EditTrackCommand.php b/app/Commands/EditTrackCommand.php index 5cdd8af2..900c94d5 100644 --- a/app/Commands/EditTrackCommand.php +++ b/app/Commands/EditTrackCommand.php @@ -146,6 +146,15 @@ class EditTrackCommand extends CommandBase } } + $oldid = null; + + if (isset($this->_input['user_id'])) { + if ($track->user_id != $this->_input['user_id']) { + $oldid = $track->user_id; + $track->user_id = $this->_input['user_id']; + } + } + $track->updateTags(); $track->save(); @@ -153,6 +162,12 @@ class EditTrackCommand extends CommandBase 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = ' . $this->_track->user_id . ')') ]); + if ($oldid != null) { + User::whereId($oldid)->update([ + 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = ' . $oldid . ')') + ]); + } + return CommandResponse::succeed(['real_cover_url' => $track->getCoverUrl(Image::NORMAL)]); } diff --git a/public/templates/directives/track-editor.html b/public/templates/directives/track-editor.html index 83406389..eae3f1bb 100644 --- a/public/templates/directives/track-editor.html +++ b/public/templates/directives/track-editor.html @@ -107,6 +107,13 @@ +
+
+ + +
{{errors.title}}
+
+