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 // Restore of large courses requires extra memory. Use the amount configured
22 raise_memory_limit(MEMORY_EXTRA
);
24 if ($stage & restore_ui
::STAGE_CONFIRM + restore_ui
::STAGE_DESTINATION
) {
25 $restore = restore_ui
::engage_independent_stage($stage, $contextid);
27 $restoreid = optional_param('restore', false, PARAM_ALPHANUM
);
28 $rc = restore_ui
::load_controller($restoreid);
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
,
33 backup
::MODE_GENERAL
, $USER->id
, $restore->get_target());
37 // check if the format conversion must happen first
38 if ($rc->get_status() == backup
::STATUS_REQUIRE_CONV
) {
42 $restore = new restore_ui($rc, array('contextid'=>$context->id
));
46 $PAGE->set_title($course->shortname
. ': ' . get_string('restore'));
47 $PAGE->set_heading($course->fullname
);
49 $renderer = $PAGE->get_renderer('core','backup');
50 echo $OUTPUT->header();
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(get_string('preparingui', 'backup'));
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();
60 if (!$restore->is_independent() && $restore->enforce_changed_dependencies()) {
61 debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER
);
64 if (!$restore->is_independent()) {
65 // Use a temporary (disappearing) progress bar to show the precheck progress if any.
66 $precheckprogress = new core_backup_display_progress_if_slow(get_string('preparingdata', 'backup'));
67 $restore->get_controller()->set_progress($precheckprogress);
68 if ($restore->get_stage() == restore_ui
::STAGE_PROCESS
&& !$restore->requires_substage()) {
70 // Div used to hide the 'progress' step once the page gets onto 'finished'.
71 echo html_writer
::start_div('', array('id' => 'executionprogress'));
72 // Show the current restore state (header with bolded item).
73 echo $renderer->progress_bar($restore->get_progress_bar());
74 // Start displaying the actual progress bar percentage.
75 $restore->get_controller()->set_progress(new core_backup_display_progress(true));
78 // Hide this section because we are now going to make the page show 'finished'.
79 echo html_writer
::end_div();
80 echo html_writer
::script('document.getElementById("executionprogress").style.display = "none";');
81 } catch(Exception
$e) {
86 $restore->save_controller();
90 echo $renderer->progress_bar($restore->get_progress_bar());
91 echo $restore->display($renderer);
94 echo $OUTPUT->footer();