Files
SGF/scripts/sgf-payable-due-backup.php
2026-11-11 09:00:17 +02:00

5 lines
1.9 KiB
PHP

<?php
$book='8085';require __DIR__.'/sgf-single-bootstrap.php';if(is_file($s['root'].'/payable-due-backup-pointer.json'))throw new LogicException('Preserve existing catalogue baseline');if($native->table('gl_journals')->count()!==27)throw new LogicException('Expected27 accepted journals');
foreach(['host'=>['database'=>$s['env']['DB_DATABASE'],'username'=>$s['env']['DB_USERNAME'],'password'=>$s['env']['DB_PASSWORD']],'native'=>$s['nativeConnection']]as$name=>$c){$dump=new Symfony\Component\Process\Process(['C:/Program Files/PostgreSQL/17/bin/pg_dump.exe','-h','127.0.0.1','-p','55439','-U',$c['username'],'-d',$c['database'],'--format=custom','--no-owner','--no-privileges','--file',$work.'/'.$name.'-before-payable-due.dump'],$repo,['PGPASSWORD'=>$c['password']]);$dump->setTimeout(120);$dump->mustRun();}
$prior=json_decode(file_get_contents($s['root'].'/single-integration/20261110-220955-ad348ffc/payable-positions-preservation.json'),true);$qualified=array_unique(array_merge($prior['identical_original_tables'],['native.invoices','native.pa_obligations','native.pa_sources','native.pa_commands','native.stock_items','native.audit_logs']));$before=[];foreach($qualified as$key){[$name,$table]=explode('.',$key);$db=$name==='host'?$host:$native;$before[$name][$table]=$db->table($table)->orderBy(in_array($table,['sr_outbox','sr_deliveries'],true)?'event_id':($table==='sc_catalogue_meta'?'policy':'id'))->get()->toJson();}$before['binding']=hash_file('sha256',$s['root'].'/binding.json');$before['single_binding']=hash_file('sha256',$s['root'].'/single-bindings.json');$before['stock_binding']=hash_file('sha256',$s['root'].'/stock-binding.json');file_put_contents($work.'/preservation-private.json',json_encode($before));file_put_contents($s['root'].'/payable-due-backup-pointer.json',json_encode(['root'=>$work]));echo json_encode(['passed'=>true,'private_backup'=>$work,'database_writes'=>0]).PHP_EOL;