Files
SGF/scripts/sgf-assets-backup.php
T
2026-11-11 15:04:01 +02:00

3 lines
2.0 KiB
PHP

<?php
$book='8085';require __DIR__.'/sgf-single-bootstrap.php';$prior=json_decode(file_get_contents($s['root'].'/single-integration/20261111-095619-e3fff98c/hp-readable-installation.json'),true);$qualified=array_unique(array_merge($prior['identical_original_tables'],array_map(fn($t)=>'native.'.$t,['gl_accounts','gl_rules','gl_proposals','gl_reviews','gl_journals','gl_lines','gl_commands','gl_events','gl_corrections','gl_correction_results','gl_period_checks','gl_period_reviews','gl_period_closures'])));$before=[];$order=fn($t)=>in_array($t,['sr_outbox','sr_deliveries'],true)?'event_id':(in_array($t,['sc_catalogue_meta','pd_due_meta','fo_meta','fs_meta','rm_meta','hp_meta'],true)?'policy':(in_array($t,['hr_qa_profiles','sgf_presentation_profiles'],true)?'profile_key':(in_array($t,['fs_results','fs_result_lines'],true)?'snapshot_key':($t==='company_memberships'?'user_id':'id'))));foreach($qualified as$k){[$n,$t]=explode('.',$k);$db=$n==='host'?$host:$native;$before[$n][$t]=$db->table($t)->orderBy($order($t))->when($t==='fs_result_lines',fn($q)=>$q->orderBy('account_id'))->get()->toJson();}foreach(['binding.json','single-bindings.json','stock-binding.json']as$f)$before['files'][$f]=hash_file('sha256',$s['root'].'/'.$f);file_put_contents($work.'/preservation-private.json',json_encode($before));$files=['packages/general-ledger/bootstrap.php','packages/general-ledger/src/PayableJournal.php','packages/general-ledger/src/LedgerCycle.php','app/Modules/Accounting/ComposedLedger.php'];foreach($files as$f){$to=$work.'/before/'.$f;if(!is_dir(dirname($to)))mkdir(dirname($to),0700,true);copy($repo.'/'.$f,$to);}file_put_contents($work.'/gl-balance-function-private.sql',$native->selectOne("SELECT pg_get_functiondef('gl_assert_balanced(bigint)'::regprocedure) definition")->definition);file_put_contents($s['root'].'/assets-backup-pointer.json',json_encode(['root'=>$work]));echo json_encode(['passed'=>true,'backup'=>$work,'original_tables'=>count($qualified),'database_writes'=>0]).PHP_EOL;