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:
@@ -76,11 +76,11 @@ final class ReportIncidentCommand
|
||||
public $stickied;
|
||||
|
||||
/**
|
||||
* The date at which the incident occurred.
|
||||
* The date at which the incident occurred at.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $incident_date;
|
||||
public $occurred_at;
|
||||
|
||||
/**
|
||||
* A given incident template.
|
||||
@@ -110,7 +110,7 @@ final class ReportIncidentCommand
|
||||
'component_status' => 'nullable|required_with:component_id|int|min:0|max:4',
|
||||
'notify' => 'nullable|bool',
|
||||
'stickied' => 'required|bool',
|
||||
'incident_date' => 'nullable|string',
|
||||
'occurred_at' => 'nullable|string',
|
||||
'template' => 'nullable|string',
|
||||
];
|
||||
|
||||
@@ -125,13 +125,13 @@ final class ReportIncidentCommand
|
||||
* @param int $component_status
|
||||
* @param bool $notify
|
||||
* @param bool $stickied
|
||||
* @param string|null $incident_date
|
||||
* @param string|null $occurred_at
|
||||
* @param string|null $template
|
||||
* @param array $template_vars
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($name, $status, $message, $visible, $component_id, $component_status, $notify, $stickied, $incident_date, $template, array $template_vars = [])
|
||||
public function __construct($name, $status, $message, $visible, $component_id, $component_status, $notify, $stickied, $occurred_at, $template, array $template_vars = [])
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->status = $status;
|
||||
@@ -141,7 +141,7 @@ final class ReportIncidentCommand
|
||||
$this->component_status = $component_status;
|
||||
$this->notify = $notify;
|
||||
$this->stickied = $stickied;
|
||||
$this->incident_date = $incident_date;
|
||||
$this->occurred_at = $occurred_at;
|
||||
$this->template = $template;
|
||||
$this->template_vars = $template_vars;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,13 @@ namespace CachetHQ\Cachet\Bus\Commands\Incident;
|
||||
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
|
||||
/**
|
||||
* This is the update incident command.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
* @author Joseph Cohem <joe@alt-three.com>
|
||||
* @author Graham Campbell <graham@alt-three.com>
|
||||
*/
|
||||
final class UpdateIncidentCommand
|
||||
{
|
||||
/**
|
||||
@@ -79,11 +86,11 @@ final class UpdateIncidentCommand
|
||||
public $stickied;
|
||||
|
||||
/**
|
||||
* The date that the incident occurred on.
|
||||
* The timestamp that the incident occurred at.
|
||||
*
|
||||
* @var string
|
||||
* @var string|null
|
||||
*/
|
||||
public $incident_date;
|
||||
public $occurred_at;
|
||||
|
||||
/**
|
||||
* A given incident template.
|
||||
@@ -113,6 +120,7 @@ final class UpdateIncidentCommand
|
||||
'component_status' => 'nullable|int|min:0|max:4|required_with:component_id',
|
||||
'notify' => 'nullable|bool',
|
||||
'stickied' => 'nullable|bool',
|
||||
'occurred_at' => 'nullable|string',
|
||||
'template' => 'nullable|string',
|
||||
];
|
||||
|
||||
@@ -128,13 +136,13 @@ final class UpdateIncidentCommand
|
||||
* @param int $component_status
|
||||
* @param bool $notify
|
||||
* @param bool $stickied
|
||||
* @param string|null $incident_date
|
||||
* @param string|null $occurred_at
|
||||
* @param string|null $template
|
||||
* @param array $template_vars
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Incident $incident, $name, $status, $message, $visible, $component_id, $component_status, $notify, $stickied, $incident_date, $template, array $template_vars = [])
|
||||
public function __construct(Incident $incident, $name, $status, $message, $visible, $component_id, $component_status, $notify, $stickied, $occurred_at, $template, array $template_vars = [])
|
||||
{
|
||||
$this->incident = $incident;
|
||||
$this->name = $name;
|
||||
@@ -145,7 +153,7 @@ final class UpdateIncidentCommand
|
||||
$this->component_status = $component_status;
|
||||
$this->notify = $notify;
|
||||
$this->stickied = $stickied;
|
||||
$this->incident_date = $incident_date;
|
||||
$this->occurred_at = $occurred_at;
|
||||
$this->template = $template;
|
||||
$this->template_vars = $template_vars;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Bus\Exceptions\Incident;
|
||||
|
||||
use CachetHQ\Cachet\Bus\Exceptions\ExceptionInterface;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* This is the invalid incident timestamp exception.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
class InvalidIncidentTimestampException extends Exception implements ExceptionInterface
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -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