bootstrap($app);(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app);$c=config('database.connections.'.config('database.default'));if($c['database']!=='investemoz'||(int)$c['port']!==5432)throw new RuntimeException('Active identity guard');$targets=['active'=>['db'=>'investemoz','port'=>5432,'user'=>$c['username'],'password'=>$c['password']],'QA'=>['db'=>'stability_consumers_20261011_084534_test','port'=>55441,'user'=>'postgres','password'=>'']];$result=['at'=>gmdate('c'),'method'=>'READ ONLY; inventory and dependencies only','targets'=>[]];foreach($targets as$k=>$t){$p=new PDO('pgsql:host=127.0.0.1;port='.$t['port'].';dbname='.$t['db'],$t['user'],$t['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$p->exec('BEGIN READ ONLY');try{$id=$p->query('select current_database() as database,inet_server_port() as port')->fetch(PDO::FETCH_ASSOC);if($id['database']!==$t['db']||(int)$id['port']!==$t['port'])throw new RuntimeException('Actual identity guard');$result['targets'][$k]=['identity'=>$id,'sectors'=>$p->query('select id,name,slug,is_active from sectors order by id')->fetchAll(PDO::FETCH_ASSOC),'legacy_resources'=>$p->query("select r.id,r.metadata_version,r.published,r.source_url,r.rights_status,d.external_id,d.sha256,d.malware_scan_status,d.malware_scanned_sha256,d.data_classification from portal_resources r join documents d on d.id=r.document_id where d.external_id like 'legacy-tempo-%' and d.deleted_at is null order by r.id")->fetchAll(PDO::FETCH_ASSOC),'published_services'=>$p->query("select id,code,version,status from desk_service_versions where status='published' order by code,version desc")->fetchAll(PDO::FETCH_ASSOC)];}finally{$p->exec('ROLLBACK');}}file_put_contents(__DIR__.'/LEITURA-ESTADO.json',json_encode($result,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));echo json_encode(['active_legacy_count'=>count($result['targets']['active']['legacy_resources']),'QA_legacy_count'=>count($result['targets']['QA']['legacy_resources']),'active_sector_slugs'=>array_column($result['targets']['active']['sectors'],'slug'),'QA_sector_slugs'=>array_column($result['targets']['QA']['sectors'],'slug')]);