selectOne('SELECT current_database() AS database,inet_server_port() AS port'); if($target!==['database'=>'stability_consumers_20261011_084534_test','port'=>55441])throw new RuntimeException('QA isolation required'); $db->beginTransaction();$db->statement('SET TRANSACTION READ ONLY'); try{ $access=app(App\Services\PortalProfileAccess::class);$actor=App\Models\User::findOrFail(22); $grant=$db->table('portal_role_assignments')->where('user_id',22)->where('role','promoter')->whereNull('revoked_at')->sole(); $request=$db->table('portal_profile_requests')->where('id',$grant->request_id)->sole(); $documents=json_decode($request->document_ids,true,512,JSON_THROW_ON_ERROR); foreach($documents as$id){if(!$db->table('documents')->where('id',$id)->where('uploaded_by',22)->whereNull('deleted_at')->where('status','active')->where('malware_scan_status','clean')->whereColumn('sha256','malware_scanned_sha256')->exists())throw new RuntimeException('Existing supporting evidence required');} $cases=[];foreach(App\Models\Opportunity::where('owner_user_id',21)->where('organization_id',$grant->organization_id)->get()as$o){ if($access->canEdit($actor,$o))$cases[]=['id'=>$o->id,'state'=>$access->state($o),'type'=>$o->opportunity_category]; } $proof=['at'=>gmdate('c'),'target'=>$target,'SQL_read_only'=>true,'active_writes'=>0,'grant_id'=>$grant->id,'user_id'=>22,'organization_id'=>$grant->organization_id,'requested_types'=>json_decode($grant->opportunity_types,true),'support_document_ids'=>$documents,'representation_type'=>$request->representation_type,'editable_existing_cases'=>$cases,'other_roles_retained'=>array_values(array_unique(array_map(fn($g)=>$g->role,$access->grants($actor)))),'superuser_id'=>27,'superuser_is_existing'=>$access->superuser(App\Models\User::findOrFail(27))]; $dest=__DIR__.'/option-B5-revocation-preflight.json';if(is_file($dest))throw new RuntimeException('Preserve preflight'); file_put_contents($dest,json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR)); echo json_encode($proof,JSON_UNESCAPED_UNICODE).PHP_EOL; }finally{$db->rollBack();}