From 7fedee30bfa8cfa41809d53a7be7c69d0e82b4b3 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Mon, 3 Apr 2023 08:20:45 +0000 Subject: [PATCH] use correct variable, fixes #2504 Closes #2504 Merge request studip/studip!1693 --- lib/classes/StudipLog.class.php | 58 ++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/lib/classes/StudipLog.class.php b/lib/classes/StudipLog.class.php index 54d513dcd49..d214aaaa535 100644 --- a/lib/classes/StudipLog.class.php +++ b/lib/classes/StudipLog.class.php @@ -48,38 +48,52 @@ class StudipLog * @param mixed $dbg_info Debug information to add to the event * @param mixed $user_id Provide null for the current user id **/ - public static function log($action_name, $affected = null, - $coaffected = null, $info = null, $dbg_info = null, $user_id = null) - { + public static function log( + $action_name, + $affected = null, + $coaffected = null, + $info = null, + $dbg_info = null, + $user_id = null + ) { if (!Config::get()->LOG_ENABLE) { - return; + return false; + } + + // automagically set current user as agent + if (!$user_id) { + $user_id = $GLOBALS['user']->id; } $log_action = LogAction::findOneByName($action_name); if (!$log_action) { // Action doesn't exist -> LOG_ERROR - $debug = sprintf('StudipLog::log(%s,%s,%s,%s,%s) for user %s', - $log_action->name, $affected, $coaffected, $info, - $dbg_info, $user_id); + $debug = sprintf( + 'StudipLog::log(%s,%s,%s,%s,%s) for user %s', + $action_name, + $affected, + $coaffected, + $info, + $dbg_info, + $user_id + ); self::log('LOG_ERROR', null, null, null, $debug); return false; } - if ($log_action->isActive()) { - // automagically set current user as agent - if (!$user_id) { - $user_id = $GLOBALS['auth']->auth['uid']; - } - $log_event = new LogEvent(); - $log_event->user_id = $user_id; - $log_event->action_id = $log_action->getId(); - $log_event->affected_range_id = $affected; - $log_event->coaffected_range_id = $coaffected; - $log_event->info = $info; - $log_event->dbg_info = $dbg_info; - $log_event->store(); - return true; + + if (!$log_action->isActive()) { + return false; } - return false; + + $log_event = new LogEvent(); + $log_event->user_id = $user_id; + $log_event->action_id = $log_action->getId(); + $log_event->affected_range_id = $affected; + $log_event->coaffected_range_id = $coaffected; + $log_event->info = $info; + $log_event->dbg_info = $dbg_info; + $log_event->store(); + return true; } /** -- GitLab