forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore_execute.html
88 lines (77 loc) · 3.43 KB
/
restore_execute.html
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
<?php
//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;
// Validate objects from session by checking their checksums
$status = false;
if (isset($SESSION->restore_checksums)) {
$checksums = $SESSION->restore_checksums;
if (isset($checksums['info']) && $checksums['info'] == md5(serialize($info)) &&
isset($checksums['course_header']) && $checksums['course_header'] == md5(serialize($course_header)) &&
isset($checksums['restore']) && $checksums['restore'] == md5(serialize($restore))) {
$status = true; // All session checksums were or, we can rely on that to continue restoring
}
}
if(!$status) { // Something was wrong checking objects from session, abort with error
print_error('restorechecksumfailed');
}
}
//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;
// Copy $info->original_siteidentifier, is present, so backup_is_same_site can work.
if (isset($info->original_siteidentifier)) {
$restore->original_siteidentifier = $info->original_siteidentifier;
}
//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;
//Check login
require_login();
$loginurl = get_login_url();
//Check admin
if (!empty($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
$site = get_site();
$errorstr = '';
$status = restore_execute($restore,$info,$course_header,$errorstr);
if (!$status) {
print_error ("cannotrestore");
}
if (empty($restore->importing)) {
//Print final message
echo $OUTPUT->box(get_string("restorefinished"));
} else {
echo $OUTPUT->box(get_string("importdatafinished"));
$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");
}
unset($SESSION->restore);
}
echo $OUTPUT->continue_button("$CFG->wwwroot/course/view.php?id=".$restore->course_id);