From 8f0ce3ca17ab5b993ac375b0dd7ffbf8bbd51a98 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Tue, 13 Aug 2013 14:25:13 +0100 Subject: [PATCH] MDL-41163 Restore: Large course restore timeout on schema page --- backup/util/ui/restore_ui_stage.class.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/backup/util/ui/restore_ui_stage.class.php b/backup/util/ui/restore_ui_stage.class.php index a7464bf49ae..a884fc721ca 100644 --- a/backup/util/ui/restore_ui_stage.class.php +++ b/backup/util/ui/restore_ui_stage.class.php @@ -475,8 +475,9 @@ class restore_ui_stage_schema extends restore_ui_stage { if ($this->stageform === null) { $form = new restore_schema_form($this, $PAGE->url); $tasks = $this->ui->get_tasks(); - $content = ''; $courseheading = false; + + $allsettings = array(); foreach ($tasks as $task) { if (!($task instanceof restore_root_task)) { if (!$courseheading) { @@ -484,13 +485,11 @@ class restore_ui_stage_schema extends restore_ui_stage { $form->add_heading('coursesettings', get_string('coursesettings', 'backup')); $courseheading = true; } - // First add each setting + // Put each setting into an array of settings to add. Adding + // a setting individually is a very slow operation, so we add + // them all in a batch later on. foreach ($task->get_settings() as $setting) { - $form->add_setting($setting, $task); - } - // The add all the dependencies - foreach ($task->get_settings() as $setting) { - $form->add_dependencies($setting); + $allsettings[] = array($setting, $task); } } else if ($this->ui->enforce_changed_dependencies()) { // Only show these settings if dependencies changed them. @@ -505,6 +504,15 @@ class restore_ui_stage_schema extends restore_ui_stage { } } } + + // Actually add all the settings that we put in the array. + $form->add_settings($allsettings); + + // Add the dependencies for all the settings. + foreach ($allsettings as $settingtask) { + $form->add_dependencies($settingtask[0]); + } + $this->stageform = $form; } return $this->stageform;