-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestore.php
103 lines (89 loc) · 3.61 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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package block_simple_restore
* @copyright 2008 onwards Louisiana State University
* @copyright 2008 onwards Chad Mazilly, Robert Russo, Jason Peak, Dave Elliott, Adam Zapletal, Philip Cali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once($CFG->dirroot . '/blocks/simple_restore/lib.php');
$contextid = required_param('contextid', PARAM_INT);
$filename = required_param('filename', PARAM_FILE);
$restoreto = optional_param('restore_to', 0, PARAM_INT);
$confirm = optional_param('confirm', 0, PARAM_INT);
$loading = optional_param('loading', 0, PARAM_INT);
$archivemode = get_config('simple_restore', 'is_archive_server') == 1 && $restoreto == 2;
list($context, $course, $cm) = get_context_info_array($contextid);
$blockname = get_string('pluginname', 'block_simple_restore');
$restoreheading = simple_restore_utils::heading($restoreto);
$PAGE->set_url(new moodle_url('/blocks/simple_restore/restore.php', array(
'contextid' => $contextid)
));
$PAGE->set_context($context);
$PAGE->set_course($course);
$PAGE->navbar->add($restoreheading);
$PAGE->set_title($blockname . ': ' . $restoreheading);
$PAGE->set_heading($blockname . ': ' . $restoreheading);
// Check requirements according to restore mode.
if ($archivemode) {
require_login();
require_capability('block/simple_restore:canrestorearchive', $context);
} else {
require_login($course, null, $cm);
require_capability('block/simple_restore:canrestore', $context);
}
$restore = new simple_restore($course, $filename, $restoreto);
$header = $course->fullname;
if (!$confirm) {
echo $OUTPUT->header();
echo $OUTPUT->heading($header);
$confirmstr = simple_restore_utils::_s('confirm_message',
'<strong>'.$restoreheading.'</strong>'
);
$confirmurl = new moodle_url('restore.php', array(
'contextid' => $contextid,
'restore_to' => $restoreto,
'confirm' => 1,
'filename' => $filename
));
$cancelurl = new moodle_url('list.php', array(
'id' => $course->id,
'restore_to' => $restoreto
));
echo $OUTPUT->confirm($confirmstr, $confirmurl, $cancelurl);
echo $OUTPUT->footer();
}
// This conditional returns html content for the ajax reponse.
if ($confirm and data_submitted()) {
echo $OUTPUT->header();
echo $OUTPUT->heading($header);
try {
$restore->execute();
echo $OUTPUT->notification(
get_string('restoreexecutionsuccess', 'backup'), 'notifysuccess'
);
} catch (Exception $e) {
$a = $e->getMessage();
echo $OUTPUT->notification(simple_restore_utils::_s('no_restore', $a));
// In case of an aborted archive restore, the 'new' course will have been deleted.
$course->id = $archivemode == 1 ? 1 : $course->id;
}
echo $OUTPUT->continue_button(
new moodle_url('/course/view.php', array('id' => $course->id))
);
echo $OUTPUT->footer();
}