MDL-41840 Restore: Page title, breadcrumbs show incorrect stage
[moodle.git] / backup / restore.php
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 // Restore of large courses requires extra memory. Use the amount configured
21 // in admin settings.
22 raise_memory_limit(MEMORY_EXTRA);
24 if ($stage & restore_ui::STAGE_CONFIRM + restore_ui::STAGE_DESTINATION) {
25     $restore = restore_ui::engage_independent_stage($stage, $contextid);
26 } else {
27     $restoreid = optional_param('restore', false, PARAM_ALPHANUM);
28     $rc = restore_ui::load_controller($restoreid);
29     if (!$rc) {
30         $restore = restore_ui::engage_independent_stage($stage/2, $contextid);
31         if ($restore->process()) {
32             $rc = new restore_controller($restore->get_filepath(), $restore->get_course_id(), backup::INTERACTIVE_YES,
33                                 backup::MODE_GENERAL, $USER->id, $restore->get_target());
34         }
35     }
36     if ($rc) {
37         // check if the format conversion must happen first
38         if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
39             $rc->convert();
40         }
42         $restore = new restore_ui($rc, array('contextid'=>$context->id));
43     }
44 }
46 $PAGE->set_title($course->shortname . ': ' . get_string('restore'));
47 $PAGE->set_heading($course->fullname);
49 $renderer = $PAGE->get_renderer('core','backup');
50 echo $OUTPUT->header();
52 // Prepare a progress bar which can display optionally during long-running
53 // operations while setting up the UI.
54 $slowprogress = new core_backup_display_progress_if_slow();
55 // Depending on the code branch above, $restore may be a restore_ui or it may
56 // be a restore_ui_independent_stage. Either way, this function exists.
57 $restore->set_progress_reporter($slowprogress);
58 $outcome = $restore->process();
60 if (!$restore->is_independent() && $restore->enforce_changed_dependencies()) {
61     debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER);
62 }
64 if (!$restore->is_independent()) {
65     if ($restore->get_stage() == restore_ui::STAGE_PROCESS && !$restore->requires_substage()) {
66         try {
67             // Display an extra progress bar so that we can show the progress first.
68             echo html_writer::start_div('', array('id' => 'executionprogress'));
69             echo $renderer->progress_bar($restore->get_progress_bar());
70             $restore->get_controller()->set_progress(new core_backup_display_progress());
71             $restore->execute();
72             echo html_writer::end_div();
73             echo html_writer::script('document.getElementById("executionprogress").style.display = "none";');
74         } catch(Exception $e) {
75             $restore->cleanup();
76             throw $e;
77         }
78     } else {
79         $restore->save_controller();
80     }
81 }
83 echo $renderer->progress_bar($restore->get_progress_bar());
84 echo $restore->display($renderer);
85 $restore->destroy();
86 unset($restore);
87 echo $OUTPUT->footer();