diff options
author | Simon Rettberg | 2021-06-25 16:21:17 +0200 |
---|---|---|
committer | Simon Rettberg | 2021-06-25 16:21:17 +0200 |
commit | 32f0677dbca9e3347b931c1d0105eb37aa57e90d (patch) | |
tree | ddad4562e7ee8439a24e2462d44614692bb71d14 /modules-available/eventlog/hooks | |
parent | Update .idea (diff) | |
download | slx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.tar.gz slx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.tar.xz slx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.zip |
[eventlog] Add event filtering and notification system
Diffstat (limited to 'modules-available/eventlog/hooks')
-rw-r--r-- | modules-available/eventlog/hooks/cron.inc.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/modules-available/eventlog/hooks/cron.inc.php b/modules-available/eventlog/hooks/cron.inc.php index 180bafd3..bf7ced17 100644 --- a/modules-available/eventlog/hooks/cron.inc.php +++ b/modules-available/eventlog/hooks/cron.inc.php @@ -2,4 +2,28 @@ if (mt_rand(1, 10) === 1) { Database::exec("DELETE FROM eventlog WHERE (UNIX_TIMESTAMP() - 86400 * 190) > dateline"); + // Keep at least 30 events or 7 days wirth of samples (whichever is more) + $types = Database::simpleQuery("SELECT type, Count(*) AS num, Min(dateline) as oldest + FROM `notification_sample` GROUP BY type"); + $cutoff = time() - 86400 * 7; + foreach ($types as $type) { + if ($type['num'] > 30 && $type['oldest'] < $cutoff) { + // This type has more than 30 and the oldest one is older than 7 days + // find out which one takes priority + $thisCutoff = $cutoff; + $find = Database::queryFirst("SELECT dateline FROM notification_sample + WHERE type = :type AND dateline + ORDER BY dateline DESC + LIMIT 29, 1", + ['type' => $type['type']]); + // The 30th entry is older than 7 days? Bump the cutoff dateline back to this date, + // so we keep at least 30 entries + if ($find !== false && $find['dateline'] < $thisCutoff) { + $thisCutoff = $find['dateline']; + } + Database::exec("DELETE FROM notification_sample + WHERE type = :type AND dateline < :dateline", + ['type' => $type['type'], 'dateline' => $thisCutoff]); + } + } } |