Files
Investidor-V2/outputs/investmoz-orientacao-legado-agronegocio-20261015/read-dependencies.php
T
nala 6a76aac80f
tests / ci (push) Canceled after 0s
versao compilada 1
2026-10-16 09:17:28 +02:00

6 lines
2.4 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','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['database']!=='investemoz'||(int)$c['port']!==5432)throw new RuntimeException('Destination guard');
$targets=['destination'=>['database'=>'investemoz','port'=>5432,'user'=>$c['username'],'pass'=>$c['password']],'existing_pilot_QA'=>['database'=>'desk_restore_20261009_174726_test','port'=>55441,'user'=>'postgres','pass'=>'']];$result=['at'=>gmdate('c'),'method'=>'READ ONLY, no imports/publications','targets'=>[]];
foreach($targets as$label=>$t){$pdo=new PDO('pgsql:host=127.0.0.1;port='.$t['port'].';dbname='.$t['database'],$t['user'],$t['pass'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$pdo->exec('BEGIN READ ONLY');try{$identity=$pdo->query('select current_database() as database,inet_server_port() as port')->fetch(PDO::FETCH_ASSOC);if($identity['database']!==$t['database']||(int)$identity['port']!==$t['port'])throw new RuntimeException('Actual identity guard');$services=$pdo->query("select id,code,version,status,definition from desk_service_versions where status='published' order by code,version desc")->fetchAll(PDO::FETCH_ASSOC);foreach($services as&$s){$def=json_decode($s['definition'],true);$s['title']=$def['title']??null;$s['definition_sha256']=hash('sha256',$s['definition']);$s['definition_snapshot']=$def;unset($s['definition']);}unset($s);$resources=$pdo->query("select r.id as resource_id,r.metadata_version,r.published,r.rights_status,r.source_confirmation,d.external_id,d.sha256,d.data_classification,d.rights_status as file_rights_status,d.status,d.malware_scan_status,d.malware_scanned_sha256 from portal_resources r join documents d on d.id=r.document_id where d.external_id like 'legacy-tempo-%' order by r.id")->fetchAll(PDO::FETCH_ASSOC);$result['targets'][$label]=['identity'=>$identity,'services'=>$services,'sectors'=>$pdo->query("select id,name,slug,is_active from sectors where slug='agronegocio'")->fetchAll(PDO::FETCH_ASSOC),'resources'=>$resources];}finally{$pdo->exec('ROLLBACK');}}
file_put_contents(__DIR__.'/DEPENDENCIAS-LEITURA.json',json_encode($result,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));echo 'Read-only dependency snapshots refreshed';