mirror of
https://github.com/moodle/moodle.git
synced 2025-02-02 14:19:07 +01:00
9ff5e44a93
Completely untested by me but it LOOKS like it should work. It's quite standalone, and is basically a single function call during the restore precheck which looks in the backup to see if it's a BB file, then converts it using XSLT. Apart from a little tidyup and renaming, I added a check so that it should just silently fail if XSLT functions aren't available Many thanks to Ziba Scott <ziba@linuxbox.com> who wrote it!
140 lines
4.6 KiB
PHP
140 lines
4.6 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/blocklib.php");
|
|
|
|
//Optional
|
|
optional_variable($id);
|
|
optional_variable($file);
|
|
optional_variable($cancel);
|
|
optional_variable($launch);
|
|
optional_variable($to);
|
|
|
|
//Check login
|
|
require_login();
|
|
|
|
if (!$to && isset($SESSION->restore->restoreto) && isset($SESSION->restore->importing) && isset($SESSION->restore->course_id)) {
|
|
$to = $SESSION->restore->course_id;
|
|
}
|
|
|
|
if (!empty($id)) {
|
|
if (!isteacheredit($id)) {
|
|
if (empty($to)) {
|
|
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
|
} else {
|
|
if (!isteacheredit($to)) {
|
|
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
if (!isadmin()) {
|
|
error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
|
}
|
|
}
|
|
|
|
//Check site
|
|
if (!$site = get_site()) {
|
|
error("Site not found!");
|
|
}
|
|
|
|
//Check necessary functions exists. Thanks to gregb@crowncollege.edu
|
|
backup_required_functions();
|
|
|
|
//Check backup_version
|
|
if ($file) {
|
|
$linkto = "restore.php?id=".$id."&file=".$file;
|
|
} else {
|
|
$linkto = "restore.php";
|
|
}
|
|
upgrade_backup_db($linkto);
|
|
|
|
//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
|
|
if (!$file) {
|
|
print_header("$site->shortname: $strcourserestore", $site->fullname,
|
|
"<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> $strcourserestore");
|
|
print_heading(get_string("nofilesselected"));
|
|
print_continue("$CFG->wwwroot/$CFG->admin/index.php");
|
|
print_footer();
|
|
exit;
|
|
}
|
|
|
|
//If cancel has been selected, inform and end
|
|
if ($cancel) {
|
|
print_header("$site->shortname: $strcourserestore", $site->fullname,
|
|
"<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> $strcourserestore");
|
|
print_heading(get_string("restorecancelled"));
|
|
print_continue("$CFG->wwwroot/$CFG->admin/index.php");
|
|
print_footer();
|
|
exit;
|
|
}
|
|
|
|
//We are here, so me have a file.
|
|
|
|
//Get and check course
|
|
if (! $course = get_record("course", "id", $id)) {
|
|
error("Course ID was incorrect (can't find it)");
|
|
}
|
|
|
|
check_for_restricted_user($USER->username, "$CFG->wwwroot/course/view.php?id=$course->id");
|
|
|
|
//Print header
|
|
if (isadmin()) {
|
|
print_header("$site->shortname: $strcourserestore", $site->fullname,
|
|
"<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> ->
|
|
$strcourserestore -> ".basename($file));
|
|
} else {
|
|
print_header("$course->shortname: $strcourserestore", $course->fullname,
|
|
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
|
|
$strcourserestore");
|
|
}
|
|
//Print form
|
|
print_heading("$strcourserestore".((empty($to) ? ': '.basename($file) : '')));
|
|
print_simple_box_start('center');
|
|
|
|
//Adjust some php variables to the execution of this script
|
|
@ini_set("max_execution_time","3000");
|
|
raise_memory_limit("memory_limit","128M");
|
|
|
|
//Call the form, depending the step we are
|
|
|
|
|
|
if (!$launch) {
|
|
include_once("restore_precheck.html");
|
|
} else if ($launch == "form") {
|
|
if ($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");
|
|
} else if ($launch == "execute") {
|
|
include_once("restore_execute.html");
|
|
}
|
|
print_simple_box_end();
|
|
|
|
//Print footer
|
|
print_footer();
|
|
|
|
?>
|