Skip to content

Commit

Permalink
Improve how we work out system status with scheduled maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrooksuk committed Jul 13, 2016
1 parent ca4a72c commit 47a5569
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/Composers/StatusPageComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public function compose(View $view)
];
} elseif (Component::enabled()->notStatus(1)->count() === 0) {
// If all our components are ok, do we have any non-fixed incidents?
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get()->filter(function ($incident) {
return $incident->status > 0;
});
$incidentCount = $incidents->count();

if ($incidentCount === 0 || ($incidentCount >= 1 && (int) $incidents->first()->status === 4)) {
Expand Down
15 changes: 9 additions & 6 deletions app/Models/Incident.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CachetHQ\Cachet\Models\Traits\SortableTrait;
use CachetHQ\Cachet\Presenters\IncidentPresenter;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use McCool\LaravelAutoPresenter\HasPresenter;
Expand Down Expand Up @@ -97,7 +98,7 @@ class Incident extends Model implements HasPresenter
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeVisible($query)
public function scopeVisible(Builder $query)
{
return $query->where('visible', 1);
}
Expand All @@ -109,9 +110,9 @@ public function scopeVisible($query)
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeScheduled($query)
public function scopeScheduled(Builder $query)
{
return $query->where('status', 0)->where('scheduled_at', '>=', Carbon::now());
return $query->where('status', 0)->where('scheduled_at', '>=', Carbon::now()->toDateTimeString());
}

/**
Expand All @@ -121,10 +122,12 @@ public function scopeScheduled($query)
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeNotScheduled($query)
public function scopeNotScheduled(Builder $query)
{
return $query->where(function ($query) {
return $query->whereNull('scheduled_at')->orWhere('scheduled_at', '<=', Carbon::now());
return $query->where('status', '>', 0)->orWhere(function ($query) {
$query->where('status', 0)->where(function ($query) {
$query->whereNull('scheduled_at')->orWhere('scheduled_at', '<=', Carbon::now()->toDateTimeString());
});
});
}

Expand Down

0 comments on commit 47a5569

Please sign in to comment.