MDL-41311 tool_generator: remove legacy code
[moodle.git] / admin / plugins.php
bloba092e00018942486ee284220ad919ff711ee9137
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * UI for general plugins management
21 * Supported HTTP parameters:
23 * ?fetchremote=1 - check for available updates
24 * ?updatesonly=1 - display plugins with available update only
25 * ?contribonly=1 - display non-standard add-ons only
26 * ?uninstall=foo_bar - uninstall the given plugin
27 * ?delete=foo_bar - delete the plugin folder (it must not be installed)
28 * &confirm=1 - confirm the uninstall or delete action
30 * @package core
31 * @subpackage admin
32 * @copyright 2011 David Mudrak <david@moodle.com>
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 require_once(dirname(dirname(__FILE__)) . '/config.php');
37 require_once($CFG->libdir . '/adminlib.php');
38 require_once($CFG->libdir . '/pluginlib.php');
39 require_once($CFG->libdir . '/filelib.php');
41 $fetchremote = optional_param('fetchremote', false, PARAM_BOOL);
42 $updatesonly = optional_param('updatesonly', false, PARAM_BOOL);
43 $contribonly = optional_param('contribonly', false, PARAM_BOOL);
44 $uninstall = optional_param('uninstall', '', PARAM_COMPONENT);
45 $delete = optional_param('delete', '', PARAM_COMPONENT);
46 $confirmed = optional_param('confirm', false, PARAM_BOOL);
48 // NOTE: do not use admin_externalpage_setup() here because it loads
49 // full admin tree which is not possible during uninstallation.
51 require_login();
52 $syscontext = context_system::instance();
53 require_capability('moodle/site:config', $syscontext);
55 $pluginman = plugin_manager::instance();
57 if ($uninstall) {
58 require_sesskey();
60 if (!$confirmed) {
61 admin_externalpage_setup('pluginsoverview');
62 } else {
63 $PAGE->set_url('/admin/plugins.php');
64 $PAGE->set_context($syscontext);
65 $PAGE->set_pagelayout('maintenance');
66 $PAGE->set_popup_notification_allowed(false);
69 /** @var core_admin_renderer $output */
70 $output = $PAGE->get_renderer('core', 'admin');
72 $pluginfo = $pluginman->get_plugin_info($uninstall);
74 // Make sure we know the plugin.
75 if (is_null($pluginfo)) {
76 throw new moodle_exception('err_uninstalling_unknown_plugin', 'core_plugin', '', array('plugin' => $uninstall),
77 'plugin_manager::get_plugin_info() returned null for the plugin to be uninstalled');
80 $pluginname = $pluginman->plugin_name($pluginfo->component);
81 $PAGE->set_title($pluginname);
82 $PAGE->navbar->add(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
84 if (!$pluginman->can_uninstall_plugin($pluginfo->component)) {
85 throw new moodle_exception('err_cannot_uninstall_plugin', 'core_plugin', '',
86 array('plugin' => $pluginfo->component),
87 'plugin_manager::can_uninstall_plugin() returned false');
90 if (!$confirmed) {
91 $continueurl = new moodle_url($PAGE->url, array('uninstall' => $pluginfo->component, 'sesskey' => sesskey(), 'confirm' => 1));
92 echo $output->plugin_uninstall_confirm_page($pluginman, $pluginfo, $continueurl);
93 exit();
95 } else {
96 $progress = new progress_trace_buffer(new text_progress_trace(), false);
97 $pluginman->uninstall_plugin($pluginfo->component, $progress);
98 $progress->finished();
100 if ($pluginman->is_plugin_folder_removable($pluginfo->component)) {
101 $continueurl = new moodle_url($PAGE->url, array('delete' => $pluginfo->component, 'sesskey' => sesskey(), 'confirm' => 1));
102 echo $output->plugin_uninstall_results_removable_page($pluginman, $pluginfo, $progress, $continueurl);
103 // Reset op code caches.
104 if (function_exists('opcache_reset')) {
105 opcache_reset();
107 exit();
109 } else {
110 echo $output->plugin_uninstall_results_page($pluginman, $pluginfo, $progress);
111 // Reset op code caches.
112 if (function_exists('opcache_reset')) {
113 opcache_reset();
115 exit();
120 if ($delete and $confirmed) {
121 require_sesskey();
123 $PAGE->set_url('/admin/plugins.php');
124 $PAGE->set_context($syscontext);
125 $PAGE->set_pagelayout('maintenance');
126 $PAGE->set_popup_notification_allowed(false);
128 /** @var core_admin_renderer $output */
129 $output = $PAGE->get_renderer('core', 'admin');
131 $pluginfo = $pluginman->get_plugin_info($delete);
133 // Make sure we know the plugin.
134 if (is_null($pluginfo)) {
135 throw new moodle_exception('err_removing_unknown_plugin', 'core_plugin', '', array('plugin' => $delete),
136 'plugin_manager::get_plugin_info() returned null for the plugin to be deleted');
139 $pluginname = $pluginman->plugin_name($pluginfo->component);
140 $PAGE->set_title($pluginname);
141 $PAGE->navbar->add(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
143 // Make sure it is not installed.
144 if (!is_null($pluginfo->versiondb)) {
145 throw new moodle_exception('err_removing_installed_plugin', 'core_plugin', '',
146 array('plugin' => $pluginfo->component, 'versiondb' => $pluginfo->versiondb),
147 'plugin_manager::get_plugin_info() returned not-null versiondb for the plugin to be deleted');
150 // Make sure the folder is removable.
151 if (!$pluginman->is_plugin_folder_removable($pluginfo->component)) {
152 throw new moodle_exception('err_removing_unremovable_folder', 'core_plugin', '',
153 array('plugin' => $pluginfo->component, 'rootdir' => $pluginfo->rootdir),
154 'plugin root folder is not removable as expected');
157 // Make sure the folder is within Moodle installation tree.
158 if (strpos($pluginfo->rootdir, $CFG->dirroot) !== 0) {
159 throw new moodle_exception('err_unexpected_plugin_rootdir', 'core_plugin', '',
160 array('plugin' => $pluginfo->component, 'rootdir' => $pluginfo->rootdir, 'dirroot' => $CFG->dirroot),
161 'plugin root folder not in the moodle dirroot');
164 // So long, and thanks for all the bugs.
165 fulldelete($pluginfo->rootdir);
166 // Reset op code caches.
167 if (function_exists('opcache_reset')) {
168 opcache_reset();
170 // We need to execute upgrade to make sure everything including caches is up to date.
171 redirect(new moodle_url('/admin/index.php'));
174 admin_externalpage_setup('pluginsoverview');
176 /** @var core_admin_renderer $output */
177 $output = $PAGE->get_renderer('core', 'admin');
179 $checker = available_update_checker::instance();
181 // Filtering options.
182 $options = array(
183 'updatesonly' => $updatesonly,
184 'contribonly' => $contribonly,
187 if ($fetchremote) {
188 require_sesskey();
189 $checker->fetch();
190 redirect(new moodle_url($PAGE->url, $options));
193 $deployer = available_update_deployer::instance();
194 if ($deployer->enabled()) {
195 $myurl = new moodle_url($PAGE->url, array('updatesonly' => $updatesonly, 'contribonly' => $contribonly));
196 $deployer->initialize($myurl, new moodle_url('/admin'));
198 $deploydata = $deployer->submitted_data();
199 if (!empty($deploydata)) {
200 echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata);
201 die();
205 echo $output->plugin_management_page($pluginman, $checker, $options);