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')||config('suitecrm.enabled'))throw new RuntimeException('QA required'); $oid=32;if(!in_array($oid,[32,56],true))throw new RuntimeException('Own opportunities only'); $map=json_decode(file_get_contents(__DIR__.'/option-B8-map-v2-progress.json'),true,512,JSON_THROW_ON_ERROR);$s=['resources'=>['map-v2'=>['resource_id'=>$map['resource_id'],'document_id'=>$map['document_id'],'sha256'=>$map['sha256']]]];$dest=__DIR__.'/option-B8-map-v2-scan.json';if(is_file($dest))throw new RuntimeException('Preserve previous proof'); $before=$db->table('jobs')->orderBy('id')->get()->keyBy('id');$scanner=app(App\Services\Malware\MalwareScanner::class);if(!$scanner->health()['available'])throw new RuntimeException('Real scanner unavailable');$removed=[];$proof=[]; foreach($s['resources']as$label=>$r){ $d=$db->table('documents')->where('id',$r['document_id'])->first();$link=$db->table('opportunity_documents')->where('id',$r['resource_id'])->where('opportunity_id',$oid)->first(); if(!$link||!$d||$link->document_id!==$d->id||$d->uploaded_by!==21||$d->source_system!=='opportunity-resources'||trim($d->sha256)!==$r['sha256'])throw new RuntimeException('Own document binding required'); $job=new App\Jobs\ScanDocumentForMalware($d->id);$job->handle($scanner);$d=$db->table('documents')->where('id',$d->id)->first();if($d->status!=='active'||$d->malware_scan_status!=='clean'||trim($d->sha256)!==$d->malware_scanned_sha256)throw new RuntimeException('Hash/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); $proof[$label]=['id'=>$d->id,'MIME'=>$d->media_type,'sha256'=>trim($d->sha256),'scanned_sha256'=>$d->malware_scanned_sha256,'scan'=>'clean','engine'=>$d->malware_engine_version,'signatures_at'=>$d->malware_signatures_at,'storage_encryption'=>$d->storage_encryption]; } foreach($before as$jid=>$r)if(!in_array($jid,$removed,true)&&((array)$db->table('jobs')->where('id',$jid)->first()!==(array)$r))throw new RuntimeException('Unrelated queue changed'); $result=['at'=>gmdate('c'),'target'=>$t,'result'=>'passed','documents'=>$proof,'own_queue_jobs_removed'=>$removed,'unrelated_queue_unchanged'=>true,'active_writes'=>0,'worker_test_claimed'=>false];file_put_contents($dest,json_encode($result,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode($result).PHP_EOL;