commit compras2 2711
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-27 18:11:02 +02:00
parent e709d900d1
commit 930064269e
74 changed files with 7506 additions and 40 deletions
+8 -6
View File
@@ -25,22 +25,24 @@ final class ImportCostDocumentHealth
'documents_checked' => 0, 'files_checked' => 0, 'missing' => 0, 'altered' => 0,
'invalid_reference' => 0, 'unreferenced' => 0, 'reasons' => []];
$disk = Storage::disk('local');
$records = DB::table('supply_records')->whereIn('kind', ['import_cost_doc', 'import_document'])->orderBy('id')->limit($limit + 1)->get();
$records = DB::table('supply_records')->whereIn('kind', ['import_cost_doc', 'import_document', 'import_legal_source'])->orderBy('id')->limit($limit + 1)->get();
$limited = $records->count() > $limit;
$root = realpath($disk->path(''));
foreach ($records->take($limit) as $record) {
$result['documents_checked']++;
$snapshot = json_decode($record->snapshot, true, 64, JSON_THROW_ON_ERROR);
$evidence = $snapshot['evidence'] ?? [];
$directory = $record->kind === 'import_cost_doc' ? 'import-costs' : 'import-dossier';
$prefix = $directory.'/'.$record->tenant_id.'/'.$record->purchase_order_id.'/';
$directory = match ($record->kind) {
'import_cost_doc' => 'import-costs', 'import_legal_source' => 'import-legal', default => 'import-dossier'
};
$prefix = $directory.'/'.$record->tenant_id.'/'.($record->kind === 'import_legal_source' ? '' : $record->purchase_order_id.'/');
$path = $evidence['path'] ?? null;
if (($evidence['disk'] ?? null) !== 'local' || ! is_string($path)
|| ! preg_match('/^[a-f0-9-]{36}$/D', $record->record_key)
|| ! preg_match('/^'.preg_quote($prefix.$record->record_key.'-'.$record->version, '/').'\.(pdf|jpg|jpeg|png)$/D', $path)
|| ! is_int($evidence['size'] ?? null) || $evidence['size'] < 1 || $evidence['size'] > 2097152
|| ! is_int($evidence['size'] ?? null) || $evidence['size'] < 1 || $evidence['size'] > ($record->kind === 'import_legal_source' ? 67108864 : 2097152)
|| ! is_string($evidence['sha256'] ?? null) || ! preg_match('/^[a-f0-9]{64}$/D', $evidence['sha256'])
|| ! DB::table('purchase_orders')->where('tenant_id', $record->tenant_id)->where('id', $record->purchase_order_id)->exists()) {
|| ($record->kind !== 'import_legal_source' && ! DB::table('purchase_orders')->where('tenant_id', $record->tenant_id)->where('id', $record->purchase_order_id)->exists())) {
$result['invalid_reference']++;
continue;
@@ -69,7 +71,7 @@ final class ImportCostDocumentHealth
$result['altered']++;
}
}
foreach (['import-costs' => 'import_cost_doc', 'import-dossier' => 'import_document'] as $directory => $kind) {
foreach (['import-costs' => 'import_cost_doc', 'import-dossier' => 'import_document', 'import-legal' => 'import_legal_source'] as $directory => $kind) {
foreach ($disk->getDriver()->listContents($directory, true) as $entry) {
if (! $entry->isFile()) {
continue;