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'); $stage=$argv[1]??'';if(!in_array($stage,['before','after'],true))throw new RuntimeException('stage required'); $db->beginTransaction();$db->statement('SET TRANSACTION READ ONLY'); try { $a=app(App\Services\PortalProfileAccess::class);$u=App\Models\User::findOrFail(22); $grants=$db->table('portal_role_assignments')->orderBy('id')->get(); $hashes=[];foreach($grants as $g)$hashes[$g->id]=hash('sha256',json_encode($g,JSON_THROW_ON_ERROR)); $roles=$db->table('portal_role_assignments')->where('user_id',22)->get(['id','role','organization_id','opportunity_types','revoked_at']); $p=['at'=>gmdate('c'),'target'=>$target,'SQL_read_only'=>true,'QA22_grants'=>$roles,'all_grant_hashes'=>$hashes,'QA22_session_count'=>$db->table('sessions')->where('user_id',22)->count(),'QA22_can_edit15'=>$a->canEdit($u,App\Models\Opportunity::findOrFail(15)),'QA22_can_view30'=>$a->canView($u,App\Models\Opportunity::findOrFail(30)),'active_changes'=>0]; $path=__DIR__.'/line02-'.$stage.'-readonly-20261015.json';if(is_file($path))throw new RuntimeException('Preserve proof'); file_put_contents($path,json_encode($p,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL);echo json_encode($p,JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL; }finally{$db->rollBack();}