10 lines
3.6 KiB
PHP
10 lines
3.6 KiB
PHP
<?php
|
|
$book='8085';require __DIR__.'/sgf-single-bootstrap.php';$pointer=json_decode(file_get_contents($s['root'].'/stock-catalogue-backup-pointer.json'),true);$before=json_decode(file_get_contents($pointer['root'].'/preservation-private.json'),true);$flow=json_decode(file_get_contents($s['root'].'/stock-catalogue-http-20261110.json'),true);if(($flow['passed']??false)!==true)throw new LogicException('Accepted directed flow required');$checks=[];
|
|
foreach(['host'=>$host,'native'=>$native]as$name=>$db)foreach($before[$name]as$table=>$json){$rows=json_decode($json,true);$key=in_array($table,['sr_outbox','sr_deliveries'],true)?'event_id':'id';if($db->table($table)->whereIn($key,array_column($rows,$key))->orderBy($key)->get()->toJson()!==$json)throw new LogicException('Original rows changed '.$name.'.'.$table);$expected=count($rows)+($table==='permission_grants'?2:($name==='native'&&$table==='stock_items'?1:($name==='native'&&$table==='audit_logs'?2:0)));if($db->table($table)->count()!==$expected)throw new LogicException('Unexpected append '.$name.'.'.$table);$checks[]=$name.'.'.$table;}
|
|
foreach(['binding.json'=>'binding','single-bindings.json'=>'single_binding','stock-binding.json'=>'stock_binding']as$file=>$key)if(hash_file('sha256',$s['root'].'/'.$file)!==$before[$key])throw new LogicException('Original binding changed '.$file);
|
|
$oldGrants=array_column(json_decode($before['host']['permission_grants'],true),'id');$newGrants=$host->table('permission_grants')->whereNotIn('id',$oldGrants)->orderBy('user_id')->get(['user_id','permission','tenant_id','company_id','unit_id'])->map(fn($r)=>(array)$r)->all();if($newGrants!==[['user_id'=>2,'permission'=>'stock.items.prepare','tenant_id'=>1,'company_id'=>2,'unit_id'=>2],['user_id'=>12,'permission'=>'stock.items.review','tenant_id'=>1,'company_id'=>2,'unit_id'=>2]])throw new LogicException('Different access scope');
|
|
$oldItems=array_column(json_decode($before['native']['stock_items'],true),'id');$new=$native->table('stock_items')->whereNotIn('id',$oldItems)->get();if($new->count()!==1||$new[0]->code!=='QA-CATALOGO-INTEGRADO'||$new[0]->unit!=='UN'||$native->table('stock_movements')->where('stock_item_id',$new[0]->id)->exists())throw new LogicException('One new zero-history article required');if($native->table('sc_catalogue_versions')->where('record_key',$flow['record_key'])->count()!==2||$native->table('sc_catalogue_commands')->count()!==2)throw new LogicException('Unexpected catalogue decisions');
|
|
$oldAudit=array_column(json_decode($before['native']['audit_logs'],true),'id');foreach($native->table('audit_logs')->whereNotIn('id',$oldAudit)->get()as$row){$after=json_decode($row->after,true);if($row->action!=='sgf.stock.catalogue.command'||($after['record_key']??null)!==$flow['record_key'])throw new LogicException('Unrelated native audit append');}
|
|
$public=$native->selectOne("SELECT EXISTS(SELECT 1 FROM pg_proc p,LATERAL aclexplode(coalesce(p.proacl,acldefault('f',p.proowner))) a WHERE p.pronamespace='public'::regnamespace AND p.proname='sc_catalogue_append_only' AND a.grantee=0) allowed")->allowed;if($public)throw new LogicException('No new PUBLIC execution permission permitted');
|
|
file_put_contents($work.'/stock-catalogue-preservation.json',json_encode(['passed'=>true,'identical_original_tables'=>$checks,'approved_new_host_grants'=>$newGrants,'old_bindings_unchanged'=>true,'new_articles'=>1,'new_stock_movements'=>0,'new_journals'=>0,'new_public_function_permissions'=>0,'six_protected_records'=>'No connections or commands target protected installations/records','blocked_cache'=>'No clear/delete','new_demo'=>false],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'proof'=>$work.'/stock-catalogue-preservation.json']).PHP_EOL;
|