summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/hooks/cron.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/statistics/hooks/cron.inc.php')
-rw-r--r--modules-available/statistics/hooks/cron.inc.php18
1 files changed, 18 insertions, 0 deletions
diff --git a/modules-available/statistics/hooks/cron.inc.php b/modules-available/statistics/hooks/cron.inc.php
new file mode 100644
index 00000000..94c65248
--- /dev/null
+++ b/modules-available/statistics/hooks/cron.inc.php
@@ -0,0 +1,18 @@
+<?php
+
+Database::exec("DELETE FROM statistic WHERE (UNIX_TIMESTAMP() - dateline) > 86400 * 190");
+Database::exec("DELETE FROM machine WHERE (UNIX_TIMESTAMP() - lastseen) > 86400 * 365");
+
+function logstats() {
+ $NOW = time();
+ $cutoff = $NOW - 86400 * 30;
+ $online = $NOW - 610;
+ $known = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $cutoff");
+ $on = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $online");
+ $used = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $online AND logintime <> 0");
+ Database::exec("INSERT INTO statistic (dateline, typeid, clientip, username, data) VALUES (:now, '~stats', '', '', :vals)", array(
+ 'now' => $NOW,
+ 'vals' => $known['val'] . '#' . $on['val'] . '#' . $used['val'],
+ ));
+}
+logstats();