MDL-24962 backup - circular refs destroyer for backup settings
authorEloy Lafuente <stronk7@moodle.org>
Mon, 15 Nov 2010 07:16:24 +0000 (07:16 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Mon, 15 Nov 2010 07:16:24 +0000 (07:16 +0000)
backup/util/settings/base_setting.class.php
backup/util/settings/setting_dependency.class.php
backup/util/ui/backup_ui_setting.class.php

index b2cce66..82e6eb1 100644 (file)
@@ -113,6 +113,26 @@ abstract class base_setting {
         $this->uisetting = new base_setting_ui($this);
     }
 
+    /**
+     * Destroy all circular references. It helps PHP 5.2 a lot!
+     */
+    public function destroy() {
+        // Before reseting anything, call destroy recursively
+        foreach ($this->dependencies as $dependency) {
+            $dependency->destroy();
+        }
+        foreach ($this->dependenton as $dependenton) {
+            $dependenton->destroy();
+        }
+        if ($this->uisetting) {
+            $this->uisetting->destroy();
+        }
+        // Everything has been destroyed recursively, now we can reset safely
+        $this->dependencies = array();
+        $this->dependenton = array();
+        $this->uisetting = null;
+    }
+
     public function get_name() {
         return $this->name;
     }
index 8e04b4e..37099a8 100644 (file)
@@ -77,6 +77,16 @@ abstract class setting_dependency {
         $this->defaultvalue = $defaultvalue;
         $this->lastvalue = $dependentsetting->get_value();
     }
+
+    /**
+     * Destroy all circular references. It helps PHP 5.2 a lot!
+     */
+    public function destroy() {
+        // No need to destroy anything recursively here, direct reset
+        $this->setting = null;
+        $this->dependentsetting = null;
+    }
+
     /**
      * Processes a change is setting called by the primary setting
      * @param int $changetype
@@ -442,4 +452,4 @@ class setting_dependency_disabledif_empty extends setting_dependency_disabledif_
         // Else return based upon the dependent settings status
         return ($this->dependentsetting->get_status() !== base_setting::NOT_LOCKED);
     }
-}
\ No newline at end of file
+}
index 5391f2a..3db20a1 100644 (file)
@@ -73,6 +73,15 @@ class base_setting_ui {
     public function __construct(base_setting $setting) {
         $this->setting = $setting;
     }
+
+    /**
+     * Destroy all circular references. It helps PHP 5.2 a lot!
+     */
+    public function destroy() {
+        // No need to destroy anything recursively here, direct reset
+        $this->setting = null;
+    }
+
     /**
      * Gets the name of this item including its prefix
      * @return string
@@ -581,4 +590,4 @@ class backup_setting_ui_dateselector extends backup_setting_ui_text {
 }
 
 class base_setting_ui_exception extends base_setting_exception {}
-class backup_setting_ui_exception extends base_setting_ui_exception {};
\ No newline at end of file
+class backup_setting_ui_exception extends base_setting_ui_exception {};