feat: add Snipe-IT asset synchronization

This commit is contained in:
2026-08-04 16:15:09 +01:00
parent 604180b735
commit 077015f17a
37 changed files with 1302 additions and 26 deletions

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Console\Commands;
use App\Domain\Inventory\Services\AssetSyncService;
use App\Jobs\SyncSnipeAssets;
use Illuminate\Console\Command;
use Throwable;
class SyncSnipeAssetsCommand extends Command
{
protected $signature = 'snipe:sync-assets {--queue : Colocar a sincronização na fila em vez de a executar agora}';
protected $description = 'Sincroniza o cache local de equipamentos com a API do Snipe-IT';
public function handle(AssetSyncService $syncService): int
{
if ($this->option('queue')) {
SyncSnipeAssets::dispatch();
$this->info('Sincronização Snipe-IT colocada na fila.');
return self::SUCCESS;
}
try {
$run = $syncService->sync();
} catch (Throwable $exception) {
$this->error($exception->getMessage());
return self::FAILURE;
}
$this->table(
['Processados', 'Criados', 'Atualizados', 'Desativados'],
[[
$run->records_processed,
$run->records_created,
$run->records_updated,
$run->records_disabled,
]],
);
return self::SUCCESS;
}
}