make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); $db=Illuminate\Support\Facades\DB::connection(); $db->beginTransaction(); $db->statement('SET TRANSACTION READ ONLY'); $identity=$db->selectOne("select current_database() as db,current_user as role,inet_server_port() as port,current_setting('cluster_name') as cluster"); if($identity->db!=='sgf_modules_dev_2576427d1939'||$identity->role!=='sgf_modules_qa_2576427d1939'||(int)$identity->port!==55439||$identity->cluster!=='sgf_modular_regression_2576427d1939')throw new RuntimeException('Wrong destination'); $recovery=dirname($host).'/private/requisitions-recovery'; $baseline=json_decode(file_get_contents($recovery.'/baseline.json'),true,64,JSON_THROW_ON_ERROR); $grants=json_decode(json_encode($db->table('permission_grants')->orderBy('id')->get()),true); $ids=array_column($baseline['grants'],'id'); foreach($baseline['grants'] as $row)if(!in_array($row,$grants,true))throw new RuntimeException('Existing grant changed'); $new=array_values(array_filter($grants,fn($x)=>!in_array($x['id'],$ids))); $rights=[1=>['purchasing_requisitions.view','purchasing_requisitions.prepare','purchasing_requisitions.configure','purchasing_requisitions.approve.department_head','purchasing_budget.view','purchasing_budget.create','purchasing_budget.approve','purchasing_budget.record'],2=>['purchasing_requisitions.view','purchasing_requisitions.approve.department_head','purchasing_budget.view','purchasing_budget.approve'],3=>['purchasing_requisitions.view','purchasing_budget.view']]; if(count($new)!==14)throw new RuntimeException('Expected exactly fourteen new grants'); foreach($new as $g)if($g['tenant_id']!==1||$g['company_id']!==1||$g['unit_id']!==1||!in_array($g['permission'],$rights[$g['user_id']]??[],true))throw new RuntimeException('Unexpected grant'); $usersUnchanged=hash('sha256',json_encode($db->table('users')->orderBy('id')->get()))===$baseline['users_sha256']; if(!$usersUnchanged)throw new RuntimeException('Users changed'); $state=['identity'=>$identity,'read_only'=>true,'previous_grants_preserved'=>true,'new_grants'=>$new,'users_unchanged'=>$usersUnchanged,'backup_valid'=>hash_file('sha256',$recovery.'/before.dump')===$baseline['backup_sha256'],'backup_sha256'=>$baseline['backup_sha256'],'centres'=>$db->table('cb_centres')->get(),'budgets'=>$db->table('cb_budgets')->get(),'requests'=>$db->table('ir_requests')->get(['id','status','requester_id','version','total_minor']),'steps'=>$db->table('ir_steps')->get(),'entries'=>$db->table('cb_budget_entries')->get(),'policy'=>$db->table('ir_policies')->get(),'initialisation_scopes'=>config('purchasing-access.initialisation_scopes'),'operational'=>config('purchasing-operational'),'pointer_unchanged'=>hash_file('sha256',$host.'/packages/purchasing/current.json')===$baseline['pointer_sha256']]; $db->rollBack(); echo json_encode($state,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR);