Merge branch 'MDL-35026_22' of git://github.com/timhunt/moodle into MOODLE_22_STABLE
[moodle.git] / backup / restore.php
blob2ac6b7847f9d7068e64a2c41e17f9862bea519e8
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 try {
46 $restore->execute();
47 } catch(Exception $e) {
48 $restore->cleanup();
49 throw $e;
51 } else {
52 $restore->save_controller();
55 $heading = $course->fullname;
57 $PAGE->set_title($heading.': '.$restore->get_stage_name());
58 $PAGE->set_heading($heading);
59 $PAGE->navbar->add($restore->get_stage_name());
61 $renderer = $PAGE->get_renderer('core','backup');
62 echo $OUTPUT->header();
63 if (!$restore->is_independent() && $restore->enforce_changed_dependencies()) {
64 echo $renderer->dependency_notification(get_string('dependenciesenforced','backup'));
66 echo $renderer->progress_bar($restore->get_progress_bar());
67 echo $restore->display($renderer);
68 $restore->destroy();
69 unset($restore);
70 echo $OUTPUT->footer();