From 45dae68497184e4390eb08e14ad5ca494214b6ac Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Mon, 11 Jul 2016 13:00:29 +0100 Subject: [PATCH] #86: Fixed track uploading SQL errors --- app/Commands/ParseTrackTagsCommand.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/Commands/ParseTrackTagsCommand.php b/app/Commands/ParseTrackTagsCommand.php index 3848f4b0..bb035376 100644 --- a/app/Commands/ParseTrackTagsCommand.php +++ b/app/Commands/ParseTrackTagsCommand.php @@ -95,10 +95,30 @@ class ParseTrackTagsCommand extends CommandBase $this->track->is_downloadable = $this->input['is_downloadable'] ?? true; $this->track->is_listed = $this->input['is_listed'] ?? true; + $this->track = $this->unsetNullVariables($this->track); + $this->track->save(); return CommandResponse::succeed(); } + /** + * If a value is null, remove it! Helps prevent weird SQL errors + * + * @param Track + * @return Track + */ + private function unsetNullVariables($track) { + $vars = $track->getAttributes(); + + foreach ($vars as $key => $value) { + if ($value == null) { + unset($track->{"$key"}); + } + } + + return $track; + } + /** * Returns the ID of the given genre, creating it if necessary. *