2004-09-12 01:34:24 +00:00
|
|
|
<?php //$Id$
|
2003-05-25 22:58:13 +00:00
|
|
|
//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;
|
|
|
|
}
|
|
|
|
|
2004-05-06 23:20:25 +00:00
|
|
|
//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;
|
2009-01-20 03:16:30 +00:00
|
|
|
// Copy $info->original_siteidentifier, is present, so backup_is_same_site can work.
|
|
|
|
if (isset($info->original_siteidentifier)) {
|
|
|
|
$restore->original_siteidentifier = $info->original_siteidentifier;
|
|
|
|
}
|
2005-04-12 16:10:47 +00:00
|
|
|
//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;
|
2004-05-06 23:20:25 +00:00
|
|
|
|
2003-05-25 22:58:13 +00:00
|
|
|
//Check login
|
|
|
|
require_login();
|
|
|
|
|
2009-01-02 22:56:48 +00:00
|
|
|
$loginurl = get_login_url();
|
|
|
|
|
2003-05-25 22:58:13 +00:00
|
|
|
//Check admin
|
2003-08-03 00:42:41 +00:00
|
|
|
if (!empty($id)) {
|
2006-09-19 07:16:04 +00:00
|
|
|
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
|
2005-01-27 02:35:10 +00:00
|
|
|
if (empty($to)) {
|
2009-01-02 22:56:48 +00:00
|
|
|
print_error("cannotuseadminadminorteacher", '', $loginurl);
|
2005-01-27 02:35:10 +00:00
|
|
|
} else {
|
2007-11-26 02:39:28 +00:00
|
|
|
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
|
|
|
|
&& !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) {
|
2009-01-02 22:56:48 +00:00
|
|
|
print_error("cannotuseadminadminorteacher", '', $loginurl);
|
2005-01-27 02:35:10 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-03 00:42:41 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-05-02 04:37:02 +00:00
|
|
|
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
|
2009-01-02 22:56:48 +00:00
|
|
|
print_error("cannotuseadmin", '', $loginurl);
|
2003-08-03 00:42:41 +00:00
|
|
|
}
|
2003-05-25 22:58:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Check site
|
|
|
|
if (!$site = get_site()) {
|
2008-05-08 08:43:17 +00:00
|
|
|
print_error("siteisnotdefined", 'debug');
|
2003-05-25 22:58:13 +00:00
|
|
|
}
|
2006-01-15 21:09:13 +00:00
|
|
|
$errorstr = '';
|
2006-09-25 09:10:19 +00:00
|
|
|
|
2006-01-15 21:09:13 +00:00
|
|
|
$status = restore_execute($restore,$info,$course_header,$errorstr);
|
2003-05-25 22:58:13 +00:00
|
|
|
|
|
|
|
if (!$status) {
|
2008-05-08 08:43:17 +00:00
|
|
|
print_error ("cannotrestore");
|
2003-05-25 22:58:13 +00:00
|
|
|
}
|
|
|
|
|
2006-06-03 20:18:02 +00:00
|
|
|
if (empty($restore->importing)) {
|
2005-01-27 02:35:10 +00:00
|
|
|
//Print final message
|
2005-02-07 23:28:52 +00:00
|
|
|
print_simple_box(get_string("restorefinished"),"center");
|
2005-01-27 02:35:10 +00:00
|
|
|
} else {
|
2005-02-07 23:28:52 +00:00
|
|
|
print_simple_box(get_string("importdatafinished"),"center");
|
2007-03-02 01:43:47 +00:00
|
|
|
$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");
|
|
|
|
}
|
2005-01-27 02:35:10 +00:00
|
|
|
unset($SESSION->restore);
|
|
|
|
}
|
2003-08-01 14:34:11 +00:00
|
|
|
print_continue("$CFG->wwwroot/course/view.php?id=".$restore->course_id);
|
2003-07-07 18:46:36 +00:00
|
|
|
|
2003-05-25 22:58:13 +00:00
|
|
|
?>
|