diff --git a/extensions/flags/src/Command/CreateFlagHandler.php b/extensions/flags/src/Command/CreateFlagHandler.php index 9be436301..10a4fcec0 100644 --- a/extensions/flags/src/Command/CreateFlagHandler.php +++ b/extensions/flags/src/Command/CreateFlagHandler.php @@ -9,12 +9,14 @@ namespace Flarum\Flags\Command; +use Flarum\Flags\Event\Created; use Flarum\Flags\Flag; use Flarum\Foundation\ValidationException; use Flarum\Post\CommentPost; use Flarum\Post\PostRepository; use Flarum\Settings\SettingsRepositoryInterface; use Flarum\User\Exception\PermissionDeniedException; +use Illuminate\Events\Dispatcher; use Illuminate\Support\Arr; use Symfony\Component\Translation\TranslatorInterface; use Tobscure\JsonApi\Exception\InvalidParameterException; @@ -36,15 +38,23 @@ class CreateFlagHandler */ protected $settings; + /** + * @var Dispatcher + */ + protected $events; + /** * @param PostRepository $posts * @param TranslatorInterface $translator + * @param SettingsRepositoryInterface $settings + * @param Dispatcher $events */ - public function __construct(PostRepository $posts, TranslatorInterface $translator, SettingsRepositoryInterface $settings) + public function __construct(PostRepository $posts, TranslatorInterface $translator, SettingsRepositoryInterface $settings, Dispatcher $events) { $this->posts = $posts; $this->translator = $translator; $this->settings = $settings; + $this->events = $events; } /** @@ -93,6 +103,8 @@ class CreateFlagHandler $flag->save(); + $this->events->dispatch(new Created($flag, $actor, $data)); + return $flag; } } diff --git a/extensions/flags/src/Command/DeleteFlagsHandler.php b/extensions/flags/src/Command/DeleteFlagsHandler.php index 06a405703..d38f3e0b4 100644 --- a/extensions/flags/src/Command/DeleteFlagsHandler.php +++ b/extensions/flags/src/Command/DeleteFlagsHandler.php @@ -9,10 +9,11 @@ namespace Flarum\Flags\Command; +use Flarum\Flags\Event\Deleting; use Flarum\Flags\Event\FlagsWillBeDeleted; use Flarum\Flags\Flag; use Flarum\Post\PostRepository; -use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Events\Dispatcher; class DeleteFlagsHandler { @@ -48,8 +49,13 @@ class DeleteFlagsHandler $actor->assertCan('viewFlags', $post->discussion); + // remove beta 17 $this->events->dispatch(new FlagsWillBeDeleted($post, $actor, $command->data)); + foreach ($post->flags as $flag) { + $this->events->dispatch(new Deleting($flag, $actor, $command->data)); + } + $post->flags()->delete(); return $post; diff --git a/extensions/flags/src/Event/Created.php b/extensions/flags/src/Event/Created.php new file mode 100644 index 000000000..8c2949842 --- /dev/null +++ b/extensions/flags/src/Event/Created.php @@ -0,0 +1,43 @@ +flag = $flag; + $this->actor = $actor; + $this->data = $data; + } +} diff --git a/extensions/flags/src/Event/Deleting.php b/extensions/flags/src/Event/Deleting.php new file mode 100644 index 000000000..ae7e585e2 --- /dev/null +++ b/extensions/flags/src/Event/Deleting.php @@ -0,0 +1,43 @@ +flag = $flag; + $this->actor = $actor; + $this->data = $data; + } +} diff --git a/extensions/flags/src/Event/FlagsWillBeDeleted.php b/extensions/flags/src/Event/FlagsWillBeDeleted.php index 489a76e27..aea44416d 100644 --- a/extensions/flags/src/Event/FlagsWillBeDeleted.php +++ b/extensions/flags/src/Event/FlagsWillBeDeleted.php @@ -12,6 +12,10 @@ namespace Flarum\Flags\Event; use Flarum\Post\Post; use Flarum\User\User; +/** + * @deprecated 0.1.0-beta.16, remove 0.1.0-beta.17 + * Listen for Flarum\Flags\Event\Deleting instead + */ class FlagsWillBeDeleted { /**