39 lines
1.4 KiB
PHP
Executable File
39 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\Amministratore;
|
|
use App\Services\GesconImport\Micro\StabiliMicroImporter;
|
|
use App\Models\GesconImportMapping;
|
|
|
|
class GesconMicroImportStabili extends Command
|
|
{
|
|
protected $signature = 'gescon:micro-import-stabile {legacy_code} {--amministratore-id=}';
|
|
protected $description = 'Import rapido (micro) di uno stabile GESCON usando mapping salvato';
|
|
|
|
public function handle(): int
|
|
{
|
|
$legacy = trim($this->argument('legacy_code'));
|
|
if ($legacy === '') {
|
|
$this->error('legacy_code richiesto');
|
|
return 1;
|
|
}
|
|
$ammId = $this->option('amministratore-id');
|
|
$amministratore = $ammId ? Amministratore::find($ammId) : Amministratore::first();
|
|
if (!$amministratore) {
|
|
$this->error('Nessun amministratore trovato');
|
|
return 1;
|
|
}
|
|
$mappingRec = GesconImportMapping::where('legacy_code', $legacy)->first();
|
|
$map = [];
|
|
if ($mappingRec && is_array($mappingRec->meta)) {
|
|
$map = (array)($mappingRec->meta['mapping'] ?? []);
|
|
}
|
|
$svc = new StabiliMicroImporter();
|
|
$res = $svc->import($legacy, $amministratore, $map);
|
|
$this->info("Stabile {$legacy}: created={$res['created']} updated={$res['updated']} id=" . ($res['stabile_id'] ?? 'null'));
|
|
return 0;
|
|
}
|
|
}
|