1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* A helper to create a stored file for the restore process to use.
|
|
|
19 |
*
|
|
|
20 |
* @package report_allbackups
|
|
|
21 |
* @copyright 2020 Catalyst IT
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once('../../config.php');
|
|
|
26 |
|
|
|
27 |
$filename = required_param('filename', PARAM_FILE);
|
|
|
28 |
require_login();
|
|
|
29 |
require_all_capabilities(array('report/allbackups:view', 'moodle/restore:restorecourse'), context_system::instance());
|
|
|
30 |
|
|
|
31 |
// Create file based on filename.
|
|
|
32 |
// Make sure backup dir is set.
|
|
|
33 |
$backupdest = get_config('backup', 'backup_auto_destination');
|
|
|
34 |
if (empty($backupdest) || pathinfo($filename, PATHINFO_EXTENSION) != 'mbz') {
|
|
|
35 |
redirect($CFG->wwwroot);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
$file = $backupdest . '/' . $filename;
|
|
|
39 |
if (is_readable($file)) {
|
|
|
40 |
$fs = get_file_storage();
|
|
|
41 |
$record = (object)[
|
|
|
42 |
'filearea' => 'draft',
|
|
|
43 |
'component' => 'user',
|
|
|
44 |
'filepath' => '/',
|
|
|
45 |
'itemid' => file_get_unused_draft_itemid(),
|
|
|
46 |
'license' => $CFG->sitedefaultlicense,
|
|
|
47 |
'author' => '',
|
|
|
48 |
'filename' => $filename,
|
|
|
49 |
'contextid' => \context_user::instance($USER->id)->id,
|
|
|
50 |
'userid' => $USER->id,
|
|
|
51 |
];
|
|
|
52 |
$storedfile = $fs->create_file_from_pathname($record, $file);
|
|
|
53 |
|
|
|
54 |
$params = array();
|
|
|
55 |
$params['action'] = 'choosebackupfile';
|
|
|
56 |
$params['filename'] = $filename;
|
|
|
57 |
$params['filepath'] = '/';
|
|
|
58 |
$params['component'] = 'user';
|
|
|
59 |
$params['filearea'] = 'draft';
|
|
|
60 |
$params['filecontextid'] = \context_user::instance($USER->id)->id;
|
|
|
61 |
$params['contextid'] = \context_user::instance($USER->id)->id;
|
|
|
62 |
$params['itemid'] = $record->itemid;
|
|
|
63 |
$restoreurl = new moodle_url('/backup/restorefile.php', $params);
|
|
|
64 |
redirect($restoreurl);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
redirect($CFG->wwwroot);
|