Files
compras/app/Console/Commands/ReceiptDocumentsCheck.php
nala 63d20b10fc
tests / ci (push) Canceled after 0s
commit de armazens
2026-11-04 09:40:26 +02:00

45 lines
2.3 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Services\ReceiptDocumentHealth;
use Illuminate\Console\Command;
use Throwable;
class ReceiptDocumentsCheck extends Command
{
protected $signature = 'sgc:receipt-documents-check {--json : Resultado agregado para operação} {--limit=1000 : Máximo de registos e ficheiros, de 1 a 10000}';
protected $description = 'Verificar documentos privados da recepção sem modificar registos ou ficheiros';
public function handle(ReceiptDocumentHealth $health): int
{
$limit = filter_var($this->option('limit'), FILTER_VALIDATE_INT, ['options' => ['min_range' => 1, 'max_range' => 10000]]);
if ($limit === false) {
$this->error('O limite deve ser um inteiro entre 1 e 10000.');
return self::INVALID;
}
try {
$result = $health->inspect($limit);
} catch (Throwable $error) {
report($error);
$result = ['checked_at' => now()->toIso8601String(), 'ok' => false, 'complete' => false, 'reasons' => ['unavailable']];
}
if ($this->option('json')) {
$this->line(json_encode($result, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
} else {
$this->line($result['ok'] ? 'Documentos da recepção: verificação concluída sem divergências observadas.' : 'Documentos da recepção: verificação requer atenção.');
$labels = ['not_installed' => 'Estrutura documental não instalada.', 'storage_unavailable' => 'Armazenamento privado indisponível.',
'missing' => 'Existem ficheiros em falta.', 'invalid_reference' => 'Existem referências inválidas.', 'altered' => 'Existem divergências de tamanho ou conteúdo.',
'unreferenced_recent' => 'Existem ficheiros recentes sem referência; podem estar em processamento.', 'unreferenced_older' => 'Existem ficheiros sem referência há pelo menos uma hora.',
'limit_reached' => 'Verificação incompleta: atingido o limite configurado.', 'unavailable' => 'Consulta indisponível; verificar o registo técnico.'];
foreach ($result['reasons'] as $reason) {
$this->line($labels[$reason]);
}
}
return $result['ok'] ? self::SUCCESS : self::FAILURE;
}
}