MDL-29226 - center align Scale table, in course grades menu (when in RTL mode)(cherry...
[moodle.git] / backup / restore.php
blob04ed41a0f28e8169894f496c3816c090f77dd02a
1 <?php
2 //This script is used to configure and execute the restore proccess.
4 require_once('../config.php');
5 require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
7 $contextid = required_param('contextid', PARAM_INT);
8 $stage = optional_param('stage', restore_ui::STAGE_CONFIRM, PARAM_INT);
10 list($context, $course, $cm) = get_context_info_array($contextid);
12 navigation_node::override_active_url(new moodle_url('/backup/restorefile.php', array('contextid'=>$contextid)));
13 $PAGE->set_url(new moodle_url('/backup/restore.php', array('contextid'=>$contextid)));
14 $PAGE->set_context($context);
15 $PAGE->set_pagelayout('standard');
17 require_login($course, null, $cm);
18 require_capability('moodle/restore:restorecourse', $context);
20 if ($stage & restore_ui::STAGE_CONFIRM + restore_ui::STAGE_DESTINATION) {
21 $restore = restore_ui::engage_independent_stage($stage, $contextid);
22 } else {
23 $restoreid = optional_param('restore', false, PARAM_ALPHANUM);
24 $rc = restore_ui::load_controller($restoreid);
25 if (!$rc) {
26 $restore = restore_ui::engage_independent_stage($stage/2, $contextid);
27 if ($restore->process()) {
28 $rc = new restore_controller($restore->get_filepath(), $restore->get_course_id(), backup::INTERACTIVE_YES,
29 backup::MODE_GENERAL, $USER->id, $restore->get_target());
32 if ($rc) {
33 // check if the format conversion must happen first
34 if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
35 $rc->convert();
38 $restore = new restore_ui($rc, array('contextid'=>$context->id));
42 $outcome = $restore->process();
43 if (!$restore->is_independent()) {
44 if ($restore->get_stage() == restore_ui::STAGE_PROCESS && !$restore->requires_substage()) {
45 try {
46 $restore->execute();
47 } catch(Exception $e) {
48 $restore->cleanup();
49 throw new moodle_exception((string)$e);
51 } else {
52 $restore->save_controller();
55 $heading = $course->fullname;
57 $PAGE->set_title($heading.': '.$restore->get_stage_name());
58 $PAGE->set_heading($heading);
59 $PAGE->navbar->add($restore->get_stage_name());
61 $renderer = $PAGE->get_renderer('core','backup');
62 echo $OUTPUT->header();
63 if (!$restore->is_independent() && $restore->enforce_changed_dependencies()) {
64 echo $renderer->dependency_notification(get_string('dependenciesenforced','backup'));
66 echo $renderer->progress_bar($restore->get_progress_bar());
67 echo $restore->display($renderer);
68 $restore->destroy();
69 unset($restore);
70 echo $OUTPUT->footer();