9 lines
6.3 KiB
PHP
9 lines
6.3 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();$c=config('database.connections.'.config('database.default'));if($c['database']!=='investemoz'||(int)$c['port']!==5432)throw new RuntimeException('Destination guard');
|
|
use Illuminate\Support\Facades\DB;
|
|
$b=json_decode(file_get_contents(__DIR__.'/FRESH-BACKUP.json'),true);$baseline=json_decode(file_get_contents($b['private_directory'].'/backup-proof-private.json'),true);$clone=new PDO('pgsql:host=127.0.0.1;port=55441;dbname='.$b['restore_target']['database'],'postgres','',[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$clone->exec('BEGIN READ ONLY');DB::beginTransaction();DB::statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ ONLY');try{$diff=[];$same=0;foreach($baseline['tables']as$name=>$before){$sql='SELECT row_to_json(t)::text as value FROM '.$name.' t ORDER BY row_to_json(t)::text';$now=array_map(fn($x)=>$x->value,DB::select($sql));if(hash('sha256',implode("\n",$now))===$before['sha256']){$same++;continue;}$old=$clone->query($sql)->fetchAll(PDO::FETCH_COLUMN);$removed=array_values(array_diff($old,$now));$added=array_values(array_diff($now,$old));$technical=in_array($name,['"public"."cache"','"public"."cache_locks"','"public"."sessions"']);if(!$technical&&$removed!==[])throw new RuntimeException('Preexisting business rows changed: '.$name);if(!$technical&&!in_array($name,['"public"."documents"','"public"."portal_resources"','"public"."portal_resource_revisions"','"public"."audit_events"','"public"."document_malware_scans"']))throw new RuntimeException('Unexpected new domain rows: '.$name);$diff[$name]=['before'=>count($old),'after'=>count($now),'prior_rows_changed_or_removed'=>count($removed),'new_or_changed_rows'=>count($added),'technical'=>$technical];}
|
|
$reader=app(App\Services\LegacyContent::class);if(!$reader->available()||!config('investor-path.enabled'))throw new RuntimeException('Flags incorrect');$article=$reader->article('agronegocio');if($article['id']!==5||$article['image']['sha256']!=='5e3840705cf98226d1f189cf665aaa98cb05da96c645159a1332a1d429d642eb')throw new RuntimeException('Wrong article/image');$manifest=json_decode(file_get_contents($root.'/outputs/investmoz-legado-setores-lote20-QA-20261015/MANIFESTO-POR-RECURSO.json'),true)['resources'];$expected=array_column($manifest,null,'external_id');$rows=DB::table('portal_resources as r')->join('documents as d','d.id','=','r.document_id')->whereIn('d.external_id',array_keys($expected))->orderBy('r.id')->get(['r.id','r.title','r.published','r.metadata_version','r.approved_by','r.last_reviewed_by','r.source_url','r.version_label','r.source_reference','r.rights_status','r.source_confirmation','r.legal_status','d.external_id','d.sha256','d.storage_key','d.data_classification','d.malware_scan_status','d.malware_scanned_sha256']);if($rows->count()!==20)throw new RuntimeException('Count incorrect');foreach($rows as$x){$e=$expected[$x->external_id];if(!$x->published||(int)$x->approved_by!==2||(int)$x->last_reviewed_by!==2||(int)$x->metadata_version!==3||$x->rights_status!=='authorized'||$x->source_confirmation!=='identified'||$x->legal_status!=='not_applicable'||$x->data_classification!=='public'||$x->malware_scan_status!=='clean'||trim($x->sha256)!==$x->malware_scanned_sha256||trim($x->sha256)!==$e['sha256']||hash_file('sha256',Illuminate\Support\Facades\Storage::disk('local')->path($x->storage_key))!==$e['sha256']||$x->title!==$e['title']||$x->source_url!==$e['source_url']||$x->version_label!==$e['version_label']||!str_starts_with($x->source_reference,$e['source_reference'])||!str_contains($x->source_reference,'manifesto SHA-256 ade9a00c031534f4341e8f6bd5e425b502ee03efc9fcfaec4f463a10fb28201b'))throw new RuntimeException('Published manifest/metadata mismatch');}
|
|
$resolved=[];foreach(config('legacy_content.articles')as$slug=>$identity){if(!isset($expected[$identity['external_id']]))continue;$a=$reader->article($slug);$origin=$reader->articleForResource($a['id']);if($a['sha256']!==$expected[$identity['external_id']]['sha256']||!$a['image']||!$a['sector']||$origin['start_href']!=='/investimentos/a-partir-de/'.$slug)throw new RuntimeException('Resolution mismatch');$resolved[]=['slug'=>$slug,'href'=>$a['href'],'image'=>$a['image'],'resource_id'=>$a['id'],'context_version'=>$a['version'],'start_href'=>$origin['start_href'],'sector'=>$a['sector']];}if(count($resolved)!==16)throw new RuntimeException('Resolution count mismatch');
|
|
foreach($baseline['file_hashes']as$relative=>$hash){if($relative==='app/Console/Commands/ImportDocumentBatch.php'||str_starts_with($relative,'storage-documents/'))continue;if(hash_file('sha256',$root.'/'.$relative)!==$hash)throw new RuntimeException('Protected file changed: '.$relative);}if(hash_file('sha256',$root.'/app/Console/Commands/ImportDocumentBatch.php')!=='f429fb2655a3956f4025d3a42db64d161643872045a134f63ab183f5dc011eb8')throw new RuntimeException('Candidate source mismatch');
|
|
$service=DB::table('desk_service_versions')->where('code','project-preparation')->where('status','published')->orderByDesc('version')->first(['id','code','version']);if((int)$service->version!==5)throw new RuntimeException('Service baseline changed');$v=['at'=>gmdate('c'),'target'=>'investemoz:5432','SQL_read_only'=>true,'tables_checked'=>count($baseline['tables']),'tables_exactly_equal'=>$same,'differences'=>$diff,'all_preexisting_business_rows_preserved'=>true,'resources'=>$rows,'resolved_origins'=>$resolved,'all_20_manifest_metadata_and_hashes_match'=>true,'protected_files_unchanged'=>true,'configuration_changes'=>0,'article_resource_id'=>$article['id'],'image_href'=>$article['image']['href'],'reader_enabled'=>true,'B_path_enabled'=>true,'latest_published_support'=>$service,'resource_revisions'=>DB::table('portal_resource_revisions')->whereIn('resource_id',range(7,26))->orderBy('resource_id')->orderBy('revision_no')->get(['resource_id','revision_no','change_type','actor_user_id','created_at']),'excluded_financial_documents'=>DB::table('documents')->where('external_id','legacy-tempo-post-171994-20260417')->count(),'no_new_dossiers_or_support_requests'=>true];file_put_contents(__DIR__.'/FINAL-READONLY.json',json_encode($v,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));echo json_encode($v,JSON_THROW_ON_ERROR);}finally{DB::rollBack();$clone->exec('ROLLBACK');}
|