Files
SGF/scripts/sgf-bank-setup.php
T
2026-11-11 09:00:17 +02:00

5 lines
2.6 KiB
PHP

<?php
$book=$argv[1]??'regression';require __DIR__.'/sgf-single-bootstrap.php';$p=json_decode(file_get_contents($repo.'/docs/integration/sgf-bank-reconciliation-access-proposal.json'),true);if(($p['approved']??false)!==true||($p['authorization']['decision']??null)!=='Autorizar a conferência bancária QA e os direitos apresentados'||count($p['grants_per_book'])!==8)throw new LogicException('Specific approval required');$count=0;
$host->transaction(function()use($host,$p,&$count){$old=$host->selectOne("SELECT pg_get_constraintdef(oid) d FROM pg_constraint WHERE conrelid='permission_grants'::regclass AND conname='permission_grants_scope_check'")->d;if(!str_contains($old,'bank_reconciliation.view')){if(!preg_match('/^CHECK \((.*)\)$/s',$old,$m))throw new LogicException('Unknown scope check');$host->statement('ALTER TABLE permission_grants DROP CONSTRAINT permission_grants_scope_check');$names=implode(',',array_map(fn($s)=>"'".$s."'",$p['new_right_names']));$host->statement('ALTER TABLE permission_grants ADD CONSTRAINT permission_grants_scope_check CHECK (('.$m[1].') OR (unit_id IS NOT NULL AND permission IN('.$names.')))');}foreach($p['grants_per_book']as$g){if(!in_array($g['user_id'],[13,14,15,16,17],true)||array_intersect_key($g,array_flip(['tenant_id','company_id','unit_id']))!==['tenant_id'=>1,'company_id'=>2,'unit_id'=>2])throw new LogicException('Exact approved recipients');if($host->table('permission_grants')->where($g)->exists())continue;$host->table('permission_grants')->insert($g);App\Modules\Identity\Services\Audit::record('access.granted_on_creation',null,1,2,2,$g['user_id'],['permission'=>$g['permission'],'reason'=>$p['authorization']]);$count++;}if(!$host->getSchemaBuilder()->hasTable('br_statements'))$host->unprepared(file_get_contents(dirname(__DIR__).'/database/sql/bank_reconciliation.sql'));});
$binding=['composition'=>$tag,'scope'=>$f['scope'],'statement_key'=>'e232a83b-14d2-43e2-aa74-225df3858b45','ledger_line_ids'=>[4,5],'account_ref'=>'QA-BANCO-LOCAL','period'=>'2026-11','synthetic_only'=>true];$file=$s['root'].'/bank-binding.json';if(is_file($file)&&json_decode(file_get_contents($file),true)!==$binding)throw new LogicException('Preserve different bank binding');if(!is_file($file))file_put_contents($file,json_encode($binding,JSON_PRETTY_PRINT));file_put_contents($work.'/bank-setup.json',json_encode(['passed'=>true,'book'=>$book,'new_grants'=>$count,'new_right_names'=>4,'new_users'=>0,'new_pg_roles'=>0,'new_demo'=>false],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'book'=>$book,'new_grants'=>$count,'proof'=>$work.'/bank-setup.json']).PHP_EOL;