mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 07:17:34 +08:00
Don't allow empty post content
Parsing the post content makes it non-empty (`<t></t>`), so we don't parse it if it is empty. Also delete a created discussion if the first post was invalid. closes flarum/core#224
This commit is contained in:
parent
9a0190e13a
commit
58223b8a23
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user