From aceda914bdbc1908af5e019d4e5fd09292bc0e37 Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Tue, 22 Oct 2019 08:15:52 +0800 Subject: [PATCH] Check that logged in user exists before assigning to post. Resolves an issue where the seeder fails in the migrations because it's usually run in a context where there is no user. Fixes #480. --- models/Post.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/models/Post.php b/models/Post.php index f360db36..9172660a 100644 --- a/models/Post.php +++ b/models/Post.php @@ -141,7 +141,9 @@ public function beforeSave() { if (empty($this->user)) { $user = BackendAuth::getUser(); - $this->user = $user->id; + if (!is_null($user)) { + $this->user = $user->id; + } } $this->content_html = self::formatHtml($this->content); }