forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore.php
184 lines (160 loc) · 6.56 KB
/
restore.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?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");
require_once("$CFG->libdir/wiki_to_markdown.php" );
require_once("$CFG->libdir/adminlib.php");
//Optional
$id = optional_param( 'id' );
$file = optional_param( 'file' );
$cancel = optional_param( 'cancel' );
$launch = optional_param( 'launch' );
$to = optional_param( 'to' );
$method = optional_param( 'method' );
$backup_unique_code = optional_param('backup_unique_code',0,PARAM_INT);
//Get and check course
if (! $course = get_record("course", "id", $id)) {
print_error('invalidcourseid');
}
// To some reasons, course_startdateoffset value was lost during restoring
// See MDL-17469
if (!empty($course->startdate) && !empty($SESSION->course_header->course_startdate)) {
$SESSION->restore->course_startdateoffset = $course->startdate - $SESSION->course_header->course_startdate;
} else {
$SESSION->restore->course_startdateoffset = 0;
}
//Check login
require_login();
/// 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);
}
}
if (!$to && isset($SESSION->restore->restoreto) && isset($SESSION->restore->importing) && isset($SESSION->restore->course_id)) {
$to = $SESSION->restore->course_id;
}
$loginurl = get_login_url();
if (!empty($id)) {
require_login($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("cannotfindsite");
}
//Check necessary functions exists. Thanks to [email protected]
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
$navlinks = array();
$navlinks[] = array('name' => $stradministration, 'link' => "$CFG->wwwroot/$CFG->admin/index.php", 'type' => 'misc');
$navlinks[] = array('name' => $strcourserestore, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
if (!$file) {
print_header("$site->shortname: $strcourserestore", $site->fullname, $navigation);
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, $navigation);
print_heading(get_string("restorecancelled"));
print_continue("$CFG->wwwroot/course/view.php?id=".$id);
print_footer();
exit;
}
//We are here, so me have a file.
//Print header
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
$navlinks[] = array('name' => basename($file), 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$site->shortname: $strcourserestore", $site->fullname, $navigation);
} else {
$navlinks = array();
$navlinks[] = array('name' => $course->shortname, 'link' => "$CFG->wwwroot/course/view.php?id=$course->id", 'type' => 'misc');
$navlinks[] = array('name' => $strcourserestore, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: $strcourserestore", $course->fullname, $navigation);
}
//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("192M");
//Call the form, depending the step we are
if (!$launch) {
include_once("restore_precheck.html");
} else if ($launch == "form") {
if (!empty($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");
//To avoid multiple restore executions...
$SESSION->cancontinue = true;
} else if ($launch == "execute") {
//Prevent multiple restore executions...
if (empty($SESSION->cancontinue)) {
print_error('multiplerestorenotallow');
}
//Unset this for the future
unset($SESSION->cancontinue);
include_once("restore_execute.html");
}
print_simple_box_end();
//Print footer
print_footer();
?>