/** * Creates the backup_schema_form instance for this stage * * @return backup_schema_form */ protected function initialise_stage_form() { global $PAGE; if ($this->stageform === null) { $form = new restore_schema_form($this, $PAGE->url); $tasks = $this->ui->get_tasks(); $content = ''; $courseheading = false; foreach ($tasks as $task) { if (!$task instanceof restore_root_task) { if (!$courseheading) { // If we havn't already display a course heading to group nicely $form->add_heading('coursesettings', get_string('coursesettings', 'backup')); $courseheading = true; } // First add each setting 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); } } else { if ($this->ui->enforce_changed_dependencies()) { // Only show these settings if dependencies changed them. // Add a root settings heading to group nicely $form->add_heading('rootsettings', get_string('rootsettings', 'backup')); // Iterate all settings and add them to the form as a fixed // setting. We only want schema settings to be editable foreach ($task->get_settings() as $setting) { if ($setting->get_name() != 'filename') { $form->add_fixed_setting($setting, $task); } } } } } $this->stageform = $form; } return $this->stageform; }
/** * Creates the backup_schema_form instance for this stage * * @return backup_schema_form */ protected function initialise_stage_form() { global $PAGE; if ($this->stageform === null) { $form = new restore_schema_form($this, $PAGE->url); $tasks = $this->ui->get_tasks(); $courseheading = false; // Track progress through each stage. $progress = $this->ui->get_progress_reporter(); $progress->start_progress('Initialise schema stage form', 3); $progress->start_progress('', count($tasks)); $done = 1; $allsettings = array(); foreach ($tasks as $task) { if (!$task instanceof restore_root_task) { if (!$courseheading) { // If we haven't already display a course heading to group nicely. $form->add_heading('coursesettings', get_string('coursesettings', 'backup')); $courseheading = true; } // 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) { $allsettings[] = array($setting, $task); } } else { if ($this->ui->enforce_changed_dependencies()) { // Only show these settings if dependencies changed them. // Add a root settings heading to group nicely. $form->add_heading('rootsettings', get_string('rootsettings', 'backup')); // Iterate all settings and add them to the form as a fixed // setting. We only want schema settings to be editable. foreach ($task->get_settings() as $setting) { if ($setting->get_name() != 'filename') { $form->add_fixed_setting($setting, $task); } } } } // Update progress. $progress->progress($done++); } $progress->end_progress(); // Add settings for tasks in batches of up to 1000. Adding settings // in larger batches improves performance, but if it takes too long, // we won't be able to update the progress bar so the backup might. // time out. 1000 is chosen to balance this. $numsettings = count($allsettings); $progress->start_progress('', ceil($numsettings / self::MAX_SETTINGS_BATCH)); $start = 0; $done = 1; while ($start < $numsettings) { $length = min(self::MAX_SETTINGS_BATCH, $numsettings - $start); $form->add_settings(array_slice($allsettings, $start, $length)); $start += $length; $progress->progress($done++); } $progress->end_progress(); // Add the dependencies for all the settings. $progress->start_progress('', count($allsettings)); $done = 1; foreach ($allsettings as $settingtask) { $form->add_dependencies($settingtask[0]); $progress->progress($done++); } $progress->end_progress(); $progress->end_progress(); $this->stageform = $form; } return $this->stageform; }
/** * Creates the backup_schema_form instance for this stage * * @return backup_schema_form */ protected function initialise_stage_form() { global $PAGE; if ($this->stageform === null) { $form = new restore_schema_form($this, $PAGE->url); $tasks = $this->ui->get_tasks(); $courseheading = false; $allsettings = array(); foreach ($tasks as $task) { if (!$task instanceof restore_root_task) { if (!$courseheading) { // If we havn't already display a course heading to group nicely $form->add_heading('coursesettings', get_string('coursesettings', 'backup')); $courseheading = true; } // 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) { $allsettings[] = array($setting, $task); } } else { if ($this->ui->enforce_changed_dependencies()) { // Only show these settings if dependencies changed them. // Add a root settings heading to group nicely $form->add_heading('rootsettings', get_string('rootsettings', 'backup')); // Iterate all settings and add them to the form as a fixed // setting. We only want schema settings to be editable foreach ($task->get_settings() as $setting) { if ($setting->get_name() != 'filename') { $form->add_fixed_setting($setting, $task); } } } } } // 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; }