Files
SGF/scripts/sgf-install-coverage-reconciliation.php
2026-11-11 15:04:01 +02:00

8 lines
2.6 KiB
PHP

<?php
$book='8085';require __DIR__.'/sgf-single-bootstrap.php';
if((json_decode(file_get_contents($run['root'].'/private/receipt-composition-b4093c6f6707/single-integration/20261111-103843-f515a584/coverage-reconciliation.json'),true)['passed']??false)!==true)throw new LogicException('Metadata proof required');
$previous=json_decode(file_get_contents($s['root'].'/single-integration/20261111-090956-998c70ef/hp-installation.json'),true);$qualified=$previous['identical_original_tables'];$before=[];$order=fn($table)=>in_array($table,['sr_outbox','sr_deliveries'],true)?'event_id':(in_array($table,['sc_catalogue_meta','pd_due_meta','fo_meta','fs_meta','rm_meta','hp_meta'],true)?'policy':(in_array($table,['hr_qa_profiles','sgf_presentation_profiles'],true)?'profile_key':(in_array($table,['fs_results','fs_result_lines'],true)?'snapshot_key':($table==='company_memberships'?'user_id':'id'))));foreach($qualified as$key){[$name,$table]=explode('.',$key);$db=$name==='host'?$host:$native;$before[$name][$table]=$db->table($table)->orderBy($order($table))->when($table==='fs_result_lines',fn($q)=>$q->orderBy('account_id'))->get()->toJson();}$binding=hash_file('sha256',$s['root'].'/binding.json');file_put_contents($work.'/preservation-private.json',json_encode($before));
$files=['app/Modules/Services/FiscalCoverage.php'];foreach($files as$file)if(str_ends_with($file,'.php'))(new Symfony\Component\Process\Process([PHP_BINARY,'-l',$repo.'/'.$file]))->mustRun();$hashes=[];$copy=function($src,$file)use($s,$work,&$hashes){$dest=$s['app'].'/'.$file;$backup=$work.'/before/'.$file;if(is_file($dest)){if(!is_dir(dirname($backup)))mkdir(dirname($backup),0700,true);copy($dest,$backup);}if(!is_dir(dirname($dest)))mkdir(dirname($dest),0700,true);copy($src,$dest);$hashes[$file]=hash_file('sha256',$dest);};foreach($files as$file)$copy($repo.'/'.$file,$file);
$checks=[];foreach($before as$name=>$tables){$db=$name==='host'?$host:$native;foreach($tables as$table=>$json){if($db->table($table)->orderBy($order($table))->when($table==='fs_result_lines',fn($q)=>$q->orderBy('account_id'))->get()->toJson()!==$json)throw new LogicException('Original facts changed '.$table);$checks[]=$name.'.'.$table;}}if($binding!==hash_file('sha256',$s['root'].'/binding.json'))throw new LogicException('Binding changed');file_put_contents($work.'/coverage-reconciliation-installation.json',json_encode(['passed'=>true,'hashes'=>$hashes,'identical_original_tables'=>$checks,'business_commands'=>0,'new_grants'=>0,'new_demo'=>false,'cache_cleared'=>false,'native_writes'=>0,'binding_unchanged'=>true],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'proof'=>$work.'/coverage-reconciliation-installation.json']).PHP_EOL;