Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update a user's comment count after deleting a discussion #2472

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/User/UserMetadataUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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
Expand All @@ -35,15 +34,15 @@ public function subscribe(Dispatcher $events)
*/
public function whenPostWasPosted(Posted $event)
{
$this->updateCommentsCount($event->post);
$this->updateCommentsCount($event->post->user);
}

/**
* @param \Flarum\Post\Event\Deleted $event
*/
public function whenPostWasDeleted(PostDeleted $event)
{
$this->updateCommentsCount($event->post);
$this->updateCommentsCount($event->post->user);
}

/**
Expand All @@ -60,12 +59,14 @@ public function whenDiscussionWasStarted(Started $event)
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();
}
Expand Down