Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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   * Defines classes used for plugin info.
  19   *
  20   * @package    core
  21   * @copyright  2013 Petr Skoda {@link http://skodak.org}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core\plugininfo;
  25  
  26  use moodle_url;
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  /**
  31   * Class for themes
  32   */
  33  class theme extends base {
  34      public function is_uninstall_allowed() {
  35          global $CFG;
  36  
  37          if ($this->name === 'boost') {
  38              // All of these are protected for now.
  39              return false;
  40          }
  41  
  42          if (!empty($CFG->theme) and $CFG->theme === $this->name) {
  43              // Cannot uninstall default theme.
  44              return false;
  45          }
  46  
  47          return true;
  48      }
  49  
  50      /**
  51       * Pre-uninstall hook.
  52       *
  53       * This is intended for disabling of plugin, some DB table purging, etc.
  54       *
  55       * NOTE: to be called from uninstall_plugin() only.
  56       * @private
  57       */
  58      public function uninstall_cleanup() {
  59          global $DB;
  60  
  61          $DB->set_field('course', 'theme', '', array('theme'=>$this->name));
  62          $DB->set_field('course_categories', 'theme', '', array('theme'=>$this->name));
  63          $DB->set_field('user', 'theme', '', array('theme'=>$this->name));
  64          $DB->set_field('mnet_host', 'theme', '', array('theme'=>$this->name));
  65  
  66          if (get_config('core', 'thememobile') === $this->name) {
  67              unset_config('thememobile');
  68          }
  69          if (get_config('core', 'themetablet') === $this->name) {
  70              unset_config('themetablet');
  71          }
  72          if (get_config('core', 'themelegacy') === $this->name) {
  73              unset_config('themelegacy');
  74          }
  75  
  76          $themelist = get_config('core', 'themelist');
  77          if (!empty($themelist)) {
  78              $themes = explode(',', $themelist);
  79              $key = array_search($this->name, $themes);
  80              if ($key !== false) {
  81                  unset($themes[$key]);
  82                  set_config('themelist', implode(',', $themes));
  83              }
  84          }
  85  
  86          parent::uninstall_cleanup();
  87      }
  88  
  89      /**
  90       * Return URL used for management of plugins of this type.
  91       * @return moodle_url
  92       */
  93      public static function get_manage_url() {
  94          return new moodle_url('/theme/index.php');
  95      }
  96  }