-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathSetLatestStatusIncident.php
More file actions
35 lines (27 loc) · 853 Bytes
/
SetLatestStatusIncident.php
File metadata and controls
35 lines (27 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace Cachet\Actions\Incident;
use Cachet\Enums\IncidentStatusEnum;
use Cachet\Events\Incidents\IncidentUpdated;
use Cachet\Models\Incident;
use Cachet\Models\Update;
class SetLatestStatusIncident
{
/**
* Handle the action.
*/
public function handle(Incident $incident): Incident
{
/** @var Update|null $update */
$update = $incident->updates()->latest()->limit(1)->first();
if(is_null($update) && $incident->status === IncidentStatusEnum::unknown) {
return $incident;
}
$newStatus = $update->status ?? IncidentStatusEnum::unknown;
if($newStatus === $incident->status) {
return $incident;
}
$incident->update(['status' => $newStatus]);
IncidentUpdated::dispatch($incident);
return $incident->fresh();
}
}