Skip to content

Commit

Permalink
MDL-24962 backup - clean plan/settings circular refs on restore
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Nov 15, 2010
1 parent 32df07b commit 8231bb1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
21 changes: 20 additions & 1 deletion backup/controller/restore_controller.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ public function __construct($tempdir, $courseid, $interactive, $mode, $userid, $
}
}

/**
* Clean structures used by the restore_controller
*
* This method clean various structures used by the restore_controller,
* destroying them in an ordered way, so their memory will be gc properly
* by PHP (mainly circular references).
*
* Note that, while it's not mandatory to execute this method, it's highly
* recommended to do so, specially in scripts performing multiple operations
* (like the automated backups) or the system will run out of memory after
* a few dozens of backups)
*/
public function destroy() {
// Only need to destroy circulars under the plan. Delegate to it.
$this->plan->destroy();
}

public function finish_ui() {
if ($this->status != backup::STATUS_SETTING_UI) {
throw new restore_controller_exception('cannot_finish_ui_if_not_setting_ui');
Expand All @@ -157,7 +174,9 @@ public function set_status($status) {
// containing all the steps will be sent to DB. 100% (monster) useless.
if ($status == backup::STATUS_AWAITING || $status == backup::STATUS_NEED_PRECHECK) {
$this->save_controller();
$this->logger = self::load_controller($this->restoreid)->logger; // wakeup loggers
$tbc = self::load_controller($this->restoreid);
$this->logger = $tbc->logger; // wakeup loggers
$tbc->destroy(); // Clean temp controller structures
}
}

Expand Down
10 changes: 10 additions & 0 deletions backup/util/plan/restore_plan.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public function __construct($controller) {
parent::__construct('restore_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() {
restore_plan_builder::build_plan($this->controller); // We are moodle2 always, go straight to builder
$this->built = true;
Expand Down

0 comments on commit 8231bb1

Please sign in to comment.