40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Planner;
|
|
use DishPlanner\Schedule\Actions\GenerateSchedulesForUserAction;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class GenerateSchedulesCommand extends Command
|
|
{
|
|
protected $signature = 'schedule:generate';
|
|
|
|
protected $description = 'Generates the next 2 years of schedules';
|
|
|
|
public function handle(): int
|
|
{
|
|
$startDate = Carbon::today();
|
|
$endDate = $startDate->copy()->addYears(2);
|
|
|
|
$this->info("Generating schedules from {$startDate->toDateString()} to {$endDate->toDateString()} for all planners.");
|
|
|
|
$planners = Planner::all();
|
|
|
|
if ($planners->isEmpty()) {
|
|
$this->warn('No planners found. Aborting schedule generation.');
|
|
return self::FAILURE;
|
|
}
|
|
|
|
foreach ($planners as $planner) {
|
|
$this->info("Processing schedules for Planner ID: {$planner->id}");
|
|
|
|
resolve(GenerateSchedulesForUserAction::class)->execute($planner);
|
|
}
|
|
|
|
$this->info('Schedule generation for all planners has been completed.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|