Files
Investidor-V2/outputs/investmoz-setores-fintech-ativacao-20261015/resources-readonly.php
T
nala 6a76aac80f
tests / ci (push) Canceled after 0s
versao compilada 1
2026-10-16 09:17:28 +02:00

15 lines
4.1 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';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
$phase=$argv[1]??'inspect';if(!in_array($phase,['inspect','PRIVATE-SCAN','CLASSIFIED','PUBLISHED'],true))throw new RuntimeException('Phase');
Illuminate\Support\Facades\DB::statement('BEGIN READ ONLY');
try{
$target=Illuminate\Support\Facades\DB::selectOne('SELECT current_database() AS database,inet_server_port() AS port');if($target->database!=='investemoz'||(int)$target->port!==5432)throw new RuntimeException('Target');
$m=json_decode(file_get_contents($root.'/outputs/investmoz-fintech-investimento-QA-20261015/lote-privado/legacy-trio-20261015/manifest.json'),true,512,JSON_THROW_ON_ERROR);$items=[];
foreach($m['documents']as$e){$rows=Illuminate\Support\Facades\DB::table('documents as d')->join('portal_resources as r','r.document_id','=','d.id')->where('d.external_id',$e['external_id'])->whereNull('d.deleted_at')->get(['d.id as document_id','d.external_id','d.sha256','d.storage_key','d.status','d.data_classification','d.rights_status as file_rights','d.malware_scan_status','d.malware_scanned_sha256','d.malware_scan_attempts','d.malware_engine_version','d.malware_scanned_at','d.malware_signatures_at','r.id','r.title','r.category','r.topic','r.source_reference','r.source_confirmation','r.legal_status','r.rights_status','r.published','r.metadata_version','r.approved_by','r.document_type','r.language','r.source_url','r.version_label']);if($rows->count()!==1)throw new RuntimeException('Unique resource');$r=$rows[0];$r->actual_sha256=hash_file('sha256',Illuminate\Support\Facades\Storage::disk('local')->path($r->storage_key));unset($r->storage_key);if(!hash_equals($e['sha256'],$r->sha256)||!hash_equals($e['sha256'],$r->actual_sha256))throw new RuntimeException('Bytes');
if($phase!=='inspect'){if($r->malware_scan_status!=='clean'||!hash_equals($r->sha256,$r->malware_scanned_sha256)||$r->status!=='active')throw new RuntimeException('Scan not clean');if((bool)$r->published!==($phase==='PUBLISHED'))throw new RuntimeException('Publication state');if($phase==='PRIVATE-SCAN'&&$r->data_classification!=='internal')throw new RuntimeException('Private state');if(in_array($phase,['CLASSIFIED','PUBLISHED'],true)&&($r->data_classification!=='public'||$r->file_rights!=='authorized'||$r->rights_status!=='authorized'||$r->source_confirmation!=='identified'||$r->legal_status!=='not_applicable'||$r->category!=='education'||$r->document_type!=='guide'||$r->language!=='pt'))throw new RuntimeException('Metadata state');}
$items[]=$r;}
$image=Illuminate\Support\Facades\DB::table('documents as d')->join('portal_resources as r','r.document_id','=','d.id')->where('d.external_id',$m['reused_resources'][0]['external_id'])->get(['r.id','r.published','r.metadata_version','d.sha256','d.storage_key','d.malware_scan_status','d.malware_scanned_sha256']);if($image->count()!==1)throw new RuntimeException('Shared image');$image=$image[0];$image->actual_sha256=hash_file('sha256',Illuminate\Support\Facades\Storage::disk('local')->path($image->storage_key));unset($image->storage_key);if($image->sha256!==$m['reused_resources'][0]['sha256']||$image->sha256!==$image->actual_sha256||$image->sha256!==$image->malware_scanned_sha256||!$image->published)throw new RuntimeException('Image state');
$jobs=Illuminate\Support\Facades\DB::table('jobs')->orderBy('id')->get(['id','queue','attempts','reserved_at','available_at','payload'])->map(function($j){$p=json_decode($j->payload,true);unset($j->payload);$j->job_class=$p['displayName']??null;return $j;});
$out=['at'=>gmdate('c'),'target'=>$target,'phase'=>$phase,'resources'=>$items,'reused_image'=>$image,'queue'=>$jobs,'active_writes'=>0];if($phase!=='inspect'){if(is_file(__DIR__.'/'.$phase.'.json'))throw new RuntimeException('Preserve proof');file_put_contents(__DIR__.'/'.$phase.'.json',json_encode($out,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));}echo json_encode($out,JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR);
}finally{Illuminate\Support\Facades\DB::statement('ROLLBACK');}