diff --git a/framework/core/src/Core/Discussions/Commands/StartDiscussionHandler.php b/framework/core/src/Core/Discussions/Commands/StartDiscussionHandler.php index 0e1456d7f..bf8b1d7dd 100644 --- a/framework/core/src/Core/Discussions/Commands/StartDiscussionHandler.php +++ b/framework/core/src/Core/Discussions/Commands/StartDiscussionHandler.php @@ -6,6 +6,7 @@ use Illuminate\Contracts\Bus\Dispatcher; use Flarum\Core\Discussions\Discussion; use Flarum\Core\Posts\Commands\PostReply; use Flarum\Core\Support\DispatchesEvents; +use Exception; class StartDiscussionHandler { @@ -57,9 +58,15 @@ class StartDiscussionHandler // Now that the discussion has been created, we can add the first post. // We will do this by running the PostReply command. - $post = $this->bus->dispatch( - new PostReply($discussion->id, $actor, $data) - ); + try { + $post = $this->bus->dispatch( + new PostReply($discussion->id, $actor, $data) + ); + } catch (Exception $e) { + $discussion->delete(); + + throw $e; + } // Before we dispatch events, refresh our discussion instance's // attributes as posting the reply will have changed some of them (e.g. diff --git a/framework/core/src/Core/Posts/CommentPost.php b/framework/core/src/Core/Posts/CommentPost.php index 1e6c3f20e..61173fb7a 100755 --- a/framework/core/src/Core/Posts/CommentPost.php +++ b/framework/core/src/Core/Posts/CommentPost.php @@ -142,7 +142,7 @@ class CommentPost extends Post */ public function setContentAttribute($value) { - $this->attributes['content'] = static::$formatter->parse($value, $this); + $this->attributes['content'] = $value ? static::$formatter->parse($value, $this) : null; } /**