2009-11-01 15:39:15 +00:00
|
|
|
<?php
|
2003-05-17 08:56:53 +00:00
|
|
|
//This script is used to configure and execute the restore proccess.
|
2003-05-14 23:25:00 +00:00
|
|
|
|
|
|
|
//Define some globals for all the script
|
|
|
|
|
|
|
|
//Units used
|
2006-09-03 09:00:13 +00:00
|
|
|
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");
|
2005-04-12 23:40:40 +00:00
|
|
|
require_once("$CFG->libdir/wiki_to_markdown.php" );
|
2006-09-03 09:00:13 +00:00
|
|
|
require_once("$CFG->libdir/adminlib.php");
|
2003-05-14 23:25:00 +00:00
|
|
|
|
2003-05-16 21:52:49 +00:00
|
|
|
//Optional
|
2009-08-27 19:14:45 +00:00
|
|
|
$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);
|
2006-04-25 20:47:44 +00:00
|
|
|
$backup_unique_code = optional_param('backup_unique_code',0,PARAM_INT);
|
2003-05-14 23:25:00 +00:00
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/backup/restore.php');
|
2009-10-15 03:05:35 +00:00
|
|
|
if ($id !== 0) {
|
|
|
|
$url->param('id', $id);
|
|
|
|
}
|
|
|
|
if ($file !== 0) {
|
|
|
|
$url->param('file', $file);
|
|
|
|
}
|
|
|
|
if ($cancel !== '') {
|
|
|
|
$url->param('cancel', $cancel);
|
|
|
|
}
|
|
|
|
if ($launch !== '') {
|
|
|
|
$url->param('launch', $launch);
|
|
|
|
}
|
|
|
|
if ($to !== '') {
|
|
|
|
$url->param('to', $to);
|
|
|
|
}
|
|
|
|
if ($method !== '') {
|
|
|
|
$url->param('method', $method);
|
|
|
|
}
|
|
|
|
if ($backup_unique_code !== 0) {
|
|
|
|
$url->param('backup_unique_code', $backup_unique_code);
|
|
|
|
}
|
2009-10-16 03:09:31 +00:00
|
|
|
$PAGE->set_url($url);
|
2009-10-15 03:05:35 +00:00
|
|
|
|
2009-11-01 09:21:41 +00:00
|
|
|
$site = get_site();
|
2003-05-14 23:25:00 +00:00
|
|
|
|
2006-04-10 18:34:37 +00:00
|
|
|
/// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-27 02:35:10 +00:00
|
|
|
if (!$to && isset($SESSION->restore->restoreto) && isset($SESSION->restore->importing) && isset($SESSION->restore->course_id)) {
|
|
|
|
$to = $SESSION->restore->course_id;
|
|
|
|
}
|
|
|
|
|
2009-01-02 22:56:48 +00:00
|
|
|
$loginurl = get_login_url();
|
|
|
|
|
2003-08-02 16:06:33 +00:00
|
|
|
if (!empty($id)) {
|
2007-09-24 15:50:34 +00:00
|
|
|
require_login($id);
|
2010-02-19 17:50:14 +00:00
|
|
|
if (!has_capability('moodle/restore:restorecourse', 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 {
|
2010-02-19 17:50:14 +00:00
|
|
|
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $to))
|
2010-02-19 19:11:06 +00:00
|
|
|
&& !has_capability('moodle/restore:restoretargetimport', 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-02 16:06:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-02-19 17:50:14 +00:00
|
|
|
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_SYSTEM))) {
|
2009-01-02 22:56:48 +00:00
|
|
|
print_error("cannotuseadmin", '', $loginurl);
|
2003-08-02 16:06:33 +00:00
|
|
|
}
|
2003-05-14 23:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Check site
|
2009-11-01 09:21:41 +00:00
|
|
|
$site = get_site();
|
2003-06-12 15:35:37 +00:00
|
|
|
|
|
|
|
//Check necessary functions exists. Thanks to gregb@crowncollege.edu
|
|
|
|
backup_required_functions();
|
2007-08-17 11:18:58 +00:00
|
|
|
|
2003-05-14 23:25:00 +00:00
|
|
|
//Get strings
|
2005-01-27 02:35:10 +00:00
|
|
|
if (empty($to)) {
|
|
|
|
$strcourserestore = get_string("courserestore");
|
|
|
|
} else {
|
|
|
|
$strcourserestore = get_string("importdata");
|
|
|
|
}
|
2003-05-14 23:25:00 +00:00
|
|
|
$stradministration = get_string("administration");
|
|
|
|
|
2003-05-16 21:52:49 +00:00
|
|
|
//If no file has been selected from the FileManager, inform and end
|
2009-09-07 06:18:27 +00:00
|
|
|
$PAGE->set_title("$site->shortname: $strcourserestore");
|
|
|
|
$PAGE->set_heading($site->fullname);
|
2003-05-16 21:52:49 +00:00
|
|
|
if (!$file) {
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php'));
|
2009-09-07 06:18:27 +00:00
|
|
|
$PAGE->navbar->add($strcourserestore);
|
|
|
|
echo $OUTPUT->header();
|
2009-08-06 08:19:03 +00:00
|
|
|
echo $OUTPUT->heading(get_string("nofilesselected"));
|
2009-08-18 04:29:16 +00:00
|
|
|
echo $OUTPUT->continue_button("$CFG->wwwroot/$CFG->admin/index.php");
|
2009-08-06 14:23:15 +00:00
|
|
|
echo $OUTPUT->footer();
|
2003-05-14 23:25:00 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2003-05-18 22:53:11 +00:00
|
|
|
//If cancel has been selected, inform and end
|
|
|
|
if ($cancel) {
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php'));
|
2009-09-07 06:18:27 +00:00
|
|
|
$PAGE->navbar->add($strcourserestore);
|
|
|
|
echo $OUTPUT->header();
|
2009-08-06 08:19:03 +00:00
|
|
|
echo $OUTPUT->heading(get_string("restorecancelled"));
|
2009-08-18 04:29:16 +00:00
|
|
|
echo $OUTPUT->continue_button("$CFG->wwwroot/course/view.php?id=".$id);
|
2009-08-06 14:23:15 +00:00
|
|
|
echo $OUTPUT->footer();
|
2003-05-18 22:53:11 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2009-10-05 16:32:15 +00:00
|
|
|
//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)");
|
|
|
|
}
|
2003-08-02 16:06:33 +00:00
|
|
|
|
2003-05-14 23:25:00 +00:00
|
|
|
//Print header
|
2008-05-02 04:37:02 +00:00
|
|
|
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
|
2009-09-07 06:18:27 +00:00
|
|
|
$PAGE->navbar->add(basename($file));
|
|
|
|
echo $OUTPUT->header();
|
2003-08-02 16:06:33 +00:00
|
|
|
} else {
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
|
2009-09-07 06:18:27 +00:00
|
|
|
$PAGE->navbar->add($strcourserestore);
|
|
|
|
echo $OUTPUT->header();
|
2003-08-02 16:06:33 +00:00
|
|
|
}
|
2003-05-16 21:52:49 +00:00
|
|
|
//Print form
|
2009-08-06 08:19:03 +00:00
|
|
|
echo $OUTPUT->heading("$strcourserestore".((empty($to) ? ': '.basename($file) : '')));
|
2009-08-18 04:29:16 +00:00
|
|
|
echo $OUTPUT->box_start();
|
2007-08-17 11:18:58 +00:00
|
|
|
|
2003-06-11 19:13:07 +00:00
|
|
|
//Adjust some php variables to the execution of this script
|
2004-09-08 22:47:19 +00:00
|
|
|
@ini_set("max_execution_time","3000");
|
2009-03-30 10:07:24 +00:00
|
|
|
if (empty($CFG->extramemorylimit)) {
|
2009-03-26 02:09:28 +00:00
|
|
|
raise_memory_limit('128M');
|
|
|
|
} else {
|
2009-03-30 10:07:24 +00:00
|
|
|
raise_memory_limit($CFG->extramemorylimit);
|
2009-03-26 02:09:28 +00:00
|
|
|
}
|
2003-05-16 21:52:49 +00:00
|
|
|
|
2003-05-14 23:25:00 +00:00
|
|
|
//Call the form, depending the step we are
|
2005-01-27 02:35:10 +00:00
|
|
|
|
2003-05-14 23:25:00 +00:00
|
|
|
if (!$launch) {
|
2003-05-16 21:52:49 +00:00
|
|
|
include_once("restore_precheck.html");
|
2003-05-18 17:15:05 +00:00
|
|
|
} else if ($launch == "form") {
|
2006-06-03 19:51:28 +00:00
|
|
|
if (!empty($SESSION->restore->importing)) {
|
2005-01-27 02:35:10 +00:00
|
|
|
// set up all the config stuff and skip asking the user about it.
|
|
|
|
restore_setup_for_check($SESSION->restore,$backup_unique_code);
|
2009-11-19 18:48:34 +00:00
|
|
|
require_sesskey();
|
2005-01-27 02:35:10 +00:00
|
|
|
include_once("restore_execute.html");
|
|
|
|
} else {
|
|
|
|
include_once("restore_form.html");
|
|
|
|
}
|
2003-05-19 22:28:39 +00:00
|
|
|
} else if ($launch == "check") {
|
|
|
|
include_once("restore_check.html");
|
2005-05-18 18:07:02 +00:00
|
|
|
//To avoid multiple restore executions...
|
|
|
|
$SESSION->cancontinue = true;
|
2007-08-17 11:18:58 +00:00
|
|
|
} else if ($launch == "execute") {
|
2005-05-18 18:07:02 +00:00
|
|
|
//Prevent multiple restore executions...
|
|
|
|
if (empty($SESSION->cancontinue)) {
|
2008-04-24 02:48:36 +00:00
|
|
|
print_error('multiplerestorenotallow');
|
2005-05-18 18:07:02 +00:00
|
|
|
}
|
|
|
|
//Unset this for the future
|
|
|
|
unset($SESSION->cancontinue);
|
2009-11-19 18:48:34 +00:00
|
|
|
require_sesskey();
|
2003-05-24 00:27:45 +00:00
|
|
|
include_once("restore_execute.html");
|
2003-05-14 23:25:00 +00:00
|
|
|
}
|
2009-08-18 04:29:16 +00:00
|
|
|
echo $OUTPUT->box_end();
|
2003-05-14 23:25:00 +00:00
|
|
|
|
2007-08-17 11:18:58 +00:00
|
|
|
//Print footer
|
2009-08-06 14:23:15 +00:00
|
|
|
echo $OUTPUT->footer();
|