make(Illuminate\Contracts\Console\Kernel::class); $kernel->bootstrap(); use Illuminate\Support\Facades\DB; $dryRun = ! in_array('--apply', $argv ?? []); echo "\n=== Fix Patient updated_at in sync_log ===\n"; echo $dryRun ? "Mode: DRY RUN — run with --apply to write to sync_log\n\n" : "Mode: APPLY — writing entries to sync_log...\n\n"; $patients = DB::table('patients')->get(['id', 'first_name', 'last_name', 'updated_at']); $now = now()->format('Y-m-d H:i:s'); $count = 0; foreach ($patients as $patient) { if (empty($patient->updated_at)) { echo " [SKIP] patient#{$patient->id} ({$patient->first_name} {$patient->last_name}) — updated_at is empty\n"; continue; } echo " [" . ($dryRun ? 'DRY' : 'OK ') . "] patient#{$patient->id}" . " ({$patient->first_name} {$patient->last_name})" . " => updated_at: {$patient->updated_at}\n"; if (! $dryRun) { DB::table('sync_log')->insert([ 'datetime' => $now, 'ip' => '127.0.0.1', 'user' => 'fix_script', 'table_name' => 'patients', 'action' => 'updated', 'record_id' => $patient->id, 'changed_data' => json_encode(['updated_at' => $patient->updated_at], JSON_UNESCAPED_UNICODE), ]); } $count++; } echo "\n─────────────────────────────────\n"; echo "Total patients: {$count}\n"; if ($dryRun) { echo "\nTo apply, run:\n php scripts/fix_patient_updated_at.php --apply\n"; } else { echo "\n[OK] {$count} entries written to sync_log.\n"; echo "Now run sync from the Sync page to push changes to the peer system.\n"; } echo "\nDone!\n";