<?php
declare(strict_types=1);require __DIR__.'/bootstrap.php';$check($lane==='B','Approved only B');$check(!is_file($runtime.'/recovery-journal.json'),'Recovery no replay');$rows=array_map(static function($s){return json_decode($s,true);},file($runtime.'/private-wire.jsonl',FILE_IGNORE_NEW_LINES));$pick=static function($scenario)use($rows,$check){$r=array_values(array_filter($rows,static function($r)use($scenario){return $r['scenario']===$scenario;}));$check(count($r)===1,'Exactly one original wire');return $r[0];};$added=$pick('PILOT_GP_ADD_TERMINAL_PRINTER_ADD');$edited=$pick('PILOT_GP_EDIT_TERMINAL_PRINTER_EDIT');$a=array_values(array_filter($added['original']['printer'],static function($r){return (int)$r['store_id']===2147001112;}))[0];$e=array_values(array_filter($edited['original']['printer'],static function($r){return (int)$r['store_id']===2147001112;}))[0];$before=$own();$current=$read('SELECT * FROM yoshop_printer WHERE printer_id=? AND store_id=2147001112 AND printer_name=?',[$e['printer_id'],'CDXGP11E42A_terminal_edited']);$check($current===[$e],'Exact full edited row SHA and bytes');$expected=$e;foreach(['printer_name','printer_config','sort'] as $k)$expected[$k]=$a[$k];$journal=['lane'=>$lane,'before'=>$before,'old_row_sha256'=>hash('sha256',json_encode($e,JSON_PRESERVE_ZERO_FRACTION)),'new_values'=>array_intersect_key($a,array_flip(['printer_name','printer_config','sort'])),'committed'=>false];$persist('recovery-journal.json',$journal);$db->beginTransaction();try{$s=$db->prepare('UPDATE yoshop_printer SET printer_name=?,printer_config=?,sort=? WHERE printer_id=? AND store_id=2147001112 AND printer_name=?');$s->execute([$a['printer_name'],$a['printer_config'],$a['sort'],$e['printer_id'],$e['printer_name']]);$check($s->rowCount()===1,'One exact approved Printer recovery');$db->commit();$journal['committed']=true;$journal['after']=$own();$after=$read('SELECT * FROM yoshop_printer WHERE printer_id=? AND store_id=2147001112',[$e['printer_id']]);$check($after===[$expected],'Only three approved fields differ');$exp=$before;foreach($exp['printer'] as &$row)if($row['printer_id']===$e['printer_id'])$row=$expected;unset($row);$check($exp===$journal['after'],'All twenty own tables exact recovery');$persist('recovery-journal.json',$journal);echo json_encode(['lane'=>'B','preparation_UPDATE'=>1,'API_DML'=>0,'printer_id'=>(int)$e['printer_id'],'unchanged_all_other_columns'=>true]),"\n";}catch(Throwable $x){if($db->inTransaction())$db->rollBack();throw $x;}
