From d2a4d34d29c205869189612b46a93ba10864ab97 Mon Sep 17 00:00:00 2001 From: lietuvis10 <50807912+lietuvis10@users.noreply.github.com> Date: Mon, 27 Oct 2025 17:16:55 +0200 Subject: [PATCH] Create ajax_croppers.php Ajax for cropper population info in step 3 installation. --- install/ajax_croppers.php | 88 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 install/ajax_croppers.php diff --git a/install/ajax_croppers.php b/install/ajax_croppers.php new file mode 100644 index 00000000..5d2e9d28 --- /dev/null +++ b/install/ajax_croppers.php @@ -0,0 +1,88 @@ + 0) { @ob_end_flush(); } +ob_implicit_flush(true); + +// If any installer/session code might lock the session, release it +if (session_status() === PHP_SESSION_ACTIVE) { + @session_write_close(); +} + +function sse_send(array $payload) { + echo "data: " . json_encode($payload, JSON_UNESCAPED_SLASHES) . "\n\n"; + @flush(); + @ob_flush(); +} + +function sse_ping() { + // Comment line per SSE spec, keeps connection alive + echo ":\n\n"; + @flush(); + @ob_flush(); +} + +global $database; + +// 1) Count total croppers +try { + $total = $database->TotalCroppers(); +} catch (Throwable $e) { + sse_send(['pct'=>0,'done'=>0,'total'=>0,'msg'=>'Count failed: '.$e->getMessage()]); + exit; +} + +sse_send(['pct'=>0,'done'=>0,'total'=>$total,'msg'=>"Starting croppers build (found $total tiles)…"]); + +// 2) Build with live reporter (pings to keep proxies happy) +$lastPing = time(); +$reporter = function($done, $target, $pct) use (&$lastPing) { + sse_send(['pct'=>(int)$pct,'done'=>(int)$done,'total'=>(int)$target]); + // send keep-alive every ~10s + if (time() - $lastPing >= 10) { + sse_ping(); + $lastPing = time(); + } + if (connection_aborted()) { exit; } // client left +}; + +// Run it (fresh world => truncateFirst=true; big batch on dedicated server) +$out = $database->populateCroppers($total, true, 20000, $reporter); + +if (!empty($out['ok'])) { + sse_send([ + 'pct'=>100, + 'done'=>(int)$out['processed'], + 'total'=>(int)$out['target'], + 'msg'=>'Done building croppers.' + ]); +} else { + sse_send([ + 'pct'=>0, + 'done'=>0, + 'total'=>(int)$total, + 'msg'=>'Error: '.($out['msg'] ?? 'unknown') + ]); +} +exit;