-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issues with scheduled maintenance
- Loading branch information
Showing
2 changed files
with
32 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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. | ||
* | ||
|
@@ -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'); | ||
}); | ||
} | ||
|
||
|
@@ -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()); | ||
} | ||
|
||
/** | ||
|