mirror of
https://github.com/flarum/framework.git
synced 2025-04-02 23:19:04 +08:00
Clean up event handlers
This commit is contained in:
parent
a3f44dea62
commit
e6a987ff12
@ -5,16 +5,16 @@ use Flarum\Core\Events\PostWasPosted;
|
|||||||
use Flarum\Core\Events\PostWasDeleted;
|
use Flarum\Core\Events\PostWasDeleted;
|
||||||
use Flarum\Core\Events\PostWasHidden;
|
use Flarum\Core\Events\PostWasHidden;
|
||||||
use Flarum\Core\Events\PostWasRestored;
|
use Flarum\Core\Events\PostWasRestored;
|
||||||
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class DiscussionMetadataUpdater
|
class DiscussionMetadataUpdater
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Register the listeners for the subscriber.
|
* Register the listeners for the subscriber.
|
||||||
*
|
*
|
||||||
* @param Illuminate\Events\Dispatcher $events
|
* @param \Illuminate\Contracts\Events\Dispatcher $events
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function subscribe($events)
|
public function subscribe(Dispatcher $events)
|
||||||
{
|
{
|
||||||
$events->listen('Flarum\Core\Events\PostWasPosted', __CLASS__.'@whenPostWasPosted');
|
$events->listen('Flarum\Core\Events\PostWasPosted', __CLASS__.'@whenPostWasPosted');
|
||||||
$events->listen('Flarum\Core\Events\PostWasDeleted', __CLASS__.'@whenPostWasDeleted');
|
$events->listen('Flarum\Core\Events\PostWasDeleted', __CLASS__.'@whenPostWasDeleted');
|
||||||
|
@ -4,6 +4,7 @@ use Flarum\Core\Events\DiscussionWasRenamed;
|
|||||||
use Flarum\Core\Models\DiscussionRenamedPost;
|
use Flarum\Core\Models\DiscussionRenamedPost;
|
||||||
use Flarum\Core\Notifications\Types\DiscussionRenamedNotification;
|
use Flarum\Core\Notifications\Types\DiscussionRenamedNotification;
|
||||||
use Flarum\Core\Notifications\Notifier;
|
use Flarum\Core\Notifications\Notifier;
|
||||||
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class DiscussionRenamedNotifier
|
class DiscussionRenamedNotifier
|
||||||
{
|
{
|
||||||
@ -15,10 +16,9 @@ class DiscussionRenamedNotifier
|
|||||||
/**
|
/**
|
||||||
* Register the listeners for the subscriber.
|
* Register the listeners for the subscriber.
|
||||||
*
|
*
|
||||||
* @param Illuminate\Events\Dispatcher $events
|
* @param \Illuminate\Contracts\Events\Dispatcher $events
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function subscribe($events)
|
public function subscribe(Dispatcher $events)
|
||||||
{
|
{
|
||||||
$events->listen('Flarum\Core\Events\DiscussionWasRenamed', __CLASS__.'@whenDiscussionWasRenamed');
|
$events->listen('Flarum\Core\Events\DiscussionWasRenamed', __CLASS__.'@whenDiscussionWasRenamed');
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ use Illuminate\Mail\Mailer;
|
|||||||
use Flarum\Core\Events\UserWasRegistered;
|
use Flarum\Core\Events\UserWasRegistered;
|
||||||
use Flarum\Core\Events\EmailWasChanged;
|
use Flarum\Core\Events\EmailWasChanged;
|
||||||
use Config;
|
use Config;
|
||||||
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class EmailConfirmationMailer
|
class EmailConfirmationMailer
|
||||||
{
|
{
|
||||||
@ -17,10 +18,9 @@ class EmailConfirmationMailer
|
|||||||
/**
|
/**
|
||||||
* Register the listeners for the subscriber.
|
* Register the listeners for the subscriber.
|
||||||
*
|
*
|
||||||
* @param Illuminate\Events\Dispatcher $events
|
* @param \Illuminate\Contracts\Events\Dispatcher $events
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function subscribe($events)
|
public function subscribe(Dispatcher $events)
|
||||||
{
|
{
|
||||||
$events->listen('Flarum\Core\Events\UserWasRegistered', __CLASS__.'@whenUserWasRegistered');
|
$events->listen('Flarum\Core\Events\UserWasRegistered', __CLASS__.'@whenUserWasRegistered');
|
||||||
$events->listen('Flarum\Core\Events\EmailWasChanged', __CLASS__.'@whenEmailWasChanged');
|
$events->listen('Flarum\Core\Events\EmailWasChanged', __CLASS__.'@whenEmailWasChanged');
|
||||||
|
@ -7,16 +7,16 @@ use Flarum\Core\Events\PostWasHidden;
|
|||||||
use Flarum\Core\Events\PostWasRestored;
|
use Flarum\Core\Events\PostWasRestored;
|
||||||
use Flarum\Core\Events\DiscussionWasStarted;
|
use Flarum\Core\Events\DiscussionWasStarted;
|
||||||
use Flarum\Core\Events\DiscussionWasDeleted;
|
use Flarum\Core\Events\DiscussionWasDeleted;
|
||||||
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class UserMetadataUpdater
|
class UserMetadataUpdater
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Register the listeners for the subscriber.
|
* Register the listeners for the subscriber.
|
||||||
*
|
*
|
||||||
* @param Illuminate\Events\Dispatcher $events
|
* @param \Illuminate\Contracts\Events\Dispatcher $events
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function subscribe($events)
|
public function subscribe(Dispatcher $events)
|
||||||
{
|
{
|
||||||
$events->listen('Flarum\Core\Events\PostWasPosted', __CLASS__.'@whenPostWasPosted');
|
$events->listen('Flarum\Core\Events\PostWasPosted', __CLASS__.'@whenPostWasPosted');
|
||||||
$events->listen('Flarum\Core\Events\PostWasDeleted', __CLASS__.'@whenPostWasDeleted');
|
$events->listen('Flarum\Core\Events\PostWasDeleted', __CLASS__.'@whenPostWasDeleted');
|
||||||
@ -28,22 +28,22 @@ class UserMetadataUpdater
|
|||||||
|
|
||||||
public function whenPostWasPosted(PostWasPosted $event)
|
public function whenPostWasPosted(PostWasPosted $event)
|
||||||
{
|
{
|
||||||
$this->updateRepliesCount($event->post->user, 1);
|
$this->updateCommentsCount($event->post->user, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function whenPostWasDeleted(PostWasDeleted $event)
|
public function whenPostWasDeleted(PostWasDeleted $event)
|
||||||
{
|
{
|
||||||
$this->updateRepliesCount($event->post->user, -1);
|
$this->updateCommentsCount($event->post->user, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function whenPostWasHidden(PostWasHidden $event)
|
public function whenPostWasHidden(PostWasHidden $event)
|
||||||
{
|
{
|
||||||
$this->updateRepliesCount($event->post->user, -1);
|
$this->updateCommentsCount($event->post->user, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function whenPostWasRestored(PostWasRestored $event)
|
public function whenPostWasRestored(PostWasRestored $event)
|
||||||
{
|
{
|
||||||
$this->updateRepliesCount($event->post->user, 1);
|
$this->updateCommentsCount($event->post->user, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function whenDiscussionWasStarted(DiscussionWasStarted $event)
|
public function whenDiscussionWasStarted(DiscussionWasStarted $event)
|
||||||
@ -56,7 +56,7 @@ class UserMetadataUpdater
|
|||||||
$this->updateDiscussionsCount($event->discussion->startUser, -1);
|
$this->updateDiscussionsCount($event->discussion->startUser, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updateRepliesCount(User $user, $amount)
|
protected function updateCommentsCount(User $user, $amount)
|
||||||
{
|
{
|
||||||
$user->comments_count += $amount;
|
$user->comments_count += $amount;
|
||||||
$user->save();
|
$user->save();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user