Skip to content
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

Fix issues with scheduled maintenance #3580

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Composers/ScheduledComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
41 changes: 31 additions & 10 deletions app/Models/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use McCool\LaravelAutoPresenter\HasPresenter;

/**
* This is the schedule class.
*
* @author James Brooks <[email protected]>
*/
class Schedule extends Model implements HasPresenter
{
use HasMeta,
Expand Down Expand Up @@ -148,6 +143,20 @@ public function components()
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.
*
Expand All @@ -158,7 +167,7 @@ public function components()
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');
});
}

Expand All @@ -169,21 +178,33 @@ public function scopeInProgress(Builder $query)
*
* @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 scopeScheduledInPast($query)
{
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 scopePastSchedules($query)
public function scopeCompletedInPast($query)
{
return $query->where('status', '<', self::COMPLETE)->where('scheduled_at', '<=', Carbon::now());
return $query->where('status', '=', self::COMPLETE)->where('completed_at', '<=', Carbon::now());
}

/**
Expand Down