summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2023-11-14 11:48:47 +0100
committerSimon Rettberg2023-11-14 11:48:47 +0100
commit9176cde14708dfd6844eddba737191abcf4e270a (patch)
tree36e1e4bcaeb8747f025657cc75fb0bd1819c28a5
parent[sysconfig] Make title field required via HTML (diff)
downloadslx-admin-9176cde14708dfd6844eddba737191abcf4e270a.tar.gz
slx-admin-9176cde14708dfd6844eddba737191abcf4e270a.tar.xz
slx-admin-9176cde14708dfd6844eddba737191abcf4e270a.zip
[inv/Eventlog] Fix storing last warning/failure ID for notifications
-rw-r--r--inc/eventlog.inc.php34
1 files changed, 20 insertions, 14 deletions
diff --git a/inc/eventlog.inc.php b/inc/eventlog.inc.php
index 5d6bb745..93ca5c5c 100644
--- a/inc/eventlog.inc.php
+++ b/inc/eventlog.inc.php
@@ -10,7 +10,7 @@
class EventLog
{
- private static function log($type, $message, $details)
+ private static function log(string $type, string $message, string $details, bool $markWarning): void
{
if (!Module::isAvailable('eventlog')) {
// Eventlog module does not exist; the eventlog table might not exist, so bail out
@@ -26,34 +26,40 @@ class EventLog
$data = [
'type' => $type,
'message' => $message,
- 'details' => $details
+ 'details' => $details,
];
- Database::exec("INSERT INTO eventlog (dateline, logtypeid, description, extra)"
- . " VALUES (UNIX_TIMESTAMP(), :type, :message, :details)", $data, true);
+ if (Database::exec("INSERT INTO eventlog (dateline, logtypeid, description, extra)"
+ . " VALUES (UNIX_TIMESTAMP(), :type, :message, :details)", $data, true) === false) {
+ error_log($message);
+ } else {
+ // Insert ok, see if we should update the "latest warning" id
+ $id = Database::lastInsertId();
+ if ($id !== 0 && $markWarning) {
+ Property::setLastWarningId($id);
+ }
+ }
self::applyFilterRules('#serverlog', $data);
}
- public static function failure($message, $details = '')
+ public static function failure(string $message, string $details = ''): void
{
- self::log('failure', $message, $details);
- Property::setLastWarningId(Database::lastInsertId());
+ self::log('failure', $message, $details, true);
}
- public static function warning($message, $details = '')
+ public static function warning(string $message, string $details = ''): void
{
- self::log('warning', $message, $details);
- Property::setLastWarningId(Database::lastInsertId());
+ self::log('warning', $message, $details, true);
}
- public static function info($message, $details = '')
+ public static function info(string $message, string $details = ''): void
{
- self::log('info', $message, $details);
+ self::log('info', $message, $details, false);
}
/**
* DELETE ENTIRE EVENT LOG!
*/
- public static function clear()
+ public static function clear(): void
{
if (!Module::isAvailable('eventlog'))
return;
@@ -64,7 +70,7 @@ class EventLog
* @param string $type the event. Will either be client state like ~poweron, ~runstate etc. or a client log type
* @param array $data A structured array containing event specific data that can be matched.
*/
- public static function applyFilterRules(string $type, array $data)
+ public static function applyFilterRules(string $type, array $data): void
{
if (!Module::isAvailable('eventlog'))
return;