Skip to content
Closed
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
18 changes: 18 additions & 0 deletions src/Illuminate/Console/Scheduling/ScheduleListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ScheduleListCommand extends Command
protected $signature = 'schedule:list
{--timezone= : The timezone that times should be displayed in}
{--next : Sort the listed tasks by their next due date}
{--all : Disregard environment constraints}
';

/**
Expand Down Expand Up @@ -66,6 +67,8 @@ public function handle(Schedule $schedule)

$timezone = new DateTimeZone($this->option('timezone') ?? config('app.timezone'));

$events = $this->filterEvents($events);

$events = $this->sortEvents($events, $timezone);

$events = $events->map(function ($event) use ($terminalWidth, $expressionSpacing, $repeatExpressionSpacing, $timezone) {
Expand Down Expand Up @@ -183,6 +186,21 @@ private function getRepeatExpression($event)
return $event->isRepeatable() ? "{$event->repeatSeconds}s " : '';
}

/**
* Filter the events based on the environment constraint.
*
* @param \Illuminate\Support\Collection $events
* @return \Illuminate\Support\Collection
*/
private function filterEvents(\Illuminate\Support\Collection $events)
{
$environment = $this->laravel->environment();

return $this->option('all')
? $events
: $events->filter(fn ($event) => $event->runsInEnvironment($environment));
}

/**
* Sort the events by due date if option set.
*
Expand Down