]> git.mjollnir.org Git - moodle.git/commitdiff
Added some robustness because on at least two occasions the mnet_localhost_id has...
authormoodler <moodler>
Mon, 13 Aug 2007 09:53:04 +0000 (09:53 +0000)
committermoodler <moodler>
Mon, 13 Aug 2007 09:53:04 +0000 (09:53 +0000)
mnet/environment.php

index 6fc97a2ecfbb328669ca9866214f871e1a0e94cc..f3cfb617bf4fe238e5386385a32604803030cc86 100644 (file)
@@ -30,24 +30,30 @@ class mnet_environment {
 
         // Bootstrap the object data on first load.
         if (empty($CFG->mnet_localhost_id) ) {
-
-            $this->wwwroot    = $CFG->wwwroot;
-            if(empty($_SERVER['SERVER_ADDR'])) {
-                // SERVER_ADDR is only returned by Apache-like webservers
-                $my_hostname = mnet_get_hostname_from_uri($CFG->wwwroot);
-                $my_ip       = gethostbyname($my_hostname);  // Returns unmodified hostname on failure. DOH!
-                if($my_ip == $my_hostname) {
-                    $this->ip_address = 'UNKNOWN';
+            if (!$CFG->mnet_localhost_id = get_config(NULL, 'mnet_localhost_id')) {  // Double-check db
+                $this->wwwroot    = $CFG->wwwroot;
+                if (empty($_SERVER['SERVER_ADDR'])) {
+                    // SERVER_ADDR is only returned by Apache-like webservers
+                    $my_hostname = mnet_get_hostname_from_uri($CFG->wwwroot);
+                    $my_ip       = gethostbyname($my_hostname);  // Returns unmodified hostname on failure. DOH!
+                    if ($my_ip == $my_hostname) {
+                        $this->ip_address = 'UNKNOWN';
+                    } else {
+                        $this->ip_address = $my_ip;
+                    }
                 } else {
-                    $this->ip_address = $my_ip;
+                    $this->ip_address = $_SERVER['SERVER_ADDR'];
                 }
-            } else {
-                $this->ip_address = $_SERVER['SERVER_ADDR'];
-            }
-            $this->id         = insert_record('mnet_host', $this, true);
 
-            set_config('mnet_localhost_id', $this->id);
-            $this->get_keypair();
+                if ($existingrecord = get_record('mnet_host', 'ip_address', $this->ipaddress)) {
+                    $this->id = $existingrecord->id;
+                } else {  // make a new one
+                    $this->id       = insert_record('mnet_host', $this, true);
+                }
+    
+                set_config('mnet_localhost_id', $this->id);
+                $this->get_keypair();
+            }
         } else {
             $hostobject = get_record('mnet_host','id', $CFG->mnet_localhost_id);
             if(is_object($hostobject)) {