]> git.mjollnir.org Git - moodle.git/commitdiff
mod/chat - fix another instance where empty $USER->lastIP was affecting us
authormartinlanghoff <martinlanghoff>
Tue, 2 May 2006 05:20:35 +0000 (05:20 +0000)
committermartinlanghoff <martinlanghoff>
Tue, 2 May 2006 05:20:35 +0000 (05:20 +0000)
The original commit was:

mod/chat - use empty value instead of erroring out if $USER->lastIP and getremoteaddr() don't yield any interesting value

Sometimes we can't get any useful IP for the user -- and this may even be a
valid situation. So fudge an empty value -- the DB needs it as the IP field
is NOT NULL.

mod/chat/lib.php

index 31382401fa9a76f4fd9aba1b15aaf8770021ed4d..8a4051b07a9cbbea278e970290f5bd942072bdd7 100644 (file)
@@ -416,6 +416,17 @@ function chat_login_user($chatid, $version, $groupid, $course) {
         $chatuser->course   = $course->id; //caching - needed for current_language too
         $chatuser->lang     = current_language(); //caching - to resource intensive to find out later
 
+        // Sometimes $USER->lastIP is not setup properly
+        // during login. Update with current value if possible
+        // or provide a dummy value for the db
+        if (empty($chatuser->ip)) {
+            $chatuser->ip = getremoteaddr();
+            if (empty($chatuser->ip)) {
+                $chatuser->ip = '';
+            }
+        }
+
+
         if (!insert_record('chat_users', $chatuser)) {
             return false;
         }