Merge branch 'wip-MDL-35056-stable23' of git://github.com/phalacee/moodle into MOODLE...
[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
785d6603
SH
20if ($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,
39bc4c6f 29 backup::MODE_GENERAL, $USER->id, $restore->get_target());
9e426d54 30 }
0f192e2c 31 }
785d6603 32 if ($rc) {
f666f149
DM
33 // check if the format conversion must happen first
34 if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
35 $rc->convert();
36 }
37
785d6603 38 $restore = new restore_ui($rc, array('contextid'=>$context->id));
9e426d54 39 }
785d6603 40}
f666f149 41
785d6603
SH
42$outcome = $restore->process();
43if (!$restore->is_independent()) {
44 if ($restore->get_stage() == restore_ui::STAGE_PROCESS && !$restore->requires_substage()) {
41612837
RT
45 try {
46 $restore->execute();
47 } catch(Exception $e) {
48 $restore->cleanup();
ecdd2d18 49 throw $e;
41612837 50 }
7022dd39 51 } else {
785d6603
SH
52 $restore->save_controller();
53 }
54}
55$heading = $course->fullname;
56
57$PAGE->set_title($heading.': '.$restore->get_stage_name());
58$PAGE->set_heading($heading);
785d6603
SH
59$PAGE->navbar->add($restore->get_stage_name());
60
61$renderer = $PAGE->get_renderer('core','backup');
62echo $OUTPUT->header();
63if (!$restore->is_independent() && $restore->enforce_changed_dependencies()) {
d4f5439d 64 debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER);
785d6603
SH
65}
66echo $renderer->progress_bar($restore->get_progress_bar());
67echo $restore->display($renderer);
44bb101d
SH
68$restore->destroy();
69unset($restore);
1d6b83ec 70echo $OUTPUT->footer();