$apply = json_decode(file_get_contents(storage_path('app/_recover_apply.json')), true); $bk=[]; $upd=0; $adv=0; foreach ($apply as $a) { $id=$a['id'] ?? null; if(!$id) continue; $row=DB::table('questions')->find($id); if(!$row) continue; $bk[]=['id'=>$id,'question'=>$row->question,'qa_status'=>$row->qa_status]; $set=['question'=>$a['question'],'updated_at'=>now()]; if(!empty($a['advance'])) { $set['qa_status']='unreviewed'; $adv++; } DB::table('questions')->where('id',$id)->update($set); $upd++; } file_put_contents(storage_path('app/recover_backup_'.date('Ymd_His').'.json'), json_encode($bk, JSON_UNESCAPED_UNICODE)); echo "questions_restored=$upd advanced_to_unreviewed=$adv held_needs_revision=".($upd-$adv)."\n";