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

3 lines
3.2 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('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.title,r.source_url,r.version_label,r.rights_status,r.source_confirmation,d.storage_key,d.media_type,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');}}$originals=[];foreach($result['targets']['active']['legacy_resources']as$row){$file=config('filesystems.disks.local.root').'/'.$row['storage_key'];if(!is_file($file)||hash_file('sha256',$file)!==trim($row['sha256']))throw new RuntimeException('Active original mismatch');if(str_starts_with($row['external_id'],'legacy-tempo-post-')){$source=json_decode(file_get_contents($file),true,512,JSON_THROW_ON_ERROR);$originals[]=['resource_id'=>(int)$row['id'],'external_id'=>$row['external_id'],'document_sha256'=>trim($row['sha256']),'legacy_id'=>$source['legacy_id'],'modified_at'=>$source['modified_at'],'body_sha256'=>hash('sha256',$source['content_html']),'source_url'=>$source['source_url'],'image_sha256'=>$source['image_sha256']];}}$result['active_originals']=$originals;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')]);