]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16285 MDL-16286 Cleanup and document delete function in mnet/peer
authorpeterbulmer <peterbulmer>
Mon, 1 Sep 2008 03:32:52 +0000 (03:32 +0000)
committerpeterbulmer <peterbulmer>
Mon, 1 Sep 2008 03:32:52 +0000 (03:32 +0000)
Author: Peter Bulmer <peter.bulmer@catalyst.net.nz>

mnet/peer.php

index 8ef3baa980a80ede6ea37036071d4859355d1a70..c624a07618c389d4d6852d73375bd07ac1bfac50 100644 (file)
@@ -98,32 +98,42 @@ class mnet_peer {
         }
     }
 
+    /*
+     * Process request to delete mnet peer
+     * This includes deleting current sessions, and rpc2host records.
+     * If the peer has been actively used, we mark the peer as deleted,
+     * otherwise it is actually deleted
+     * @return bool - success
+     */
     function delete() {
         global $DB;
+        $markasdeleted = false;
 
-        if ($this->deleted) return true;
+        if ($this->deleted) {
+            return true;
+        }
 
-        $users = $DB->count_records('user', array('mnethostid'=>$this->id));
-        if ($users > 0) {
-            $this->deleted = 1;
+        // If users have sso'd from this mnet peer, need to retain the peer info
+        $numusers = $DB->count_records('user', array('mnethostid'=>$this->id));
+        if ($numusers > 0) {
+            $markasdeleted = true;
         }
 
-        $actions = $DB->count_records('mnet_log', array('hostid'=>$this->id));
-        if ($actions > 0) {
-            $this->deleted = 1;
+        //If there are items in the log, need to retain peer info
+        $numactions = $DB->count_records('mnet_log', array('hostid'=>$this->id));
+        if ($numactions > 0) {
+            $markasdeleted = true;
         }
 
         $obj = $DB->delete_records('mnet_rpc2host', array('host_id'=>$this->id));
 
         $this->delete_all_sessions();
 
-        // If we don't have any activity records for which the mnet_host table
-        // provides a foreign key, then we can delete the record. Otherwise, we
-        // just mark it as deleted.
-        if (0 == $this->deleted) {
-            $DB->delete_records('mnet_host', array("id"=>$this->id));
+        if ($markasdeleted) {
+            $this->deleted = 1;
+            return $this->commit();
         } else {
-            $this->commit();
+            return $DB->delete_records('mnet_host', array("id"=>$this->id));
         }
     }