MDL-64506 phpunit: Update unit tests to use classic
[moodle.git] / lib / classes / plugininfo / theme.php
CommitLineData
e87214bd
PS
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 */
24namespace core\plugininfo;
25
26use moodle_url;
27
28defined('MOODLE_INTERNAL') || die();
29
30/**
31 * Class for themes
32 */
33class theme extends base {
34 public function is_uninstall_allowed() {
35 global $CFG;
36
e00f1c66 37 if ($this->name === 'boost') {
e87214bd
PS
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
f149e589
MN
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 }
e87214bd
PS
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}