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);$c=DB::selectOne("SELECT pg_get_constraintdef(oid) definition FROM pg_constraint WHERE conrelid='permission_grants'::regclass AND conname='permission_grants_scope_check'");if(!preg_match('/^CHECK\s*\((.*)\)$/s',$c->definition,$m))throw new LogicException('QA catalogue 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_suppliers.view','purchasing_suppliers.prepare','purchasing_suppliers.review')))"); foreach(['actor'=>['view','prepare'],'issuer'=>['view','review']]as$role=>$rights)foreach($rights as$right)DB::table('permission_grants')->insert($f['scope']+['user_id'=>$f[$role],'permission'=>'purchasing_suppliers.'.$right,'created_at'=>now(),'updated_at'=>now()]);$path=$s['root'].'/binding.json';$p=json_decode(file_get_contents($path),true);$key=implode(':',array_values($f['scope'])).':'.$f['issuer'];$p['bindings'][$key]['actor_id']=$n['finance'];file_put_contents($path,json_encode($p,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));file_put_contents($s['root'].'/supplier-baseline.json',json_encode(['passed'=>true,'prepared_seed_suppliers'=>3,'created_through_sgf'=>0,'quotes'=>0,'awards'=>0,'orders'=>0,'receipts'=>0,'movements'=>0],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));