mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 21:49:01 +01:00
Merge pull request #3580 from CachetHQ/schedule-fixes
Fix issues with scheduled maintenance
This commit is contained in:
commit
ef51636562
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user