1
0
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:
Toby Zerner
2016-02-26 13:26:09 +10:30
parent f375fd9241
commit 2f187dfd65
4 changed files with 40 additions and 12 deletions

View File

@@ -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();
}
}
/**

View File

@@ -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));
});