getTraceAsString().PHP_EOL);exit(1);}); use Illuminate\Support\Facades\DB; use App\Models\ExistingBusiness; use App\Models\User; use App\Services\ExistingBusinessClassification; $private='C:/Users/macbook/.config/investmoz/negocios-classificacao-QA-20261016'; if(is_file($private.'/compatibility-before.json'))throw new RuntimeException('Preserve compatibility case'); $business=ExistingBusiness::where('owner_user_id',1)->where('status','draft')->orderBy('id')->firstOrFail();$actor=User::findOrFail(1); try { $business->payload; $syntheticReplacement=false; } catch (Illuminate\Contracts\Encryption\DecryptException) { // Existing legacy drafts were encrypted with a different pre-QA key. Never import active secrets. // Keep the original ciphertext privately. Initialize only this isolated fixture with the QA key; no application or active key is changed. file_put_contents($private.'/compatibility-original-ciphertext-private.json',json_encode($business->getAttributes(),JSON_THROW_ON_ERROR)); $syntheticPayload=['title'=>'ENSAIO SINTÉTICO QA — compatibilidade com código anterior','description'=>'Conteúdo sintético autorizado exclusivamente para demonstrar preservação do suplemento numa edição posterior pelo código anterior.','source_reference'=>'Fixture sintética QA — sem divulgação ou efeito externo.']; DB::table('existing_businesses')->where('id',$business->id)->update(['payload'=>Illuminate\Support\Facades\Crypt::encryptString(json_encode($syntheticPayload,JSON_THROW_ON_ERROR))]); $business->refresh(); $business=app(App\Services\ExistingBusinessDrafts::class)->save($actor,['modality'=>$business->modality,'classification'=>$business->classification,'version_no'=>$business->version_no, 'reason'=>'Preparar conteúdo exclusivamente sintético no rascunho existente do clone para o ensaio de compatibilidade, preservando o exemplar cifrado anterior privadamente.', 'payload'=>$syntheticPayload],$business->id); $syntheticReplacement=true; } $f=json_decode(file_get_contents($private.'/fixture-private.json'),true);$row=$f['rows'][0];$row['classification']['document_id']=null;$row['classification']['disclosure']='restricted'; $business=app(ExistingBusinessClassification::class)->act($actor,$business->id,['action'=>'prepare','version_no'=>$business->version_no,'reason'=>'Ensaio sintético QA: suplemento no rascunho existente para provar edição posterior pelo código anterior.','rows'=>[$row]]); $state=app(ExistingBusinessClassification::class)->context($business); file_put_contents($private.'/compatibility-before.json',json_encode(['id'=>$business->id,'owner_id'=>$actor->id,'version'=>$business->version_no,'state'=>$state,'state_sha256'=>App\Services\OpportunityCanonicalValue::hash($state),'synthetic_payload_prepared_via_existing_save'=>$syntheticReplacement,'legacy_ciphertext_preserved_privately'=>$syntheticReplacement,'revision_hashes'=>DB::table('existing_business_revisions')->where('business_id',$business->id)->orderBy('version_no')->pluck('sha256')->all()],JSON_THROW_ON_ERROR)); echo json_encode(['existing_draft'=>$business->id,'version'=>$business->version_no,'new_businesses'=>0,'workflow_transitions'=>0]).PHP_EOL;