moodle/backup/restore.php
stronk7 53fd7cae8d MDL-17469 - Revert incorrect handling of restore parameters in restore.php file. It was
causing restore dates to be rolled based in the course where the backupfile is stored
and not in the target course. Merged from 19_STABLE
2009-10-05 16:32:15 +00:00

170 lines
5.9 KiB
PHP

<?php //$Id$
//This script is used to configure and execute the restore proccess.
//Define some globals for all the script
//Units used
require_once("../config.php");
require_once("../lib/xmlize.php");
require_once("../course/lib.php");
require_once("lib.php");
require_once("restorelib.php");
require_once("bb/restore_bb.php");
require_once("$CFG->libdir/wiki_to_markdown.php" );
require_once("$CFG->libdir/adminlib.php");
//Optional
$id = optional_param('id', 0, PARAM_INT);
$file = optional_param( 'file', 0, PARAM_PATH);
$cancel = optional_param('cancel', '', PARAM_RAW);
$launch = optional_param( 'launch', '', PARAM_ACTION);
$to = optional_param('to', '', PARAM_INT);
$method = optional_param('method', '', PARAM_ACTION);
$backup_unique_code = optional_param('backup_unique_code',0,PARAM_INT);
//Check login
require_login();
/// With method=manual, we come from the FileManager so we delete all the backup/restore/import session structures
if ($method == 'manual') {
if (isset($SESSION->course_header)) {
unset ($SESSION->course_header);
}
if (isset($SESSION->info)) {
unset ($SESSION->info);
}
if (isset($SESSION->backupprefs)) {
unset ($SESSION->backupprefs);
}
if (isset($SESSION->restore)) {
unset ($SESSION->restore);
}
if (isset($SESSION->import_preferences)) {
unset ($SESSION->import_preferences);
}
}
if (!$to && isset($SESSION->restore->restoreto) && isset($SESSION->restore->importing) && isset($SESSION->restore->course_id)) {
$to = $SESSION->restore->course_id;
}
$loginurl = get_login_url();
if (!empty($id)) {
require_login($id);
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
if (empty($to)) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
} else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
&& !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
}
}
}
} else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
print_error("cannotuseadmin", '', $loginurl);
}
}
//Check site
if (!$site = get_site()) {
print_error("cannotfindsite");
}
//Check necessary functions exists. Thanks to gregb@crowncollege.edu
backup_required_functions();
//Get strings
if (empty($to)) {
$strcourserestore = get_string("courserestore");
} else {
$strcourserestore = get_string("importdata");
}
$stradministration = get_string("administration");
//If no file has been selected from the FileManager, inform and end
$PAGE->set_title("$site->shortname: $strcourserestore");
$PAGE->set_heading($site->fullname);
if (!$file) {
$PAGE->navbar->add($stradministration, new moodle_url($CFG->wwwroot.'/'.$CFG->admin.'/index.php'));
$PAGE->navbar->add($strcourserestore);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string("nofilesselected"));
echo $OUTPUT->continue_button("$CFG->wwwroot/$CFG->admin/index.php");
echo $OUTPUT->footer();
exit;
}
//If cancel has been selected, inform and end
if ($cancel) {
$PAGE->navbar->add($stradministration, new moodle_url($CFG->wwwroot.'/'.$CFG->admin.'/index.php'));
$PAGE->navbar->add($strcourserestore);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string("restorecancelled"));
echo $OUTPUT->continue_button("$CFG->wwwroot/course/view.php?id=".$id);
echo $OUTPUT->footer();
exit;
}
//We are here, so we have a file.
//Get and check course
if (! $course = $DB->get_record('course', array('id'=>$id))) {
error("Course ID was incorrect (can't find it)");
}
//Print header
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
$PAGE->navbar->add(basename($file));
echo $OUTPUT->header();
} else {
$PAGE->navbar->add($course->shortname, new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$course->id)));
$PAGE->navbar->add($strcourserestore);
echo $OUTPUT->header();
}
//Print form
echo $OUTPUT->heading("$strcourserestore".((empty($to) ? ': '.basename($file) : '')));
echo $OUTPUT->box_start();
//Adjust some php variables to the execution of this script
@ini_set("max_execution_time","3000");
if (empty($CFG->extramemorylimit)) {
raise_memory_limit('128M');
} else {
raise_memory_limit($CFG->extramemorylimit);
}
//Call the form, depending the step we are
if (!$launch) {
include_once("restore_precheck.html");
} else if ($launch == "form") {
if (!empty($SESSION->restore->importing)) {
// set up all the config stuff and skip asking the user about it.
restore_setup_for_check($SESSION->restore,$backup_unique_code);
include_once("restore_execute.html");
} else {
include_once("restore_form.html");
}
} else if ($launch == "check") {
include_once("restore_check.html");
//To avoid multiple restore executions...
$SESSION->cancontinue = true;
} else if ($launch == "execute") {
//Prevent multiple restore executions...
if (empty($SESSION->cancontinue)) {
print_error('multiplerestorenotallow');
}
//Unset this for the future
unset($SESSION->cancontinue);
include_once("restore_execute.html");
}
echo $OUTPUT->box_end();
//Print footer
echo $OUTPUT->footer();
?>