Merge branch 's13_MDL-29170_risklevel_master' of git://github.com/dongsheng/moodle
[moodle.git] / backup / restore.php
blobed72ab84b762f717dfb259fe4d806eff929276cb
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 $restore->execute();
46 } else {
47 $restore->save_controller();
50 $heading = $course->fullname;
52 $PAGE->set_title($heading.': '.$restore->get_stage_name());
53 $PAGE->set_heading($heading);
54 $PAGE->navbar->add($restore->get_stage_name());
56 $renderer = $PAGE->get_renderer('core','backup');
57 echo $OUTPUT->header();
58 if (!$restore->is_independent() && $restore->enforce_changed_dependencies()) {
59 echo $renderer->dependency_notification(get_string('dependenciesenforced','backup'));
61 echo $renderer->progress_bar($restore->get_progress_bar());
62 echo $restore->display($renderer);
63 $restore->destroy();
64 unset($restore);
65 echo $OUTPUT->footer();