From b40066b20e0d5b3262d81c69d4edeeb60f7d8a00 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Thu, 29 Sep 2016 10:03:47 +0100 Subject: [PATCH] Don't fire component update emails if the status hasn't changed. Fixes #2113 --- .../Commands/Component/UpdateComponentCommandHandler.php | 5 ++--- .../SendComponentUpdateEmailNotificationHandler.php | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Bus/Handlers/Commands/Component/UpdateComponentCommandHandler.php b/app/Bus/Handlers/Commands/Component/UpdateComponentCommandHandler.php index bdead38f..cf45d8bc 100644 --- a/app/Bus/Handlers/Commands/Component/UpdateComponentCommandHandler.php +++ b/app/Bus/Handlers/Commands/Component/UpdateComponentCommandHandler.php @@ -28,10 +28,9 @@ class UpdateComponentCommandHandler public function handle(UpdateComponentCommand $command) { $component = $command->component; + $originalStatus = $component->status; - if ($command->status && $component->status !== $command->status) { - event(new ComponentStatusWasUpdatedEvent($component, $component->status, $command->status)); - } + event(new ComponentStatusWasUpdatedEvent($component, $originalStatus, $command->status)); $component->update($this->filter($command)); diff --git a/app/Bus/Handlers/Events/Component/SendComponentUpdateEmailNotificationHandler.php b/app/Bus/Handlers/Events/Component/SendComponentUpdateEmailNotificationHandler.php index 6d0b747d..e6f66f03 100644 --- a/app/Bus/Handlers/Events/Component/SendComponentUpdateEmailNotificationHandler.php +++ b/app/Bus/Handlers/Events/Component/SendComponentUpdateEmailNotificationHandler.php @@ -59,6 +59,11 @@ class SendComponentUpdateEmailNotificationHandler { $component = $event->component; + // Don't email anything if the status hasn't changed. + if ($event->original_status === $event->new_status) { + return; + } + // First notify all global subscribers. $globalSubscribers = $this->subscriber->isVerified()->isGlobal()->get();