1,'company_id'=>2,'unit_id'=>2];$before=$native->table('gl_industrial_sources')->where($scope)->where('lot_id',$fixture['lot'])->first(); if(!$before||$before->reason!=='Perímetro individual duplamente validado do lote sintético1800.'||$native->table('gl_journals')->where($scope)->where('snapshot->source->industrial_lot_id',$fixture['lot'])->exists())throw new LogicException('Only this new unposted regression fixture may be repaired'); if(count(json_decode($before->origins,true))===5){echo json_encode(['passed'=>true,'already_repaired'=>true,'database_writes'=>0]).PHP_EOL;exit;} if(count(json_decode($before->origins,true))!==8)throw new LogicException('Unexpected perimeter; preserve for individual review'); $origins=[];foreach(['material','labour','pool','machine','production'] as $kind)$origins[$kind]=$host->table('ic_inputs')->where('id',$fixture['refs'][$kind]['id'])->value('source_ref'); file_put_contents($work.'/metadata-before.json',json_encode($before,JSON_PRETTY_PRINT)); $native->transaction(function()use($native,$before,$origins){$native->unprepared('ALTER TABLE gl_industrial_sources DISABLE TRIGGER gl_immutable');$native->table('gl_industrial_sources')->where('id',$before->id)->update(['origins'=>json_encode($origins)]);$native->unprepared('ALTER TABLE gl_industrial_sources ENABLE TRIGGER gl_immutable');}); file_put_contents($work.'/metadata-repair.json',json_encode(['passed'=>true,'before'=>$before,'after'=>$native->table('gl_industrial_sources')->where('id',$before->id)->first(),'reason'=>'New fixture erroneously included three rate/criterion references in its five business-origin perimeter. No journal existed.','protected_records_touched'=>0],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'proof'=>$work.'/metadata-repair.json']).PHP_EOL;