<?php
// Run with Windows Task Scheduler. It is self-gated: normal full refresh interval is 6 hours.
// Example: C:\php\php.exe C:\Apache24\htdocs\admin\cron\receiver_match_worker.php
@set_time_limit(300);
require_once __DIR__ . '/../db_bootstrap.php';
if (function_exists('ensure_db')) ensure_db(true);
require_once __DIR__ . '/../receiver_match_refresh_lib.php';
$conn = $GLOBALS['conn'] ?? null;
$out = ['ok'=>false,'message'=>'DB connection unavailable'];
if ($conn instanceof mysqli) {
    $force = in_array('--force', $argv ?? [], true) || in_array('force=1', $argv ?? [], true);
    $out = ua_receiver_match_run_due($conn, 21600, $force);
}
echo json_encode($out, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT) . PHP_EOL;
