moodle/backup/restore_execute.html
tjhunt d61f7b7641 backup/restore: MDL-16614 more reliable test for when we are restoring a backup that was made of the same site that we are restoring to.
* Use this to fix a question restore bug.
* Replace older code that does something similar with the new test.
* Refactor initialisation of $CFG->siteidentifier into a function. There were about 4 copies of this code ;-)
2009-01-20 03:16:30 +00:00

78 lines
2.7 KiB
HTML

<?php //$Id$
//This page receives the required info and executes the restore
//with the parameters suplied. Whe finished, delete temporary
//data from backup_tables and temp directory
//Get objects from session
if ($SESSION) {
$info = $SESSION->info;
$course_header = $SESSION->course_header;
$restore = $SESSION->restore;
}
//Add info->original_wwwroot to $restore to be able to use it in all the restore process
//(mainly when decoding internal links)
$restore->original_wwwroot = $info->original_wwwroot;
// Copy $info->original_siteidentifier, is present, so backup_is_same_site can work.
if (isset($info->original_siteidentifier)) {
$restore->original_siteidentifier = $info->original_siteidentifier;
}
//Add info->backup_version to $restore to be able to detect versions in the restore process
//(to decide when to convert wiki texts to markdown...)
$restore->backup_version = $info->backup_backup_version;
//Check login
require_login();
$loginurl = get_login_url();
//Check admin
if (!empty($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("siteisnotdefined", 'debug');
}
$errorstr = '';
$status = restore_execute($restore,$info,$course_header,$errorstr);
if (!$status) {
print_error ("cannotrestore");
}
if (empty($restore->importing)) {
//Print final message
print_simple_box(get_string("restorefinished"),"center");
} else {
print_simple_box(get_string("importdatafinished"),"center");
$file = $CFG->dataroot . '/'
. $SESSION->import_preferences->backup_course
. '/backupdata/' . $SESSION->import_preferences->backup_name;
if (is_readable($file)) {
unlink($file);
}
else {
error_log("import course data: couldn't unlink $file");
}
unset($SESSION->restore);
}
print_continue("$CFG->wwwroot/course/view.php?id=".$restore->course_id);
?>