| Server IP : 213.255.246.8 / Your IP : 216.73.217.138 Web Server : Apache System : Linux dublin.stapolin.com 5.14.0-362.18.1.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Jan 29 07:05:48 EST 2024 x86_64 User : stapolin ( 1019) PHP Version : 8.4.24 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/stapolin/public_html/tracking.stapolin.com/cron/ |
Upload File : |
<?php
declare(strict_types=1);
require_once __DIR__ . '/../includes/cron.php';
run_cron_job('build_daily_aggregates', function (): string {
$since = gmdate('Y-m-d', time() - 90 * 86400);
db_execute('DELETE FROM daily_aggregates WHERE aggregate_date >= ?', 's', [$since]);
$inserted = 0;
$stmt = db_execute(
'INSERT INTO daily_aggregates (website_id, aggregate_date, metric_key, dimension_key, dimension_value, metric_value)
SELECT website_id, DATE(entered_at), ?, "", "", COUNT(*)
FROM page_views WHERE DATE(entered_at) >= ? GROUP BY website_id, DATE(entered_at)',
'ss',
['page_views', $since]
);
$inserted += $stmt->affected_rows;
$stmt = db_execute(
'INSERT INTO daily_aggregates (website_id, aggregate_date, metric_key, dimension_key, dimension_value, metric_value)
SELECT website_id, DATE(occurred_at), ?, "", "", COUNT(*)
FROM events WHERE DATE(occurred_at) >= ? GROUP BY website_id, DATE(occurred_at)',
'ss',
['events', $since]
);
$inserted += $stmt->affected_rows;
$stmt = db_execute(
'INSERT INTO daily_aggregates (website_id, aggregate_date, metric_key, dimension_key, dimension_value, metric_value)
SELECT website_id, DATE(started_at), ?, "", "", COUNT(*)
FROM sessions WHERE DATE(started_at) >= ? GROUP BY website_id, DATE(started_at)',
'ss',
['sessions', $since]
);
$inserted += $stmt->affected_rows;
return $inserted . ' daily aggregates written';
});