Files
SGF/scripts/payables-status.php
T
2026-10-29 18:43:29 +02:00

14 lines
1.8 KiB
PHP

<?php
if(!isset($argv[1])){
foreach(['compras','sgf'] as $mode){$php=$mode==='compras'?'C:/Users/macbook/.config/investmoz/php-8.5.11/php.exe':'C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe';$command=escapeshellarg($php).' '.escapeshellarg(__FILE__).' '.$mode;passthru($command,$status);if($status)exit($status);}exit;
}
$mode=$argv[1];if(!in_array($mode,['compras','sgf'],true))throw new LogicException('Unknown host');
$s=json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/payables-demo-'.$mode.'.json'),true,32,JSON_THROW_ON_ERROR);
foreach($s as $k=>$v){putenv($k.'='.$v);$_ENV[$k]=$_SERVER[$k]=$v;}
require $s['HOST_ROOT'].'/vendor/autoload.php';$app=require $s['HOST_ROOT'].'/bootstrap/app.php';$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
$db=\Illuminate\Support\Facades\DB::connection();if(!preg_match('/^(compras_receipts_test_|payable_sgf_)[a-f0-9]{12}$/D',$db->getDatabaseName())||$db->selectOne('select current_database() as d')->d!==$s['DB_DATABASE'])throw new LogicException('Wrong QA database');
$role=$db->selectOne('select rolsuper,rolcreatedb,rolcreaterole from pg_roles where rolname=current_user');if($role->rolsuper||$role->rolcreatedb||$role->rolcreaterole)throw new LogicException('Restricted role required');
$counts=[];foreach(['sources','proposals','obligations','events','outbox'] as $t)$counts[$t]=$db->table('pa_'.$t)->count();
$report=['host'=>$mode,'isolated'=>true,'restricted_role'=>true,'counts'=>$counts,'core_sha256'=>hash_file('sha256',__DIR__.'/../packages/payables/src/Payables.php'),'checked_at'=>gmdate('c')];
file_put_contents(__DIR__.'/../docs/proofs/payables-demo-'.$mode.'.json',json_encode($report,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR).PHP_EOL);echo json_encode($report,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR).PHP_EOL;