Merge pull request #3580 from CachetHQ/schedule-fixes

Fix issues with scheduled maintenance
This commit is contained in:
James Brooks 2019-05-09 08:14:22 +01:00 committed by GitHub
commit ef51636562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 11 deletions

View File

@ -31,7 +31,7 @@ class ScheduledComposer
*/
public function compose(View $view)
{
$scheduledMaintenance = Schedule::futureSchedules()->orderBy('scheduled_at')->get();
$scheduledMaintenance = Schedule::uncompleted()->orderBy('scheduled_at')->get();
$view->withScheduledMaintenance($scheduledMaintenance);
}

View File

@ -22,11 +22,6 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use McCool\LaravelAutoPresenter\HasPresenter;
/**
* This is the schedule class.
*
* @author James Brooks <james@alt-three.com>
*/
class Schedule extends Model implements HasPresenter
{
use HasMeta,
@ -148,6 +143,20 @@ class Schedule extends Model implements HasPresenter
return $this->hasMany(ScheduleComponent::class);
}
/**
* Scope schedules that are uncompleted.
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUncompleted(Builder $query)
{
return $query->whereIn('status', [self::UPCOMING, self::IN_PROGRESS])->where(function (Builder $query) {
return $query->whereNull('completed_at');
});
}
/**
* Scope schedules that are in progress.
*
@ -158,7 +167,7 @@ class Schedule extends Model implements HasPresenter
public function scopeInProgress(Builder $query)
{
return $query->where('scheduled_at', '<=', Carbon::now())->where('status', '<>', self::COMPLETE)->where(function ($query) {
$query->whereNull('completed_at')->orWhere('completed_at', '>', Carbon::now());
$query->whereNull('completed_at');
});
}
@ -169,21 +178,33 @@ class Schedule extends Model implements HasPresenter
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFutureSchedules($query)
public function scopeScheduledInFuture($query)
{
return $query->whereIn('status', [self::UPCOMING, self::IN_PROGRESS])->where('scheduled_at', '>=', Carbon::now());
}
/**
* Scopes schedules to those in the past.
* Scopes schedules to those scheduled in the past.
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePastSchedules($query)
public function scopeScheduledInPast($query)
{
return $query->where('status', '<', self::COMPLETE)->where('scheduled_at', '<=', Carbon::now());
return $query->whereIn('status', [self::UPCOMING, self::IN_PROGRESS])->where('scheduled_at', '<=', Carbon::now());
}
/**
* Scopes schedules to those completed in the past.
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCompletedInPast($query)
{
return $query->where('status', '=', self::COMPLETE)->where('completed_at', '<=', Carbon::now());
}
/**