Add incident column for when an incident occurred at (#2212)
Add incident column for when an incident occurred at. Closes #2208 [ci skip] [skip ci]
This commit is contained in:
@@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Bus\Handlers\Commands\Incident;
|
||||
use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand;
|
||||
use CachetHQ\Cachet\Bus\Commands\Incident\ReportIncidentCommand;
|
||||
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasReportedEvent;
|
||||
use CachetHQ\Cachet\Bus\Exceptions\Incident\InvalidIncidentTimestampException;
|
||||
use CachetHQ\Cachet\Dates\DateFactory;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
@@ -75,11 +76,12 @@ class ReportIncidentCommandHandler
|
||||
}
|
||||
|
||||
// The incident occurred at a different time.
|
||||
if ($command->incident_date) {
|
||||
$incidentDate = $this->dates->create('d/m/Y H:i', $command->incident_date);
|
||||
|
||||
$data['created_at'] = $incidentDate;
|
||||
$data['updated_at'] = $incidentDate;
|
||||
if ($occurredAt = $command->occurredAt) {
|
||||
if ($date = $this->dates->create('Y-m-d H:i', $occurredAt)) {
|
||||
$incident->fill(['occurred_at' => $date]);
|
||||
} else {
|
||||
throw new InvalidIncidentTimestampException("Unable to pass timestamp {$occurredAt}");
|
||||
}
|
||||
}
|
||||
|
||||
// Create the incident
|
||||
@@ -127,7 +129,7 @@ class ReportIncidentCommandHandler
|
||||
'visible' => $command->visible,
|
||||
'notify' => $command->notify,
|
||||
'stickied' => $command->stickied,
|
||||
'incident_date' => $command->incident_date,
|
||||
'occurredAt' => $command->occurredAt,
|
||||
'component' => Component::find($command->component_id) ?: null,
|
||||
'component_status' => $command->component_status,
|
||||
],
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Bus\Handlers\Commands\Incident;
|
||||
use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand;
|
||||
use CachetHQ\Cachet\Bus\Commands\Incident\UpdateIncidentCommand;
|
||||
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasUpdatedEvent;
|
||||
use CachetHQ\Cachet\Bus\Exceptions\Incident\InvalidIncidentTimestampException;
|
||||
use CachetHQ\Cachet\Dates\DateFactory;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
@@ -61,18 +62,20 @@ class UpdateIncidentCommandHandler
|
||||
}
|
||||
|
||||
$incident = $command->incident;
|
||||
$incident->update($this->filter($command));
|
||||
$incident->fill($this->filter($command));
|
||||
|
||||
// The incident occurred at a different time.
|
||||
if ($command->incident_date) {
|
||||
$incidentDate = $this->dates->create('d/m/Y H:i', $command->incident_date);
|
||||
|
||||
$incident->update([
|
||||
'created_at' => $incidentDate,
|
||||
'updated_at' => $incidentDate,
|
||||
]);
|
||||
if ($occurredAt = $command->occurredAt) {
|
||||
if ($date = $this->dates->create('Y-m-d H:i', $occurredAt)) {
|
||||
$incident->fill(['occurred_at' => $date]);
|
||||
} else {
|
||||
throw new InvalidIncidentTimestampException("Unable to pass timestamp {$occurredAt}");
|
||||
}
|
||||
}
|
||||
|
||||
// Rather than making lots of updates, just fill and save.
|
||||
$incident->save();
|
||||
|
||||
// Update the component.
|
||||
if ($component = Component::find($command->component_id)) {
|
||||
dispatch(new UpdateComponentCommand(
|
||||
@@ -138,7 +141,7 @@ class UpdateIncidentCommandHandler
|
||||
'visible' => $command->visible,
|
||||
'notify' => $command->notify,
|
||||
'stickied' => $command->stickied,
|
||||
'incident_date' => $command->incident_date,
|
||||
'occurredAt' => $command->occurredAt,
|
||||
'component' => Component::find($command->component_id) ?: null,
|
||||
'component_status' => $command->component_status,
|
||||
],
|
||||
|
||||
@@ -114,7 +114,7 @@ class SendIncidentEmailNotificationHandler
|
||||
'has_component' => ($event->incident->component) ? true : false,
|
||||
'component_name' => $component ? $component->name : null,
|
||||
'name' => $incident->name,
|
||||
'timestamp' => $incident->created_at_formatted,
|
||||
'timestamp' => $incident->occurred_at_formatted,
|
||||
'status' => $incident->human_status,
|
||||
'html_content' => $incident->formattedMessage,
|
||||
'text_content' => $incident->message,
|
||||
|
||||
Reference in New Issue
Block a user