Skip to content

Commit f910e87

Browse files
author
Peter
committed
MDL-66021 backup: Clear course if required before restore
1 parent 39ef515 commit f910e87

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

backup/controller/restore_controller.class.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,21 @@ public function get_executiontime() {
332332
public function get_plan() {
333333
return $this->plan;
334334
}
335+
/**
336+
* Gets the value for the requested setting
337+
*
338+
* @param string $name
339+
* @param bool $default
340+
* @return mixed
341+
*/
342+
public function get_setting_value($name, $default = false) {
343+
try {
344+
return $this->get_plan()->get_setting($name)->get_value();
345+
} catch (Exception $e) {
346+
debugging('Failed to find the setting: '.$name, DEBUG_DEVELOPER);
347+
return $default;
348+
}
349+
}
335350

336351
public function get_info() {
337352
return $this->info;
@@ -341,6 +356,14 @@ public function execute_plan() {
341356
// Basic/initial prevention against time/memory limits
342357
core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted
343358
raise_memory_limit(MEMORY_EXTRA);
359+
360+
// Do course cleanup precheck, if required. This was originally in restore_ui. Moved to handle async backup/restore.
361+
if ($this->get_target() == backup::TARGET_CURRENT_DELETING || $this->get_target() == backup::TARGET_EXISTING_DELETING) {
362+
$options = array();
363+
$options['keep_roles_and_enrolments'] = $this->get_setting_value('keep_roles_and_enrolments');
364+
$options['keep_groups_and_groupings'] = $this->get_setting_value('keep_groups_and_groupings');
365+
restore_dbops::delete_course_content($this->get_courseid(), $options);
366+
}
344367
// If this is not a course restore or single activity restore (e.g. duplicate), inform the plan we are not
345368
// including all the activities for sure. This will affect any
346369
// task/step executed conditionally to stop processing information

backup/util/ui/restore_ui.class.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,7 @@ public function execute() {
215215
if ($this->stage->get_stage() < self::STAGE_PROCESS) {
216216
throw new restore_ui_exception('restoreuifinalisedbeforeexecute');
217217
}
218-
if ($this->controller->get_target() == backup::TARGET_CURRENT_DELETING || $this->controller->get_target() == backup::TARGET_EXISTING_DELETING) {
219-
$options = array();
220-
$options['keep_roles_and_enrolments'] = $this->get_setting_value('keep_roles_and_enrolments');
221-
$options['keep_groups_and_groupings'] = $this->get_setting_value('keep_groups_and_groupings');
222-
restore_dbops::delete_course_content($this->controller->get_courseid(), $options);
223-
}
218+
224219
$this->controller->execute_plan();
225220
$this->progress = self::PROGRESS_EXECUTED;
226221
$this->stage = new restore_ui_stage_complete($this, $this->stage->get_params(), $this->controller->get_results());

0 commit comments

Comments
 (0)