1
0
mirror of https://github.com/flarum/core.git synced 2025-07-24 10:11:43 +02:00

update a user's comment count if deleting a discussion (#2472)

This commit is contained in:
sl-kr
2020-11-29 17:11:05 -05:00
committed by GitHub
parent 8536285106
commit 5450fcda00

View File

@@ -14,7 +14,6 @@ use Flarum\Discussion\Event\Deleted as DiscussionDeleted;
use Flarum\Discussion\Event\Started;
use Flarum\Post\Event\Deleted as PostDeleted;
use Flarum\Post\Event\Posted;
use Flarum\Post\Post;
use Illuminate\Contracts\Events\Dispatcher;
class UserMetadataUpdater
@@ -35,7 +34,7 @@ class UserMetadataUpdater
*/
public function whenPostWasPosted(Posted $event)
{
$this->updateCommentsCount($event->post);
$this->updateCommentsCount($event->post->user);
}
/**
@@ -43,7 +42,7 @@ class UserMetadataUpdater
*/
public function whenPostWasDeleted(PostDeleted $event)
{
$this->updateCommentsCount($event->post);
$this->updateCommentsCount($event->post->user);
}
/**
@@ -60,12 +59,14 @@ class UserMetadataUpdater
public function whenDiscussionWasDeleted(DiscussionDeleted $event)
{
$this->updateDiscussionsCount($event->discussion);
$this->updateCommentsCount($event->discussion->user);
}
private function updateCommentsCount(Post $post)
/**
* @param \Flarum\User\User $user
*/
private function updateCommentsCount(User $user)
{
$user = $post->user;
if ($user && $user->exists) {
$user->refreshCommentCount()->save();
}