-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add incident column for when an incident occurred at #2212
Changes from all commits
f39970a
f5fd88e
0d73145
d8eb2ec
a6e4c2a
eacb1fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,13 @@ | |
|
||
use CachetHQ\Cachet\Models\Incident; | ||
|
||
/** | ||
* This is the update incident command. | ||
* | ||
* @author James Brooks <[email protected]> | ||
* @author Joseph Cohem <[email protected]> | ||
* @author Graham Campbell <[email protected]> | ||
*/ | ||
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 @@ public function __construct(Incident $incident, $name, $status, $message, $visib | |
$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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
*/ | ||
class InvalidIncidentTimestampException extends Exception implements ExceptionInterface | ||
{ | ||
// | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,11 +127,11 @@ public function showDashboard() | |
*/ | ||
protected function getIncidents() | ||
{ | ||
$allIncidents = Incident::notScheduled()->whereBetween('created_at', [ | ||
$allIncidents = Incident::notScheduled()->whereBetween('occurred_at', [ | ||
$this->startDate->copy()->subDays(30)->format('Y-m-d').' 00:00:00', | ||
$this->startDate->format('Y-m-d').' 23:59:59', | ||
])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) { | ||
return (new Date($incident->created_at)) | ||
])->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) { | ||
return (new Date($incident->occurred_at)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we not use the presenter here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking this when I was looking at it this morning. |
||
->setTimezone($this->dateTimeZone)->toDateString(); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,11 @@ | |
use Illuminate\Support\Facades\Config; | ||
use Illuminate\Support\Str; | ||
|
||
/** | ||
* This is the feed controller. | ||
* | ||
* @author James Brooks <[email protected]> | ||
*/ | ||
class FeedController extends Controller | ||
{ | ||
/** | ||
|
@@ -80,12 +85,12 @@ private function feedAction(ComponentGroup &$group, $isRss) | |
{ | ||
if ($group->exists) { | ||
$group->components->map(function ($component) use ($isRss) { | ||
$component->incidents()->visible()->orderBy('created_at', 'desc')->get()->map(function ($incident) use ($isRss) { | ||
$component->incidents()->visible()->orderBy('occurred_at', 'desc')->get()->map(function ($incident) use ($isRss) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Long line is long 😛 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should add a better scope for this. |
||
$this->feedAddItem($incident, $isRss); | ||
}); | ||
}); | ||
} else { | ||
Incident::visible()->orderBy('created_at', 'desc')->get()->map(function ($incident) use ($isRss) { | ||
Incident::visible()->orderBy('occurred_at', 'desc')->get()->map(function ($incident) use ($isRss) { | ||
$this->feedAddItem($incident, $isRss); | ||
}); | ||
} | ||
|
@@ -105,7 +110,7 @@ private function feedAddItem(Incident $incident, $isRss) | |
$incident->name, | ||
Config::get('setting.app_name'), | ||
Str::canonicalize(cachet_route('incident', [$incident->id])), | ||
$isRss ? $incident->created_at->toRssString() : $incident->created_at->toAtomString(), | ||
$isRss ? $incident->occurred_at->toRssString() : $incident->occurred_at->toAtomString(), | ||
$isRss ? $incident->message : Markdown::convertToHtml($incident->message) | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,11 +82,11 @@ public function showIndex() | |
|
||
$incidentVisibility = Auth::check() ? 0 : 1; | ||
|
||
$allIncidents = Incident::notScheduled()->where('visible', '>=', $incidentVisibility)->whereBetween('created_at', [ | ||
$allIncidents = Incident::notScheduled()->where('visible', '>=', $incidentVisibility)->whereBetween('occurred_at', [ | ||
$startDate->copy()->subDays($daysToShow)->format('Y-m-d').' 00:00:00', | ||
$startDate->format('Y-m-d').' 23:59:59', | ||
])->orderBy('scheduled_at', 'desc')->orderBy('created_at', 'desc')->get()->load('updates')->groupBy(function (Incident $incident) { | ||
return app(DateFactory::class)->make($incident->is_scheduled ? $incident->scheduled_at : $incident->created_at)->toDateString(); | ||
])->orderBy('scheduled_at', 'desc')->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) { | ||
return app(DateFactory::class)->make($incident->is_scheduled ? $incident->scheduled_at : $incident->occurred_at)->toDateString(); | ||
}); | ||
|
||
// Add in days that have no incidents | ||
|
@@ -109,7 +109,7 @@ public function showIndex() | |
->withDaysToShow($daysToShow) | ||
->withAllIncidents($allIncidents) | ||
->withCanPageForward((bool) $today->gt($startDate)) | ||
->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0) | ||
->withCanPageBackward(Incident::notScheduled()->where('occurred_at', '<', $startDate->format('Y-m-d'))->count() > 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we even need to format There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dunno. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because |
||
->withPreviousDate($startDate->copy()->subDays($daysToShow)->toDateString()) | ||
->withNextDate($startDate->copy()->addDays($daysToShow)->toDateString()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard >
else
- looks messy imoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the exception doesn't do anything here, because
create
will throw, so we need to catch.