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 |
namespace tool_admin_presets\local\action;
|
|
|
18 |
|
|
|
19 |
defined('MOODLE_INTERNAL') || die();
|
|
|
20 |
|
|
|
21 |
use tool_admin_presets\form\export_form;
|
|
|
22 |
use moodle_exception;
|
|
|
23 |
|
|
|
24 |
global $CFG;
|
|
|
25 |
require_once($CFG->dirroot . '/lib/filelib.php');
|
|
|
26 |
require_once($CFG->dirroot . '/backup/util/xml/xml_writer.class.php');
|
|
|
27 |
require_once($CFG->dirroot . '/backup/util/xml/output/xml_output.class.php');
|
|
|
28 |
require_once($CFG->dirroot . '/backup/util/xml/output/memory_xml_output.class.php');
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* This class extends base class and handles export function.
|
|
|
32 |
*
|
|
|
33 |
* @package tool_admin_presets
|
|
|
34 |
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
|
|
|
35 |
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
|
|
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
37 |
*/
|
|
|
38 |
class export extends base {
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Shows the initial form to export/save admin settings.
|
|
|
42 |
*
|
|
|
43 |
* Loads the database configuration and prints
|
|
|
44 |
* the settings in a hierarchical table
|
|
|
45 |
*/
|
|
|
46 |
public function show(): void {
|
|
|
47 |
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'export', 'mode' => 'execute']);
|
|
|
48 |
$this->moodleform = new export_form($url);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Stores a preset into the DB.
|
|
|
53 |
*/
|
|
|
54 |
public function execute(): void {
|
|
|
55 |
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'export', 'mode' => 'execute']);
|
|
|
56 |
$this->moodleform = new export_form($url);
|
|
|
57 |
|
|
|
58 |
if ($data = $this->moodleform->get_data()) {
|
|
|
59 |
list($presetid, $settingsfound, $pluginsfound) = $this->manager->export_preset($data);
|
|
|
60 |
|
|
|
61 |
// Store it here for logging and other future id-oriented stuff.
|
|
|
62 |
$this->id = $presetid;
|
|
|
63 |
|
|
|
64 |
// If there are no settings nor plugins, an error should be raised.
|
|
|
65 |
if (!$settingsfound && !$pluginsfound) {
|
|
|
66 |
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'export']);
|
|
|
67 |
redirect($url, get_string('novalidsettingsselected', 'tool_admin_presets'));
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
// Trigger the as it is usually triggered after execute finishes.
|
|
|
72 |
$this->log();
|
|
|
73 |
|
|
|
74 |
$url = new \moodle_url('/admin/tool/admin_presets/index.php');
|
|
|
75 |
redirect($url);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* To download system presets.
|
|
|
80 |
*
|
|
|
81 |
* @return void preset file
|
|
|
82 |
* @throws dml_exception
|
|
|
83 |
* @throws moodle_exception
|
|
|
84 |
* @throws xml_output_exception
|
|
|
85 |
* @throws xml_writer_exception
|
|
|
86 |
*/
|
|
|
87 |
public function download_xml(): void {
|
|
|
88 |
require_sesskey();
|
|
|
89 |
|
|
|
90 |
list($xmlstr, $filename) = $this->manager->download_preset($this->id);
|
|
|
91 |
|
|
|
92 |
// Trigger the as it is usually triggered after execute finishes.
|
|
|
93 |
$this->log();
|
|
|
94 |
|
|
|
95 |
send_file($xmlstr, $filename, 0, 0, true, true);
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
protected function get_explanatory_description(): ?string {
|
|
|
99 |
return get_string('exportdescription', 'tool_admin_presets');
|
|
|
100 |
}
|
|
|
101 |
}
|