45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
class SyncWorkCalendar extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'app:sync-work-calendar {year? : A szinkronizálandó év (alapértelmezett: aktuális)}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Munkaszüneti napok szinkronizálása külső API-ból';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(\App\Services\WorkCalendarService $service): int
|
|
{
|
|
$year = $this->argument('year') ? (int) $this->argument('year') : now()->year;
|
|
|
|
$this->info("Szinkronizálás indítása {$year} évre...");
|
|
|
|
if ($service->syncFromApi($year)) {
|
|
$this->info('A szinkronizálás sikeresen befejeződött.');
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$this->error('A szinkronizálás során hiba történt:');
|
|
foreach ($service->getError() as $error) {
|
|
$this->error("- " . implode(', ', (array) $error));
|
|
}
|
|
|
|
return self::FAILURE;
|
|
}
|
|
}
|