6 lines
4.0 KiB
PHP
6 lines
4.0 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');$rows=DB::table('portal_resources as r')->join('documents as d','d.id','=','r.document_id')->whereIn('r.id',[5,6])->get(['r.id','r.title','r.published','r.metadata_version','r.approved_by','r.last_reviewed_by','r.rights_status','r.source_confirmation','d.external_id','d.sha256','d.malware_scan_status','d.malware_scanned_sha256']);foreach($rows as$x)if(!$x->published||(int)$x->approved_by!==2||$x->malware_scan_status!=='clean'||trim($x->sha256)!==$x->malware_scanned_sha256)throw new RuntimeException('Published record 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,'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',[5,6])->orderBy('resource_id')->orderBy('revision_no')->get(['resource_id','revision_no','change_type','actor_user_id','created_at']),'other_legacy_documents'=>DB::table('documents')->where('external_id','like','legacy-tempo-%')->count()-2,'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');}
|