103 lines
3.5 KiB
PHP
103 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
class SyncGesconFornitoriLegacyCommand extends Command
|
|
{
|
|
protected $signature = 'gescon:sync-fornitori-legacy
|
|
{amministratore_id : ID amministratore a cui associare i fornitori}
|
|
{--mdb=/mnt/gescon-archives/gescon/dbc/Fornitori.mdb : Percorso file Fornitori.mdb}
|
|
{--table=Fornitori : Nome tabella Access}
|
|
{--truncate-staging : Svuota la tabella staging prima dell\'import}
|
|
{--skip-tags : Salta l\'aggiornamento tag legacy}
|
|
{--dry-run : Esegue preview staging e dry-run dell\'import locale senza scrivere}
|
|
{--preview-limit=10 : Limite righe preview staging in dry-run}';
|
|
|
|
protected $description = 'Esegue la sync completa fornitori legacy -> staging -> archivio locale -> tag legacy.';
|
|
|
|
public function handle(): int
|
|
{
|
|
$adminId = (int) $this->argument('amministratore_id');
|
|
$mdb = (string) $this->option('mdb');
|
|
$table = (string) $this->option('table');
|
|
$dryRun = (bool) $this->option('dry-run');
|
|
$skipTags = (bool) $this->option('skip-tags');
|
|
$truncateStaging = (bool) $this->option('truncate-staging');
|
|
$previewLimit = max(1, (int) ($this->option('preview-limit') ?: 10));
|
|
|
|
if ($adminId <= 0) {
|
|
$this->error('amministratore_id non valido.');
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$this->info('Sync fornitori legacy per amministratore #' . $adminId . ($dryRun ? ' [DRY-RUN]' : ''));
|
|
|
|
$stageParams = [
|
|
'tenant' => (string) $adminId,
|
|
'--mdb' => $mdb,
|
|
'--table' => $table,
|
|
];
|
|
if ($dryRun) {
|
|
$stageParams['--preview'] = true;
|
|
$stageParams['--limit'] = $previewLimit;
|
|
}
|
|
if ($truncateStaging && ! $dryRun) {
|
|
$stageParams['--truncate'] = true;
|
|
}
|
|
|
|
$stageExit = Artisan::call('import:gescon-fornitori', $stageParams);
|
|
$stageOutput = trim((string) Artisan::output());
|
|
$this->line('Step staging exit=' . $stageExit);
|
|
if ($stageOutput !== '') {
|
|
$this->line($stageOutput);
|
|
}
|
|
if ($stageExit !== 0) {
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$importParams = [
|
|
'amministratore_id' => (string) $adminId,
|
|
'--mdb' => $mdb,
|
|
'--table' => $table,
|
|
];
|
|
if ($dryRun) {
|
|
$importParams['--dry-run'] = true;
|
|
}
|
|
|
|
$importExit = Artisan::call('gescon:import-fornitori-legacy', $importParams);
|
|
$importOutput = trim((string) Artisan::output());
|
|
$this->line('Step archivio locale exit=' . $importExit);
|
|
if ($importOutput !== '') {
|
|
$this->line($importOutput);
|
|
}
|
|
if ($importExit !== 0) {
|
|
return self::FAILURE;
|
|
}
|
|
|
|
if (! $skipTags) {
|
|
$tagParams = [];
|
|
if ($dryRun) {
|
|
$tagParams['--dry-run'] = true;
|
|
}
|
|
|
|
$tagExit = Artisan::call('fornitori:import-legacy-tags', $tagParams);
|
|
$tagOutput = trim((string) Artisan::output());
|
|
$this->line('Step tag legacy exit=' . $tagExit);
|
|
if ($tagOutput !== '') {
|
|
$this->line($tagOutput);
|
|
}
|
|
if ($tagExit !== 0) {
|
|
return self::FAILURE;
|
|
}
|
|
}
|
|
|
|
$this->info($dryRun
|
|
? 'Dry-run sync fornitori legacy completato.'
|
|
: 'Sync fornitori legacy completato.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
} |