MDL-41840 Restore: Page title, breadcrumbs show incorrect stage
[moodle.git] / backup / restore.php
CommitLineData
795b6945 1<?php
a4ad03f1 2 //This script is used to configure and execute the restore proccess.
0f192e2c 3
785d6603
SH
4require_once('../config.php');
5require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
0f192e2c 6
785d6603 7$contextid = required_param('contextid', PARAM_INT);
f666f149 8$stage = optional_param('stage', restore_ui::STAGE_CONFIRM, PARAM_INT);
0f192e2c 9
785d6603 10list($context, $course, $cm) = get_context_info_array($contextid);
0f192e2c 11
573cdf85 12navigation_node::override_active_url(new moodle_url('/backup/restorefile.php', array('contextid'=>$contextid)));
785d6603
SH
13$PAGE->set_url(new moodle_url('/backup/restore.php', array('contextid'=>$contextid)));
14$PAGE->set_context($context);
15$PAGE->set_pagelayout('standard');
69179494 16
785d6603 17require_login($course, null, $cm);
39bc4c6f 18require_capability('moodle/restore:restorecourse', $context);
873bf875 19
975f8442 20// Restore of large courses requires extra memory. Use the amount configured
21// in admin settings.
22raise_memory_limit(MEMORY_EXTRA);
23
785d6603
SH
24if ($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,
39bc4c6f 33 backup::MODE_GENERAL, $USER->id, $restore->get_target());
9e426d54 34 }
0f192e2c 35 }
785d6603 36 if ($rc) {
f666f149
DM
37 // check if the format conversion must happen first
38 if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
39 $rc->convert();
40 }
41
785d6603 42 $restore = new restore_ui($rc, array('contextid'=>$context->id));
9e426d54 43 }
785d6603 44}
f666f149 45
8d137307 46$PAGE->set_title($course->shortname . ': ' . get_string('restore'));
47$PAGE->set_heading($course->fullname);
f06abc2a 48
49$renderer = $PAGE->get_renderer('core','backup');
50echo $OUTPUT->header();
a7a64d77 51
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();
59
f06abc2a 60if (!$restore->is_independent() && $restore->enforce_changed_dependencies()) {
61 debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER);
62}
63
785d6603
SH
64if (!$restore->is_independent()) {
65 if ($restore->get_stage() == restore_ui::STAGE_PROCESS && !$restore->requires_substage()) {
41612837 66 try {
f06abc2a 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());
41612837 71 $restore->execute();
f06abc2a 72 echo html_writer::end_div();
73 echo html_writer::script('document.getElementById("executionprogress").style.display = "none";');
41612837
RT
74 } catch(Exception $e) {
75 $restore->cleanup();
ecdd2d18 76 throw $e;
41612837 77 }
7022dd39 78 } else {
785d6603
SH
79 $restore->save_controller();
80 }
81}
785d6603 82
785d6603
SH
83echo $renderer->progress_bar($restore->get_progress_bar());
84echo $restore->display($renderer);
44bb101d
SH
85$restore->destroy();
86unset($restore);
1d6b83ec 87echo $OUTPUT->footer();