netgescon-day0/app/Console/Commands/GesconSyncStabile.php

34 lines
1.2 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Amministratore;
use App\Services\GesconImport\EssentialImportService;
class GesconSyncStabile extends Command
{
protected $signature = 'gescon:sync-stabile {--stabile=} {--path=/mnt/gescon-archives/gescon} {--include-banche} {--include-gestioni} {--dry}';
protected $description = 'Risincronizza uno stabile (solo se cambiato in staging) con enrichment e (opz.) banche/gestioni.';
public function handle(): int
{
$code = $this->option('stabile');
if (!$code) {
$this->error('Serve --stabile=CODICE');
return 1;
}
$path = $this->option('path');
$dry = (bool)$this->option('dry');
$amm = Amministratore::first();
if (!$amm) {
$this->error('Nessun amministratore presente.');
return 1;
}
$svc = new EssentialImportService();
$res = $svc->syncStabile($amm, $code, ['path' => $path, 'dry' => $dry, 'with_banche' => $this->option('include-banche'), 'with_gestioni' => $this->option('include-gestioni')]);
$this->info('Sync result: ' . json_encode($res));
return 0;
}
}