Files
Investidor-V2/tools/portal-functional-target-readonly.php
T
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

23 lines
3.2 KiB
PHP

<?php
// Destination inventory: configuration without providers, SQL read-only transaction.
use Illuminate\Foundation\Bootstrap\LoadConfiguration;
use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
$root=dirname(__DIR__);require $root.'/vendor/autoload.php';$app=require $root.'/bootstrap/app.php';
(new LoadEnvironmentVariables)->bootstrap($app);(new LoadConfiguration)->bootstrap($app);
$c=config('database.connections.'.config('database.default'));
throw_unless($c['driver']==='pgsql'&&empty($c['url'])&&$c['database']==='investemoz'&&(int)$c['port']===5432,RuntimeException::class,'Exact read-only destination required.');
$pdo=new PDO('pgsql:host='.$c['host'].';port='.$c['port'].';dbname='.$c['database'],$c['username'],$c['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
$pdo->exec('BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY');
try {
$identity=$pdo->query("SELECT current_database() AS database,inet_server_port() AS port,current_setting('transaction_read_only') AS read_only")->fetch(PDO::FETCH_ASSOC);
throw_unless($identity['database']==='investemoz'&&(int)$identity['port']===5432&&$identity['read_only']==='on',RuntimeException::class,'Read-only guard refused.');
$counts=[];foreach(['users','organizations','memberships','geo_locations','geo_geometries','opportunity_documents','opportunity_images','opportunity_location_drafts','portal_role_assignments']as$table){$exists=$pdo->query("SELECT to_regclass('public.$table') IS NOT NULL")->fetchColumn();$counts[$table]=$exists?(int)$pdo->query('SELECT count(*) FROM public.'.$table)->fetchColumn():null;}
$flags=[];foreach(['organization_country_enabled','profile_access_enabled','opportunity_dashboard_access_enabled','opportunity_specialized_drafts_enabled','opportunity_modular_profiles_qa_enabled','legacy_content_qa_enabled']as$name)$flags[$name]=(bool)config('portal.'.$name);
$proof=['at'=>gmdate('c'),'identity'=>$identity,'tables'=>(int)$pdo->query("SELECT count(*) FROM pg_tables WHERE schemaname NOT IN ('pg_catalog','information_schema')")->fetchColumn(),'counts'=>$counts,'flags'=>$flags,'journey_enabled'=>(bool)config('investor_path.enabled'),
'migrations'=>$pdo->query("SELECT migration FROM migrations WHERE migration IN ('2026_10_09_020000_extend_opportunity_management','2026_10_09_030000_extend_opportunity_resources','2026_10_10_040000_create_portal_profile_authorization','2026_10_09_190000_prepare_investor_path','2026_10_10_050000_extend_organization_country') ORDER BY migration")->fetchAll(PDO::FETCH_COLUMN),'active_manifest_sha256'=>hash_file('sha256',$root.'/public/build/manifest.json'),'active_writes'=>0];
throw_unless($flags['organization_country_enabled']&&!$flags['profile_access_enabled']&&!$flags['opportunity_dashboard_access_enabled']&&!$flags['opportunity_specialized_drafts_enabled'],RuntimeException::class,'Preserved target flags differ.');
}finally{$pdo->exec('ROLLBACK');}
$receipt=in_array('--upgrade',$argv,true)?'workflow-upgrade-target-readonly-20261011.json':(in_array('--scope',$argv,true)?'functional-scope-target-readonly-20261011.json':'functional-target-readonly-20261011.json');
file_put_contents($root.'/storage/app/private/investmoz-v2/portal-audit/'.$receipt,json_encode($proof,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
echo json_encode($proof,JSON_THROW_ON_ERROR).PHP_EOL;