From fcac32a67d5a22384cdcd7f52b93966f8db79dd3 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 3 Nov 2015 23:17:22 +0000 Subject: [PATCH] Refactors out notify conditions. Closes #1083 --- .../Commands/Incident/ReportMaintenanceCommandHandler.php | 4 +--- .../Commands/Incident/UpdateIncidentCommandHandler.php | 4 +--- .../Events/Incident/SendIncidentEmailNotificationHandler.php | 4 ++++ .../Incident/SendMaintenanceEmailNotificationHandler.php | 4 ++++ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php b/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php index 9fe832b7..b5842f55 100644 --- a/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php +++ b/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php @@ -41,9 +41,7 @@ class ReportMaintenanceCommandHandler ]); // Notify subscribers. - if ($command->notify) { - event(new MaintenanceWasScheduledEvent($maintenanceEvent)); - } + event(new MaintenanceWasScheduledEvent($maintenanceEvent)); return $maintenanceEvent; } diff --git a/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php b/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php index 015c984a..dc3af1ca 100644 --- a/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php +++ b/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php @@ -50,9 +50,7 @@ class UpdateIncidentCommandHandler } // Notify subscribers. - if ($command->notify) { - event(new IncidentWasUpdatedEvent($incident)); - } + event(new IncidentWasUpdatedEvent($incident)); return $incident; } diff --git a/app/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php b/app/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php index 69b88ddb..a5f09cbd 100644 --- a/app/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php +++ b/app/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php @@ -56,6 +56,10 @@ class SendIncidentEmailNotificationHandler */ public function handle(IncidentWasReportedEvent $event) { + if (!$event->incident->notify) { + return false; + } + $incident = AutoPresenter::decorate($event->incident); $component = AutoPresenter::decorate($event->incident->component); diff --git a/app/Handlers/Events/Incident/SendMaintenanceEmailNotificationHandler.php b/app/Handlers/Events/Incident/SendMaintenanceEmailNotificationHandler.php index 8ce7e087..d942979e 100644 --- a/app/Handlers/Events/Incident/SendMaintenanceEmailNotificationHandler.php +++ b/app/Handlers/Events/Incident/SendMaintenanceEmailNotificationHandler.php @@ -56,6 +56,10 @@ class SendMaintenanceEmailNotificationHandler */ public function handle(MaintenanceWasScheduledEvent $event) { + if (!$event->incident->notify) { + return false; + } + $data = AutoPresenter::decorate($event->incident); foreach ($this->subscriber->all() as $subscriber) {