From 4d47a24eff238325b63c40df823bd1ba4f0a86db Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Mon, 30 Apr 2018 11:19:43 +0200 Subject: [PATCH] adds events to hook into --- extensions/suspend/src/Event/Suspended.php | 23 +++++++++++++++++++ extensions/suspend/src/Event/Unsuspended.php | 23 +++++++++++++++++++ .../src/Listener/SaveSuspensionToDatabase.php | 17 +++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 extensions/suspend/src/Event/Suspended.php create mode 100644 extensions/suspend/src/Event/Unsuspended.php diff --git a/extensions/suspend/src/Event/Suspended.php b/extensions/suspend/src/Event/Suspended.php new file mode 100644 index 000000000..ff8c1c9f8 --- /dev/null +++ b/extensions/suspend/src/Event/Suspended.php @@ -0,0 +1,23 @@ +user = $user; + $this->actor = $actor; + } +} diff --git a/extensions/suspend/src/Event/Unsuspended.php b/extensions/suspend/src/Event/Unsuspended.php new file mode 100644 index 000000000..db98fa8b2 --- /dev/null +++ b/extensions/suspend/src/Event/Unsuspended.php @@ -0,0 +1,23 @@ +user = $user; + $this->actor = $actor; + } +} diff --git a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php index 0a7c39e03..79440a512 100755 --- a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php +++ b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php @@ -12,6 +12,8 @@ namespace Flarum\Suspend\Listener; use DateTime; +use Flarum\Suspend\Event\Suspended; +use Flarum\Suspend\Event\Unsuspended; use Flarum\Suspend\SuspendValidator; use Flarum\User\AssertPermissionTrait; use Flarum\User\Event\Saving; @@ -27,13 +29,18 @@ class SaveSuspensionToDatabase * @var SuspendValidator */ protected $validator; + /** + * @var Dispatcher + */ + protected $events; /** * @param SuspendValidator $validator */ - public function __construct(SuspendValidator $validator) + public function __construct(SuspendValidator $validator, Dispatcher $events) { $this->validator = $validator; + $this->events = $events; } /** @@ -62,6 +69,14 @@ class SaveSuspensionToDatabase $user->suspend_until = $attributes['suspendUntil'] ? new DateTime($attributes['suspendUntil']) : null; + + if ($user->isDirty('suspend_until')) { + $this->events->dispatch( + $user->suspend_until === null ? + new Unsuspended($user, $actor) : + new Suspended($user, $actor) + ); + } } } }