Files
Investidor-V2/outputs/investmoz-audit-current-20261012/C132-preflight.php
T
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

25 lines
2.9 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1');
set_exception_handler(function(Throwable $e){fwrite(STDERR,"C132 preflight stopped: ".$e::class." at ".basename($e->getFile()).":".$e->getLine()."\n");exit(1);});
$root=dirname(__DIR__,2); require $root.'/vendor/autoload.php';
$app=require $root.'/bootstrap/app.php';
(new Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables)->bootstrap($app);
(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app);
$c=config('database.connections.'.config('database.default'));
if($c['driver']!=='pgsql'||!empty($c['url'])||!in_array($c['host'],['localhost','127.0.0.1'],true)||(int)$c['port']!==5432||$c['database']!=='investemoz')throw new RuntimeException('Target mismatch');
$db=new PDO('pgsql:host='.$c['host'].';port='.$c['port'].';dbname='.$c['database'],$c['username'],$c['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
$db->exec('BEGIN READ ONLY');$target=$db->query('select current_database() as database,inet_server_port() as port')->fetch(PDO::FETCH_ASSOC);$db->exec('ROLLBACK');
if($target['database']!=='investemoz'||(int)$target['port']!==5432)throw new RuntimeException('Identity mismatch');
$backup=json_decode(file_get_contents($root.'/storage/app/private/investmoz-v2/portal-audit/internal-designation-target-backup.json'),true,512,JSON_THROW_ON_ERROR);
if(empty($backup['restore_verified'])||empty($backup['files_verified'])||count($backup['tables'])!==295)throw new RuntimeException('Existing restore proof not valid');
foreach(['dump_path'=>'dump_sha256','files_path'=>'files_sha256'] as $p=>$h){if(!is_file($backup[$p])||hash_file('sha256',$backup[$p])!==$backup[$h])throw new RuntimeException('Recovery artifact differs');}
$data=['at'=>gmdate('c'),'target'=>$target,'cached_config'=>$app->configurationIsCached(),'route_cache'=>count(glob($root.'/bootstrap/cache/routes*.php'))>0,
'APP_ENV'=>config('app.env'),'session_driver'=>config('session.driver'),'session_cookie'=>config('session.cookie'),
'key_fingerprint'=>hash('sha256',config('app.key')),'previous_key_count'=>count(config('app.previous_keys',[])),
'flags'=>array_intersect_key(config('portal'),array_flip(['organization_country_enabled','profile_administration_enabled','profile_access_enabled','opportunity_dashboard_access_enabled','opportunity_specialized_drafts_enabled','notifications_enabled'])),
'backup_verified_at'=>$backup['verified_at'],'backup_artifacts_hashes_verified'=>true,'backup_restore_tables'=>count($backup['tables']),
'C131_active_hash'=>hash_file('sha256',$root.'/app/Services/OpportunityContacts.php'),
'active_inertia_hash'=>hash_file('sha256',$root.'/config/inertia.php'),'build_hash'=>hash_file('sha256',$root.'/public/build/manifest.json')];
$output=($argv[1]??'')==='--after'?'C132-runtime-after.json':'C132-preflight.json';
file_put_contents(__DIR__.'/'.$output,json_encode($data,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR));echo json_encode($data,JSON_THROW_ON_ERROR);