mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 21:49:01 +01:00
$incident_date is now handled by the command handler
This commit is contained in:
parent
3ca1ae5d70
commit
08e9705088
@ -62,6 +62,13 @@ class ReportIncidentCommand
|
||||
*/
|
||||
public $notify;
|
||||
|
||||
/**
|
||||
* The date at which the incident occurred.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $incident_date;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
@ -75,22 +82,24 @@ class ReportIncidentCommand
|
||||
'component_id' => 'integer',
|
||||
'component_status' => 'integer',
|
||||
'notify' => 'boolean',
|
||||
'incident_date' => 'string',
|
||||
];
|
||||
|
||||
/**
|
||||
* Create a new report incident command instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $status
|
||||
* @param string $message
|
||||
* @param int $visible
|
||||
* @param int $component_id
|
||||
* @param int $component_status
|
||||
* @param bool $notify
|
||||
* @param string $name
|
||||
* @param int $status
|
||||
* @param string $message
|
||||
* @param int $visible
|
||||
* @param int $component_id
|
||||
* @param int $component_status
|
||||
* @param bool $notify
|
||||
* @param string|null $incident_date
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($name, $status, $message, $visible, $component_id, $component_status, $notify)
|
||||
public function __construct($name, $status, $message, $visible, $component_id, $component_status, $notify, $incident_date)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->status = $status;
|
||||
@ -99,5 +108,6 @@ class ReportIncidentCommand
|
||||
$this->component_id = $component_id;
|
||||
$this->component_status = $component_status;
|
||||
$this->notify = $notify;
|
||||
$this->incident_date = $incident_date;
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,13 @@ class UpdateIncidentCommand
|
||||
*/
|
||||
public $notify;
|
||||
|
||||
/**
|
||||
* The date that the incident occurred on.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $incident_date;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
@ -97,7 +104,7 @@ class UpdateIncidentCommand
|
||||
* @param int $component_id
|
||||
* @param int $component_status
|
||||
* @param bool $notify
|
||||
* @param string|null $incidentDate
|
||||
* @param string|null $incident_date
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -13,8 +13,11 @@ namespace CachetHQ\Cachet\Handlers\Commands\Incident;
|
||||
|
||||
use CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand;
|
||||
use CachetHQ\Cachet\Events\Incident\IncidentWasReportedEvent;
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class ReportIncidentCommandHandler
|
||||
{
|
||||
@ -35,6 +38,16 @@ class ReportIncidentCommandHandler
|
||||
'component' => $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, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
|
||||
|
||||
$incident->update([
|
||||
'created_at' => $incidentDate,
|
||||
'updated_at' => $incidentDate,
|
||||
]);
|
||||
}
|
||||
|
||||
// Update the component.
|
||||
if ($command->component_id) {
|
||||
Component::find($command->component_id)->update([
|
||||
|
@ -13,8 +13,11 @@ namespace CachetHQ\Cachet\Handlers\Commands\Incident;
|
||||
|
||||
use CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand;
|
||||
use CachetHQ\Cachet\Events\Incident\IncidentWasUpdatedEvent;
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class UpdateIncidentCommandHandler
|
||||
{
|
||||
@ -30,7 +33,10 @@ class UpdateIncidentCommandHandler
|
||||
$incident = $command->incident;
|
||||
$incident->update($this->filterIncidentData($command));
|
||||
|
||||
if ($incidentDate = $command->incident_date) {
|
||||
// The incident occurred at a different time.
|
||||
if ($command->incident_date) {
|
||||
$incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
|
||||
|
||||
$incident->update([
|
||||
'created_at' => $incidentDate,
|
||||
'updated_at' => $incidentDate,
|
||||
|
@ -72,7 +72,8 @@ class IncidentController extends AbstractApiController
|
||||
Binput::get('visible', true),
|
||||
Binput::get('component_id'),
|
||||
Binput::get('component_status'),
|
||||
Binput::get('notify', true)
|
||||
Binput::get('notify', true),
|
||||
Binput::get('created_at')
|
||||
));
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
@ -99,7 +100,8 @@ class IncidentController extends AbstractApiController
|
||||
Binput::get('visible', true),
|
||||
Binput::get('component_id'),
|
||||
Binput::get('component_status'),
|
||||
Binput::get('notify', true)
|
||||
Binput::get('notify', true),
|
||||
Binput::get('created_at')
|
||||
));
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
|
@ -15,7 +15,6 @@ use AltThree\Validator\ValidationException;
|
||||
use CachetHQ\Cachet\Commands\Incident\RemoveIncidentCommand;
|
||||
use CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand;
|
||||
use CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand;
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
@ -23,10 +22,8 @@ use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class IncidentController extends Controller
|
||||
{
|
||||
@ -112,12 +109,6 @@ class IncidentController extends Controller
|
||||
*/
|
||||
public function createIncidentAction()
|
||||
{
|
||||
$incidentDate = null;
|
||||
|
||||
if ($createdAt = Binput::get('created_at')) {
|
||||
$incidentDate = Date::createFromFormat('d/m/Y H:i', $createdAt, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
|
||||
}
|
||||
|
||||
try {
|
||||
$incident = $this->dispatch(new ReportIncidentCommand(
|
||||
Binput::get('name'),
|
||||
@ -127,7 +118,7 @@ class IncidentController extends Controller
|
||||
Binput::get('component_id'),
|
||||
Binput::get('component_status'),
|
||||
Binput::get('notify', true),
|
||||
$incidentDate
|
||||
Binput::get('created_at')
|
||||
));
|
||||
} catch (ValidationException $e) {
|
||||
return Redirect::route('dashboard.incidents.add')
|
||||
@ -238,10 +229,6 @@ class IncidentController extends Controller
|
||||
*/
|
||||
public function editIncidentAction(Incident $incident)
|
||||
{
|
||||
if ($createdAt = Binput::get('created_at')) {
|
||||
$incidentDate = Date::createFromFormat('d/m/Y H:i', $createdAt, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
|
||||
}
|
||||
|
||||
try {
|
||||
$incident = $this->dispatch(new UpdateIncidentCommand(
|
||||
$incident,
|
||||
@ -251,15 +238,9 @@ class IncidentController extends Controller
|
||||
Binput::get('visible', true),
|
||||
Binput::get('component_id'),
|
||||
Binput::get('component_status'),
|
||||
Binput::get('notify', true)
|
||||
Binput::get('notify', true),
|
||||
Binput::get('created_at')
|
||||
));
|
||||
|
||||
if (isset($incidentDate)) {
|
||||
$incident->update([
|
||||
'created_at' => $incidentDate,
|
||||
'updated_at' => $incidentDate,
|
||||
]);
|
||||
}
|
||||
} catch (ValidationException $e) {
|
||||
return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])
|
||||
->withInput(Binput::all())
|
||||
|
Loading…
x
Reference in New Issue
Block a user