You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

59 lines
1.1 KiB

<?php
require_once __DIR__."/../util/dotenv.php";
header("X-Accel-Buffering: no");
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
header('Connection: keep-alive');
ignore_user_abort(true);
function sendEvent(string $event, string $data): void{
if (php_sapi_name() === 'cli')
return;
echo "event: $event\n";
echo "data: $data\n\n";
ob_flush();
flush();
}
require_once __DIR__."/../util/mysql_connect.php";
$conn = new MySQLConnection();
$update_limit = $_ENV["UPDATE_LIMIT_MINUTES"];
$result = $conn->query("
SELECT date
FROM updates
WHERE date > SUBTIME(NOW(), '00:$update_limit:00')
LIMIT 1
");
if ($result->num_rows > 0) {
$response = [
"limit" => $update_limit,
"last" => $result->fetch_assoc()["date"]
];
sendEvent("forbidden", json_encode($response));
die;
}
$conn->query("INSERT INTO updates VALUES ()");
require_once __DIR__."/Tracker.php";
sendEvent("progress", 0);
$tracker = new Tracker();
$tracker->update(function($value){
sendEvent('progress', $value);
});
$conn->query("
UPDATE updates
SET status = 'COMPLETE'
WHERE status = 'RUNNING'
");
sendEvent("done", "");