print_error('unknownbackuptype'); } // Backup of large courses requires extra memory. Use the amount configured // in admin settings. raise_memory_limit(MEMORY_EXTRA); if (!($bc = backup_ui::load_controller($backupid))) { $bc = new backup_controller($type, $id, backup::FORMAT_MOODLE, backup::INTERACTIVE_YES, backup::MODE_GENERAL, $USER->id); } $backup = new backup_ui($bc); $PAGE->set_title($heading); $PAGE->set_heading($heading); $renderer = $PAGE->get_renderer('core', 'backup'); echo $OUTPUT->header(); // Prepare a progress bar which can display optionally during long-running // operations while setting up the UI. $slowprogress = new \core\progress\display_if_slow(get_string('preparingui', 'backup')); $previous = optional_param('previous', false, PARAM_BOOL); if ($backup->get_stage() == backup_ui::STAGE_SCHEMA && !$previous) { // After schema stage, we are probably going to get to the confirmation stage, // The confirmation stage has 2 sets of progress, so this is needed to prevent // it showing 2 progress bars. $twobars = true; $slowprogress->start_progress('', 2); } else { $twobars = false; } $backup->get_controller()->set_progress($slowprogress); $backup->process(); if ($backup->enforce_changed_dependencies()) { debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER); }
$courseshortname = $SITE->shortname; } else { $coursefullname = $course->fullname; $courseshortname = $course->shortname; } // Show page header. $PAGE->set_title($courseshortname . ': ' . get_string('restore')); $PAGE->set_heading($coursefullname); $renderer = $PAGE->get_renderer('core', 'backup'); if (empty($cancel)) { // Do not print the header if user cancelled the process, as we are going to redirect the user. echo $OUTPUT->header(); } // Prepare a progress bar which can display optionally during long-running // operations while setting up the UI. $slowprogress = new \core\progress\display_if_slow(get_string('preparingui', 'backup')); // Overall, allow 10 units of progress. $slowprogress->start_progress('', 10); // This progress section counts for loading the restore controller. $slowprogress->start_progress('', 1, 1); // Restore of large courses requires extra memory. Use the amount configured // in admin settings. raise_memory_limit(MEMORY_EXTRA); if ($stage & restore_ui::STAGE_CONFIRM + restore_ui::STAGE_DESTINATION) { $restore = restore_ui::engage_independent_stage($stage, $contextid); } else { $restoreid = optional_param('restore', false, PARAM_ALPHANUM); $rc = restore_ui::load_controller($restoreid); if (!$rc) { $restore = restore_ui::engage_independent_stage($stage / 2, $contextid); if ($restore->process()) {
/** * Process the data from a form submission. * * @param array $data * @return array of warnings */ public function process($data) { $warnings = array(); $fields = $this->definition(); // Avoiding execution timeouts when updating // a large amount of grades. $progress = 0; $progressbar = new \core\progress\display_if_slow(); $progressbar->start_html(); $progressbar->start_progress(get_string('savegrades', 'gradereport_singleview'), count((array) $data) - 1); $changecount = array(); foreach ($data as $varname => $throw) { $progressbar->progress($progress); $progress++; if (preg_match("/(\\w+)_(\\d+)_(\\d+)/", $varname, $matches)) { $itemid = $matches[2]; $userid = $matches[3]; } else { continue; } $gradeitem = grade_item::fetch(array('id' => $itemid, 'courseid' => $this->courseid)); if (preg_match('/^old[oe]{1}/', $varname)) { $elementname = preg_replace('/^old/', '', $varname); if (!isset($data->{$elementname})) { // Decrease the progress because we've increased the // size of the array we are iterating through. $progress--; $data->{$elementname} = false; } } if (!in_array($matches[1], $fields)) { continue; } if (!$gradeitem) { continue; } $grade = $this->fetch_grade_or_default($gradeitem, $userid); $classname = '\\gradereport_singleview\\local\\ui\\' . $matches[1]; $element = new $classname($grade); $name = $element->get_name(); $oldname = "old{$name}"; $posted = $data->{$name}; $format = $element->determine_format(); if ($format->is_textbox() and trim($data->{$name}) === '') { $data->{$name} = null; } // Same value; skip. if (isset($data->{$oldname}) && $data->{$oldname} == $posted) { continue; } $msg = $element->set($posted); // Optional type. if (!empty($msg)) { $warnings[] = $msg; } if (preg_match('/_(\\d+)_(\\d+)/', $varname, $matchelement)) { $changecount[$matchelement[0]] = 1; } } // Some post-processing. $eventdata = new stdClass(); $eventdata->warnings = $warnings; $eventdata->post_data = $data; $eventdata->instance = $this; $eventdata->changecount = $changecount; $progressbar->end_html(); return $eventdata; }