Merge branch 'MDL-26520' of git://github.com/timhunt/moodle
[moodle.git] / backup / restore.php
blob6d49b640868acbc0d9573266e239f71f15705ef6
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 $restore = new restore_ui($rc, array('contextid'=>$context->id));
36 $outcome = $restore->process();
37 if (!$restore->is_independent()) {
38 if ($restore->get_stage() == restore_ui::STAGE_PROCESS && !$restore->requires_substage()) {
39 $restore->execute();
40 } else {
41 $restore->save_controller();
44 $heading = $course->fullname;
46 $PAGE->set_title($heading.': '.$restore->get_stage_name());
47 $PAGE->set_heading($heading);
48 $PAGE->navbar->add($restore->get_stage_name());
50 $renderer = $PAGE->get_renderer('core','backup');
51 echo $OUTPUT->header();
52 if (!$restore->is_independent() && $restore->enforce_changed_dependencies()) {
53 echo $renderer->dependency_notification(get_string('dependenciesenforced','backup'));
55 echo $renderer->progress_bar($restore->get_progress_bar());
56 echo $restore->display($renderer);
57 $restore->destroy();
58 unset($restore);
59 echo $OUTPUT->footer();