Bumping version for 1.8.9 release. Thinking we might have to go to x.x.10 for the...
[moodle.git] / backup / restore.php
blob88f75baf185ad1876d6a4586687563c98670b55e
1 <?php //$Id$
2 //This script is used to configure and execute the restore proccess.
4 //Define some globals for all the script
6 //Units used
7 require_once("../config.php");
8 require_once("../lib/xmlize.php");
9 require_once("../course/lib.php");
10 require_once("lib.php");
11 require_once("restorelib.php");
12 require_once("bb/restore_bb.php");
13 require_once("$CFG->libdir/blocklib.php");
14 require_once("$CFG->libdir/wiki_to_markdown.php" );
15 require_once("$CFG->libdir/adminlib.php");
17 //Optional
18 $id = optional_param( 'id' );
19 $file = optional_param( 'file' );
20 $cancel = optional_param( 'cancel' );
21 $launch = optional_param( 'launch' );
22 $to = optional_param( 'to' );
23 $method = optional_param( 'method' );
24 $backup_unique_code = optional_param('backup_unique_code',0,PARAM_INT);
26 //Check login
27 require_login();
29 /// With method=manual, we come from the FileManager so we delete all the backup/restore/import session structures
30 if ($method == 'manual') {
31 if (isset($SESSION->course_header)) {
32 unset ($SESSION->course_header);
34 if (isset($SESSION->info)) {
35 unset ($SESSION->info);
37 if (isset($SESSION->backupprefs)) {
38 unset ($SESSION->backupprefs);
40 if (isset($SESSION->restore)) {
41 unset ($SESSION->restore);
43 if (isset($SESSION->import_preferences)) {
44 unset ($SESSION->import_preferences);
48 if (!$to && isset($SESSION->restore->restoreto) && isset($SESSION->restore->importing) && isset($SESSION->restore->course_id)) {
49 $to = $SESSION->restore->course_id;
52 if (!empty($id)) {
53 require_login($id);
54 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
55 if (empty($to)) {
56 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
57 } else {
58 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
59 && !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) {
60 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
64 } else {
65 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
66 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
70 //Check site
71 if (!$site = get_site()) {
72 error("Site not found!");
75 //Check necessary functions exists. Thanks to gregb@crowncollege.edu
76 backup_required_functions();
78 //Check backup_version
79 if ($file) {
80 $linkto = "restore.php?id=".$id."&amp;file=".$file;
81 } else {
82 $linkto = "restore.php";
84 upgrade_backup_db($linkto);
86 //Get strings
87 if (empty($to)) {
88 $strcourserestore = get_string("courserestore");
89 } else {
90 $strcourserestore = get_string("importdata");
92 $stradministration = get_string("administration");
94 //If no file has been selected from the FileManager, inform and end
95 if (!$file) {
96 print_header("$site->shortname: $strcourserestore", $site->fullname,
97 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> $strcourserestore");
98 print_heading(get_string("nofilesselected"));
99 print_continue("$CFG->wwwroot/$CFG->admin/index.php");
100 print_footer();
101 exit;
104 //If cancel has been selected, inform and end
105 if ($cancel) {
106 print_header("$site->shortname: $strcourserestore", $site->fullname,
107 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> $strcourserestore");
108 print_heading(get_string("restorecancelled"));
109 print_continue("$CFG->wwwroot/course/view.php?id=".$id);
110 print_footer();
111 exit;
114 //We are here, so me have a file.
116 //Get and check course
117 if (! $course = get_record("course", "id", $id)) {
118 error("Course ID was incorrect (can't find it)");
121 //Print header
122 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
123 print_header("$site->shortname: $strcourserestore", $site->fullname,
124 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> ->
125 $strcourserestore -> ".basename($file));
126 } else {
127 print_header("$course->shortname: $strcourserestore", $course->fullname,
128 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
129 $strcourserestore");
131 //Print form
132 print_heading("$strcourserestore".((empty($to) ? ': '.basename($file) : '')));
133 print_simple_box_start('center');
135 //Adjust some php variables to the execution of this script
136 @ini_set("max_execution_time","3000");
137 raise_memory_limit("192M");
139 //Call the form, depending the step we are
141 if (!$launch) {
142 include_once("restore_precheck.html");
143 } else if ($launch == "form") {
144 if (!empty($SESSION->restore->importing)) {
145 // set up all the config stuff and skip asking the user about it.
146 restore_setup_for_check($SESSION->restore,$backup_unique_code);
147 include_once("restore_execute.html");
148 } else {
149 include_once("restore_form.html");
151 } else if ($launch == "check") {
152 include_once("restore_check.html");
153 //To avoid multiple restore executions...
154 $SESSION->cancontinue = true;
155 } else if ($launch == "execute") {
156 //Prevent multiple restore executions...
157 if (empty($SESSION->cancontinue)) {
158 error("Multiple restore execution not allowed!");
160 //Unset this for the future
161 unset($SESSION->cancontinue);
162 include_once("restore_execute.html");
164 print_simple_box_end();
166 //Print footer
167 print_footer();