22 lines
2.9 KiB
PHP
22 lines
2.9 KiB
PHP
<?php
|
|
require __DIR__.'/boot-QA.php';
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
$o=App\Models\Opportunity::findOrFail(16);$before=$o->getRawOriginal();$v=app(App\Services\OpportunityManagement::class)->values($o);$p=$v['canonical'];
|
|
if($o->status!=='draft'||isset($p['images']))throw new RuntimeException('Preserve existing test state');
|
|
$image=DB::table('opportunity_images')->where('opportunity_id',56)->whereNull('deleted_at')->first();if(!$image)throw new RuntimeException('Prepared synthetic image required');
|
|
$meta=json_decode($image->payload,true);$files=[$image->document_id];foreach($meta['derivatives']??[]as$d)$files[]=$d['document_id'];
|
|
$reference=dirname(__DIR__,2).'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742/storage/app/private';$copies=[];
|
|
foreach(array_unique($files)as$id){$doc=DB::table('documents')->where('id',$id)->first();$from=$reference.'/'.$doc->storage_key;$raw=file_get_contents($from);$bytes=$doc->storage_encryption==='laravel'?Crypt::decryptString($raw):$raw;
|
|
if(hash('sha256',$bytes)!==trim($doc->sha256)||$doc->malware_scan_status!=='clean')throw new RuntimeException('Existing synthetic image integrity');$to=storage_path('app/private/'.$doc->storage_key);if(!is_dir(dirname($to)))mkdir(dirname($to),0700,true);file_put_contents($to,$raw);$copies[]=['document'=>$id,'name'=>$doc->file_name,'hash'=>trim($doc->sha256)];}
|
|
$new=(array)$image;$new['id']=(string)Illuminate\Support\Str::uuid();$new['opportunity_id']=16;$new['created_by']=21;$new['created_at']=$new['updated_at']=now();$new['version']=1;
|
|
$meta['is_cover']=true;$new['payload']=json_encode($meta,JSON_THROW_ON_ERROR);
|
|
DB::table('opportunity_images')->insert($new);
|
|
$p['images']=[$new['id']];$p['visibility']='public';
|
|
foreach($p['milestones']as&$milestone){$milestone['start_date']??='2026-11-01';$milestone['end_date']??='2026-12-01';$milestone['responsible_name']??='Responsável sintético QA';}unset($milestone);
|
|
foreach($p['relations']as&$row)foreach(['external_act_reference','production_stage']as$key)if(($row['classification'][$key]??null)===null)unset($row['classification'][$key]);unset($row);
|
|
$v['canonical']=$p;$o->management_draft=$v;$o->save();
|
|
file_put_contents(dirname($source).'/canonical-fixture-completion-before.json',json_encode($before,JSON_THROW_ON_ERROR));
|
|
file_put_contents(__DIR__.'/CANONICAL-FIXTURE-COMPLETION.json',json_encode(['id'=>16,'source_image_opportunity'=>56,'copies'=>$copies,'new_document_uploads'=>0,'new_resource_links'=>1,'scope'=>'Only isolated clone fixture: supply missing milestone metadata and reuse existing synthetic image for public projection; no claims about previous workflow or historical legacy content.','approval_fixture'=>false,'active_changes'=>0],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));
|
|
echo json_encode(['fixture_only'=>true,'synthetic_originals_reused'=>count($copies),'new_document_uploads'=>0]);
|