7 lines
2.9 KiB
PHP
7 lines
2.9 KiB
PHP
<?php
|
|
ini_set('zend.exception_ignore_args','1');$f=json_decode(file_get_contents(__DIR__.'/business-country-fixture.json'),true,512,JSON_THROW_ON_ERROR);putenv('STABILITY_QA_MODE=consumers');$app=require $f['QA_source'].'/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!==$f['target']||config('portal.notifications_enabled'))throw new RuntimeException('QA target/notifications guard');$ids=[];
|
|
foreach(['franchise-variants-progress.json'=>'license_document_id','partnership-revocation-progress.json'=>'room_document_id']as$file=>$key)if(is_file(__DIR__.'/'.$file)){$s=json_decode(file_get_contents(__DIR__.'/'.$file),true,512,JSON_THROW_ON_ERROR);if(isset($s[$key]))$ids[]=$s[$key];}
|
|
if(!$ids)throw new RuntimeException('Only own newly uploaded documents can be processed');$scanner=app(App\Services\Malware\MalwareScanner::class);$health=$scanner->health();if(!$health['available'])throw new RuntimeException('Real scanner unavailable');$before=$db->table('jobs')->orderBy('id')->get()->keyBy('id');$removed=[];$documents=[];
|
|
foreach($ids as$id){$d=$db->table('documents')->where('id',$id)->first();if(!$d||$d->uploaded_by!==21||!in_array($d->source_system,['opportunity-resources','partnership-exchange'],true))throw new RuntimeException('Own QA document binding required');$job=new App\Jobs\ScanDocumentForMalware($id);$job->handle($scanner);$d=$db->table('documents')->where('id',$id)->first();if($d->malware_scan_status!=='clean'||trim($d->sha256)!==$d->malware_scanned_sha256)throw new RuntimeException('Scan/hash 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===$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);$documents[]=['id'=>$id,'source'=>$d->source_system,'MIME'=>$d->media_type,'sha256'=>trim($d->sha256),'scan'=>'clean','scanned_sha256'=>$d->malware_scanned_sha256,'engine_version'=>$d->malware_engine_version,'signatures_at'=>$d->malware_signatures_at,'attempts'=>$d->malware_scan_attempts];}
|
|
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 work changed');$p=['at'=>gmdate('c'),'target'=>$t,'own_documents'=>$documents,'own_queue_jobs_removed'=>$removed,'unrelated_queue_work_unchanged'=>true,'active_writes'=>0,'worker_test_claimed'=>false,'result'=>'passed'];file_put_contents(__DIR__.'/next-lot-own-scan-QA.json',json_encode($p,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode($p);
|