MDL-24962 backup - circular refs destroyer for backup plan
authorEloy Lafuente <stronk7@moodle.org>
Mon, 15 Nov 2010 07:15:48 +0000 (07:15 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Mon, 15 Nov 2010 07:15:48 +0000 (07:15 +0000)
backup/util/plan/backup_plan.class.php
backup/util/plan/base_plan.class.php
backup/util/plan/base_step.class.php
backup/util/plan/base_task.class.php

index 1a90b6d..0816621 100644 (file)
@@ -47,6 +47,16 @@ class backup_plan extends base_plan implements loggable {
         parent::__construct('backup_plan');
     }
 
+    /**
+     * Destroy all circular references. It helps PHP 5.2 a lot!
+     */
+    public function destroy() {
+        // No need to destroy anything recursively here, direct reset
+        $this->controller = null;
+        // Delegate to base plan the rest
+        parent::destroy();
+    }
+
     public function build() {
         backup_factory::build_plan($this->controller); // Dispatch to correct format
         $this->built = true;
index 97e8e38..3ed176b 100644 (file)
@@ -148,6 +148,22 @@ abstract class base_plan implements checksumable, executable {
             $task->execute();
         }
     }
+
+    /**
+     * Destroy all circular references. It helps PHP 5.2 a lot!
+     */
+    public function destroy() {
+        // Before reseting anything, call destroy recursively
+        foreach ($this->tasks as $task) {
+            $task->destroy();
+        }
+        foreach ($this->settings as $setting) {
+            $setting->destroy();
+        }
+        // Everything has been destroyed recursively, now we can reset safely
+        $this->tasks = array();
+        $this->settings = array();
+    }
 }
 
 
index 96db85f..e1bc116 100644 (file)
@@ -57,6 +57,14 @@ abstract class base_step implements executable, loggable {
         $this->task = $task;
     }
 
+    /**
+     * Destroy all circular references. It helps PHP 5.2 a lot!
+     */
+    public function destroy() {
+        // No need to destroy anything recursively here, direct reset
+        $this->task = null;
+    }
+
     public function log($message, $level, $a = null, $depth = null, $display = false) {
         if (is_null($this->task)) {
             throw new base_step_exception('not_specified_base_task');
index 341e71d..e38fa89 100644 (file)
@@ -32,7 +32,7 @@ abstract class base_task implements checksumable, executable, loggable {
     protected $name;      // One simple name for identification purposes
     protected $plan;      // Plan this is part of
     protected $settings;  // One array of base_setting elements to define this task
-    protected $steps;     // One array of base_task elements
+    protected $steps;     // One array of base_step elements
 
     protected $built;     // Flag to know if one task has been built
     protected $executed;  // Flag to know if one task has been executed
@@ -159,6 +159,23 @@ abstract class base_task implements checksumable, executable, loggable {
         }
     }
 
+    /**
+     * Destroy all circular references. It helps PHP 5.2 a lot!
+     */
+    public function destroy() {
+        // Before reseting anything, call destroy recursively
+        foreach ($this->steps as $step) {
+            $step->destroy();
+        }
+        foreach ($this->settings as $setting) {
+            $setting->destroy();
+        }
+        // Everything has been destroyed recursively, now we can reset safely
+        $this->steps = array();
+        $this->setting = array();
+        $this->plan = null;
+    }
+
     public function is_checksum_correct($checksum) {
         return $this->calculate_checksum() === $checksum;
     }