Files
Investidor-V2/outputs/investmoz-audit-current-20261012/option-B8-secondary-scan.php
T
nala ba1c0340ea
tests / ci (push) Canceled after 0s
oportunidades 8
2026-10-14 08:25:30 +02:00

8 lines
3.2 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1');putenv('STABILITY_QA_MODE=consumers');$b8Root=dirname(__DIR__,2);$app=require $b8Root.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742/tools/portal-stability-runtime.php';$db=Illuminate\Support\Facades\DB::connection();$t=(array)$db->selectOne('SELECT current_database() AS database,inet_server_port() AS port');if($t!==['database'=>'stability_consumers_20261011_084534_test','port'=>55441]||config('portal.notifications_enabled'))throw new RuntimeException('QA required');
$s=json_decode(file_get_contents(__DIR__.'/option-B8-secondary-progress.json'),true,512,JSON_THROW_ON_ERROR);$dest=__DIR__.'/option-B8-secondary-scan.json';if(is_file($dest))throw new RuntimeException('Preserve proof');$before=$db->table('jobs')->get()->keyBy('id');$scanner=app(App\Services\Malware\MalwareScanner::class);if(!$scanner->health()['available'])throw new RuntimeException('Scanner required');$proof=[];$removed=[];
foreach($s['documents']as$label=>&$r){$table=$r['consumer']==='land'?'land_assistance_documents':'desk_documents';$link=$db->table($table)->where('id',$r['attachment_id'])->where('case_id',$r['case_id'])->first();if(!$link)throw new RuntimeException('Consumer binding missing');$d=$db->table('documents')->where('id',$link->document_id)->first();if(!$d||$d->uploaded_by!==21||trim($d->sha256)!==$r['fixture_sha256']||!in_array($d->source_system,['land-assistance','virtual-desk'],true))throw new RuntimeException('Own source/hash required');$job=new App\Jobs\ScanDocumentForMalware($d->id);$job->handle($scanner);$d=$db->table('documents')->where('id',$d->id)->first();if($d->malware_scan_status!=='clean'||$d->status!=='active'||trim($d->sha256)!==$d->malware_scanned_sha256)throw new RuntimeException('Scan mismatch');
foreach($before as$jid=>$row){$p=json_decode($row->payload,true);if(($p['data']['commandName']??'')!==App\Jobs\ScanDocumentForMalware::class)continue;$queued=unserialize($p['data']['command'],['allowed_classes'=>[App\Jobs\ScanDocumentForMalware::class]]);if($queued instanceof App\Jobs\ScanDocumentForMalware&&$queued->documentId===$d->id){$db->table('jobs')->where('id',$jid)->where('payload',$row->payload)->delete();$removed[]=$jid;}}
(new Illuminate\Bus\UniqueLock(app(Illuminate\Contracts\Cache\Repository::class)))->release($job);$r['document_id']=$d->id;$proof[$label]=['document_id'=>$d->id,'MIME'=>$d->media_type,'sha256'=>trim($d->sha256),'scan'=>'clean','engine'=>$d->malware_engine_version,'signatures_at'=>$d->malware_signatures_at,'storage_encryption'=>$d->storage_encryption];}unset($r);
foreach($before as$jid=>$row)if(!in_array($jid,$removed,true)&&((array)$db->table('jobs')->where('id',$jid)->first()!==(array)$row))throw new RuntimeException('Unrelated queue changed');file_put_contents(__DIR__.'/option-B8-secondary-progress.json',json_encode($s,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));$out=['at'=>gmdate('c'),'target'=>$t,'documents'=>$proof,'own_queue_removed'=>$removed,'unrelated_queue_unchanged'=>true,'active_writes'=>0,'worker_test_claimed'=>false,'result'=>'passed'];file_put_contents($dest,json_encode($out,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode($out);