See Release Notes
Long Term Support Release
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 confirm_sesskey(); 56 57 $url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'export', 'mode' => 'execute']); 58 $this->moodleform = new export_form($url); 59 60 if ($data = $this->moodleform->get_data()) { 61 list($presetid, $settingsfound, $pluginsfound) = $this->manager->export_preset($data); 62 63 // Store it here for logging and other future id-oriented stuff. 64 $this->id = $presetid; 65 66 // If there are no settings nor plugins, an error should be raised. 67 if (!$settingsfound && !$pluginsfound) { 68 $url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'export']); 69 redirect($url, get_string('novalidsettingsselected', 'tool_admin_presets')); 70 } 71 } 72 73 // Trigger the as it is usually triggered after execute finishes. 74 $this->log(); 75 76 $url = new \moodle_url('/admin/tool/admin_presets/index.php'); 77 redirect($url); 78 } 79 80 /** 81 * To download system presets. 82 * 83 * @return void preset file 84 * @throws dml_exception 85 * @throws moodle_exception 86 * @throws xml_output_exception 87 * @throws xml_writer_exception 88 */ 89 public function download_xml(): void { 90 confirm_sesskey(); 91 92 list($xmlstr, $filename) = $this->manager->download_preset($this->id); 93 94 // Trigger the as it is usually triggered after execute finishes. 95 $this->log(); 96 97 send_file($xmlstr, $filename, 0, 0, true, true); 98 } 99 100 protected function get_explanatory_description(): ?string { 101 return get_string('exportdescription', 'tool_admin_presets'); 102 } 103 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body