make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();App\Modules\Purchasing\BudgetAdapter::guard(); $f=json_decode(file_get_contents($s['root'].'/fixture.json'),true);$n=json_decode(file_get_contents($s['root'].'/native-fixture.json'),true); $old=DB::selectOne("SELECT pg_get_constraintdef(oid) d FROM pg_constraint WHERE conrelid='permission_grants'::regclass AND conname='permission_grants_scope_check'")->d; if(!preg_match('/^CHECK\s*\((.*)\)$/s',$old,$m))throw new LogicException('QA constraint required'); DB::statement('ALTER TABLE permission_grants DROP CONSTRAINT permission_grants_scope_check'); DB::statement("ALTER TABLE permission_grants ADD CONSTRAINT permission_grants_scope_check CHECK (({$m[1]}) OR (unit_id IS NOT NULL AND permission IN ('purchasing_obligations.view','purchasing_obligations.prepare','purchasing_obligations.validate')))"); config(['database.connections.obligation_setup'=>$s['nativeConnection']]);$native=DB::connection('obligation_setup'); if($native->table('pa_access')->count()||$native->table('pa_obligations')->count()||$native->table('pa_proposals')->count())throw new LogicException('Empty native payable fixture required'); $file=$s['root'].'/binding.json';$p=json_decode(file_get_contents($file),true);$prefix=implode(':',array_values($f['scope'])).':'; foreach(['issuer'=>['finance',['view','prepare','validate']],'reviewer'=>['finance_reviewer',['view','validate']],'auditor'=>['finance_auditor',['view','validate']]]as$role=>[$actor,$rights]){ foreach($rights as$right){DB::table('permission_grants')->insert($f['scope']+['user_id'=>$f[$role],'permission'=>'purchasing_obligations.'.$right,'created_at'=>now(),'updated_at'=>now()]);$native->table('pa_access')->insert(['tenant_id'=>$n['tenant'],'company_id'=>0,'unit_id'=>0,'user_id'=>$n[$actor],'person'=>'qa-person-'.$role,'action'=>$right]);} } foreach($p['bindings']as&$binding)$binding['payable_instance']='qa-stock-ledger-'.$s['tag'];unset($binding); file_put_contents($file,json_encode($p,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));file_put_contents($s['root'].'/obligation-baseline.json',json_encode(['passed'=>true,'initial_obligations'=>0,'initial_proposals'=>0,'initial_commands'=>0,'source_instance_pinned'=>true,'qa_rights'=>['purchasing_obligations.view','purchasing_obligations.prepare','purchasing_obligations.validate']],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));