From bb106d35fead101ac1b0e489bd753f08aa55fa34 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 28 Oct 2015 13:58:20 +0000 Subject: [PATCH] Improved and fixed the report incident command handler --- .../Incident/ReportIncidentCommandHandler.php | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php b/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php index 10bd6291..e0f6e8c3 100644 --- a/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php +++ b/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php @@ -29,24 +29,29 @@ class ReportIncidentCommandHandler */ public function handle(ReportIncidentCommand $command) { - $incident = Incident::create([ - 'name' => $command->name, - 'status' => $command->status, - 'message' => $command->message, - 'visible' => $command->visible, - 'component_id' => $command->component_id, - ]); + $data = [ + 'name' => $command->name, + 'status' => $command->status, + 'message' => $command->message, + 'visible' => $command->visible, + ]; + + // Link with the component. + if ($command->component_id) { + $data['component_id'] = $command->component_id; + } // The incident occurred at a different time. if ($command->incident_date) { $incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone')); - $incident->update([ - 'created_at' => $incidentDate, - 'updated_at' => $incidentDate, - ]); + $data['created_at'] = $incidentDate; + $data['updated_at'] = $incidentDate; } + // Create the incident + $incident = Incident::create($data); + // Update the component. if ($command->component_id) { Component::find($command->component_id)->update([