mirror of
https://github.com/flarum/core.git
synced 2025-07-26 03:01:22 +02:00
Delete a discussion when its last post is deleted. fixes #823
This commit is contained in:
@@ -51,6 +51,12 @@ class DiscussionMetadataUpdater
|
||||
public function whenPostWasDeleted(PostWasDeleted $event)
|
||||
{
|
||||
$this->removePost($event->post);
|
||||
|
||||
$discussion = $event->post->discussion;
|
||||
|
||||
if ($discussion->comments_count === 0) {
|
||||
$discussion->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -88,14 +88,6 @@ class Post extends AbstractModel
|
||||
$post->discussion->save();
|
||||
});
|
||||
|
||||
// Don't allow the first post in a discussion to be deleted, because
|
||||
// it doesn't make sense. The discussion must be deleted instead.
|
||||
static::deleting(function (Post $post) {
|
||||
if ($post->number == 1) {
|
||||
throw new DomainException('Cannot delete the first post of a discussion');
|
||||
}
|
||||
});
|
||||
|
||||
static::deleted(function (Post $post) {
|
||||
$post->raise(new PostWasDeleted($post));
|
||||
});
|
||||
|
Reference in New Issue
Block a user