Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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 unload one loaded file completely
  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   */
  30  class unload_xml_file extends XMLDBAction {
  31  
  32      /**
  33       * Init method, every subclass will have its own
  34       */
  35      function init() {
  36          parent::init();
  37  
  38          // Get needed strings
  39          $this->loadStrings(array(
  40              // 'key' => 'module',
  41          ));
  42      }
  43  
  44      /**
  45       * Invoke method, every class will have its own
  46       * returns true/false on completion, setting both
  47       * errormsg and output as necessary
  48       */
  49      function invoke() {
  50          parent::invoke();
  51  
  52          $result = true;
  53  
  54          // Set own core attributes
  55          $this->does_generate = ACTION_NONE;
  56  
  57          // These are always here
  58          global $CFG, $XMLDB;
  59  
  60          // Do the job, setting result as needed
  61  
  62          // Get the dir containing the file
  63          $dirpath = required_param('dir', PARAM_PATH);
  64          $dirpath = $CFG->dirroot . $dirpath;
  65  
  66          // Get the original dir and delete some elements
  67          if (!empty($XMLDB->dbdirs)) {
  68              if (isset($XMLDB->dbdirs[$dirpath])) {
  69                  $dbdir = $XMLDB->dbdirs[$dirpath];
  70                  if ($dbdir) {
  71                      unset($dbdir->xml_file);
  72                      unset($dbdir->xml_loaded);
  73                      unset($dbdir->xml_changed);
  74                      unset($dbdir->xml_exists);
  75                      unset($dbdir->xml_writeable);
  76                  }
  77              }
  78          }
  79          // Get the edited dir and delete it completely
  80          if (!empty($XMLDB->editeddirs)) {
  81              if (isset($XMLDB->editeddirs[$dirpath])) {
  82                  unset($XMLDB->editeddirs[$dirpath]);
  83              }
  84          }
  85  
  86          // Launch postaction if exists (leave this here!)
  87          if ($this->getPostAction() && $result) {
  88              return $this->launch($this->getPostAction());
  89          }
  90  
  91          // Return ok if arrived here
  92          return $result;
  93      }
  94  }
  95