MDL-24962 backup - circular refs destroyer for backup plan

This commit is contained in:
Eloy Lafuente 2010-11-15 07:15:48 +00:00
parent 41dcc2a508
commit 4f6ed68c1c
4 changed files with 52 additions and 1 deletions

View 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;

View 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();
}
}

View 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');

View 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;
}