// scope: P2 + P3 ingested rows $p2p3 = function($q){ $q->where('source','like','% P2 %')->orWhere('source','like','% P3 %'); }; // 1) revert my earlier qa_status mistake (draft does NOT live in qa_status) $rev = DB::table('questions')->where('qa_status','unreviewed')->where($p2p3)->update(['qa_status'=>'ai_generated']); // 2) status_id rule: image-pending -> 4 (Draft); no image -> 6 (AGS Tutor Input = "AI generated") $d = DB::table('questions')->where($p2p3)->whereNotNull('question_image')->update(['status_id'=>4]); $g = DB::table('questions')->where($p2p3)->whereNull('question_image')->update(['status_id'=>6]); echo "reverted_qa=$rev set_draft(4)=$d set_aigen(6)=$g\n"; foreach (DB::table('questions')->select('status_id', DB::raw('count(*) c'))->where($p2p3)->groupBy('status_id')->get() as $r) echo " P2P3 status_id=".$r->status_id." -> ".$r->c."\n";