mirror of
https://github.com/flarum/framework.git
synced 2025-02-22 15:25:25 +08:00
update a user's comment count if deleting a discussion (#2472)
This commit is contained in:
parent
66482c2815
commit
387b4fd315
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user