]> git.mjollnir.org Git - moodle.git/commitdiff
datalib: add_to_log() fix a bug and better error handling
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:22:37 +0000 (07:22 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:22:37 +0000 (07:22 +0000)
All the $db->Execute calls now do proper err handling, and send their
message to debugging().

lib/datalib.php

index 8dbb743c40c3fdf982262dac4fc22748f928d77d..5e5e4d8e91d0b596009f96e85e838056cca051dd 100644 (file)
@@ -1630,20 +1630,29 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user
 /// Store lastaccess times for the current user, do not use in cron and other commandline scripts
 /// only update the lastaccess/timeaccess fields only once every 60s
     if (!empty($USER->id) && ($userid == $USER->id) && !defined('FULLME')) {
-        $db->Execute('UPDATE '. $CFG->prefix .'user
-                         SET lastip=\''. $REMOTE_ADDR .'\', lastaccess=\''. $timenow .'\'
-                       WHERE id = \''. $userid .'\' AND '.$timenow.' - lastaccess > 60');
+        $res = $db->Execute('UPDATE '. $CFG->prefix .'user
+                                SET lastip=\''. $REMOTE_ADDR .'\', lastaccess=\''. $timenow .'\'
+                             WHERE id = \''. $userid .'\' AND '.$timenow.' - lastaccess > 60');
+        if (!$res) {
+            debugging('<p>Error: Could not insert a new entry to the Moodle log</p>');  // Don't throw an error
+        }
         if ($courseid != SITEID && !empty($courseid)) {
             if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++;};
 
             if ($ulid = get_field('user_lastaccess', 'id', 'userid', $userid, 'courseid', $courseid)) {
-                $db->Execute("UPDATE {$CFG->prefix}user_lastaccess
-                              SET timeaccess=$timenow
-                              WHERE id = $ulid AND $timenow - timeaccess > 60");
+                $res = $db->Execute("UPDATE {$CFG->prefix}user_lastaccess
+                                        SET timeaccess=$timenow
+                                     WHERE id = $ulid AND $timenow - timeaccess > 60");
+                if (!$res) {
+                    debugging('Error: Could not insert a new entry to the Moodle log');  // Don't throw an error
+                }
             } else {
-                $db->Execute("INSERT INTO {$CFG->prefix}user_lastaccess
-                              ('userid', 'courseid', 'timeaccess')
-                              VALUES ($userid, $courseid, $timenow)");
+                $res = $db->Execute("INSERT INTO {$CFG->prefix}user_lastaccess
+                                            ( userid,  courseid,  timeaccess)
+                                     VALUES ($userid, $courseid, $timenow)");
+                if (!$res) {
+                    debugging('Error: Could not insert a new entry to the Moodle log');  // Don't throw an error
+                }
             }
             if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++;};
         }