Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
15.38% |
2 / 13 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Kernel | |
15.38% |
2 / 13 |
|
50.00% |
1 / 2 |
20.15 | |
0.00% |
0 / 1 |
| schedule | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| commands | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Console; |
| 4 | |
| 5 | use Illuminate\Console\Scheduling\Schedule; |
| 6 | use Illuminate\Foundation\Console\Kernel as ConsoleKernel; |
| 7 | |
| 8 | class Kernel extends ConsoleKernel |
| 9 | { |
| 10 | /** |
| 11 | * Define the application's command schedule. |
| 12 | * |
| 13 | * @return void |
| 14 | */ |
| 15 | protected function schedule(Schedule $schedule) |
| 16 | { |
| 17 | // Phase 11 — this is what the Deployment Guide's "schedule:run" cron |
| 18 | // line actually runs. Prune old activity-log rows (spatie/laravel- |
| 19 | // activitylog, added Phase 3) daily rather than growing the audit_log |
| 20 | // table forever; keeps 365 days by default (config/activitylog.php, |
| 21 | // unpublished — override there if a shorter/longer retention is wanted). |
| 22 | $schedule->command('activitylog:clean')->daily(); |
| 23 | $schedule->command('inventory:audit')->dailyAt('01:30')->withoutOverlapping(); |
| 24 | $schedule->command('orders:release-expired-stock')->everyFiveMinutes()->withoutOverlapping(); |
| 25 | |
| 26 | // Phase 11 Slice 4 — nightly backup (DB dump + the storage disk), |
| 27 | // opt-out from Settings → Backups. Cleanup always runs so old backups |
| 28 | // don't pile up even if auto backups are later turned off. |
| 29 | $schedule->command('backup:clean')->daily()->at('02:00'); |
| 30 | |
| 31 | // Guard: settings() hits the DB — if the schema isn't migrated yet (a |
| 32 | // fresh install running scheduler before migrate), skip silently rather |
| 33 | // than crashing the whole schedule run. Mirrors the guard in |
| 34 | // AppServiceProvider::boot(). |
| 35 | try { |
| 36 | if (settings('backup.auto_daily', true)) { |
| 37 | $time = settings('backup.daily_time', '02:30'); |
| 38 | $time = preg_match('/^\d{2}:\d{2}$/', (string) $time) ? $time : '02:30'; |
| 39 | $schedule->command('backup:run --only-db')->dailyAt($time)->withoutOverlapping(); |
| 40 | $schedule->command('backup:run')->weeklyOn(0, $time)->withoutOverlapping(); |
| 41 | } |
| 42 | } catch (\Throwable $e) { |
| 43 | report($e); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Register the commands for the application. |
| 49 | * |
| 50 | * @return void |
| 51 | */ |
| 52 | protected function commands() |
| 53 | { |
| 54 | $this->load(__DIR__ . '/Commands'); |
| 55 | |
| 56 | require base_path('routes/console.php'); |
| 57 | } |
| 58 | } |