source: moodle/trunk/fuentes/admin/tool/xmldb/actions/revert_changes/revert_changes.class.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 4.3 KB
Line 
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 * @package    tool_xmldb
19 * @copyright  2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
20 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21 */
22
23/**
24 * This class will revert changes (delete the editeddb)
25 *
26 * @package    tool_xmldb
27 * @copyright  2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
28 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 */
30class revert_changes extends XMLDBAction {
31
32    /**
33     * Init method, every subclass will have its own
34     */
35    function init() {
36        parent::init();
37
38        // Set own custom attributes
39
40        // Get needed strings
41        $this->loadStrings(array(
42            'confirmrevertchanges' => 'tool_xmldb',
43            'yes' => '',
44            'no' => ''
45        ));
46    }
47
48    /**
49     * Invoke method, every class will have its own
50     * returns true/false on completion, setting both
51     * errormsg and output as necessary
52     */
53    function invoke() {
54        parent::invoke();
55
56        $result = true;
57
58        // Set own core attributes
59        $this->does_generate = ACTION_GENERATE_HTML;
60
61        // These are always here
62        global $CFG, $XMLDB;
63
64        // Do the job, setting result as needed
65
66        // Get the dir containing the file
67        $dirpath = required_param('dir', PARAM_PATH);
68        $dirpath = $CFG->dirroot . $dirpath;
69
70        $confirmed = optional_param('confirmed', false, PARAM_BOOL);
71
72        // If  not confirmed, show confirmation box
73        if (!$confirmed) {
74            $o = '<table width="60" class="generaltable boxaligncenter" border="0" cellpadding="5" cellspacing="0" id="notice">';
75            $o.= '  <tr><td class="generalboxcontent">';
76            $o.= '    <p class="centerpara">' . $this->str['confirmrevertchanges'] . '<br /><br />' . $dirpath . '</p>';
77            $o.= '    <table class="boxaligncenter" cellpadding="20"><tr><td>';
78            $o.= '      <div class="singlebutton">';
79            $o.= '        <form action="index.php?action=revert_changes&amp;sesskey=' . sesskey() . '&amp;confirmed=yes&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;postaction=main_view#lastused" method="post"><fieldset class="invisiblefieldset">';
80            $o.= '          <input type="submit" value="'. $this->str['yes'] .'" /></fieldset></form></div>';
81            $o.= '      </td><td>';
82            $o.= '      <div class="singlebutton">';
83            $o.= '        <form action="index.php?action=main_view#lastused" method="post"><fieldset class="invisiblefieldset">';
84            $o.= '          <input type="submit" value="'. $this->str['no'] .'" /></fieldset></form></div>';
85            $o.= '      </td></tr>';
86            $o.= '    </table>';
87            $o.= '  </td></tr>';
88            $o.= '</table>';
89
90            $this->output = $o;
91        } else {
92            // Get the original dir and delete some elements
93            if (!empty($XMLDB->dbdirs)) {
94                if (isset($XMLDB->dbdirs[$dirpath])) {
95                    $dbdir = $XMLDB->dbdirs[$dirpath];
96                    if ($dbdir) {
97                        unset($dbdir->xml_changed);
98                    }
99                }
100            }
101            // Get the edited dir and delete it completely
102            if (!empty($XMLDB->editeddirs)) {
103                if (isset($XMLDB->editeddirs[$dirpath])) {
104                    unset($XMLDB->editeddirs[$dirpath]);
105                }
106            }
107        }
108
109        // Launch postaction if exists (leave this here!)
110        if ($this->getPostAction() && $result) {
111            return $this->launch($this->getPostAction());
112        }
113
114        // Return ok if arrived here
115        return $result;
116    }
117}
118
Note: See TracBrowser for help on using the repository browser.