Merge branch 'wip-MDL-42310-25' of git://github.com/abgreeve/moodle into MOODLE_25_STABLE
[moodle.git] / admin / plugins.php
blob08157df89d64f90bddf5942123f7ee037dbe197e
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 admin_externalpage_setup('pluginsoverview');
42 require_capability('moodle/site:config', context_system::instance());
44 $fetchremote = optional_param('fetchremote', false, PARAM_BOOL);
45 $updatesonly = optional_param('updatesonly', false, PARAM_BOOL);
46 $contribonly = optional_param('contribonly', false, PARAM_BOOL);
47 $uninstall = optional_param('uninstall', '', PARAM_COMPONENT);
48 $delete = optional_param('delete', '', PARAM_COMPONENT);
49 $confirmed = optional_param('confirm', false, PARAM_BOOL);
51 $output = $PAGE->get_renderer('core', 'admin');
53 $pluginman = plugin_manager::instance();
55 if ($uninstall) {
56 require_sesskey();
57 $pluginfo = $pluginman->get_plugin_info($uninstall);
59 // Make sure we know the plugin.
60 if (is_null($pluginfo)) {
61 throw new moodle_exception('err_uninstalling_unknown_plugin', 'core_plugin', '', array('plugin' => $uninstall),
62 'plugin_manager::get_plugin_info() returned null for the plugin to be uninstalled');
65 $pluginname = $pluginman->plugin_name($pluginfo->component);
66 $PAGE->set_title($pluginname);
67 $PAGE->navbar->add(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
69 if (!$pluginman->can_uninstall_plugin($pluginfo->component)) {
70 throw new moodle_exception('err_cannot_uninstall_plugin', 'core_plugin', '',
71 array('plugin' => $pluginfo->component),
72 'plugin_manager::can_uninstall_plugin() returned false');
75 if (!$confirmed) {
76 $continueurl = new moodle_url($PAGE->url, array('uninstall' => $pluginfo->component, 'sesskey' => sesskey(), 'confirm' => 1));
77 echo $output->plugin_uninstall_confirm_page($pluginman, $pluginfo, $continueurl);
78 exit();
80 } else {
81 $progress = new progress_trace_buffer(new text_progress_trace(), false);
82 $pluginman->uninstall_plugin($pluginfo->component, $progress);
83 $progress->finished();
85 if ($pluginman->is_plugin_folder_removable($pluginfo->component)) {
86 $continueurl = new moodle_url($PAGE->url, array('delete' => $pluginfo->component, 'sesskey' => sesskey(), 'confirm' => 1));
87 echo $output->plugin_uninstall_results_removable_page($pluginman, $pluginfo, $progress, $continueurl);
88 exit();
90 } else {
91 echo $output->plugin_uninstall_results_page($pluginman, $pluginfo, $progress);
92 exit();
97 if ($delete and $confirmed) {
98 require_sesskey();
99 $pluginfo = $pluginman->get_plugin_info($delete);
101 // Make sure we know the plugin.
102 if (is_null($pluginfo)) {
103 throw new moodle_exception('err_removing_unknown_plugin', 'core_plugin', '', array('plugin' => $delete),
104 'plugin_manager::get_plugin_info() returned null for the plugin to be deleted');
107 $pluginname = $pluginman->plugin_name($pluginfo->component);
108 $PAGE->set_title($pluginname);
109 $PAGE->navbar->add(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
111 // Make sure it is not installed.
112 if (!is_null($pluginfo->versiondb)) {
113 throw new moodle_exception('err_removing_installed_plugin', 'core_plugin', '',
114 array('plugin' => $pluginfo->component, 'versiondb' => $pluginfo->versiondb),
115 'plugin_manager::get_plugin_info() returned not-null versiondb for the plugin to be deleted');
118 // Make sure the folder is removable.
119 if (!$pluginman->is_plugin_folder_removable($pluginfo->component)) {
120 throw new moodle_exception('err_removing_unremovable_folder', 'core_plugin', '',
121 array('plugin' => $pluginfo->component, 'rootdir' => $pluginfo->rootdir),
122 'plugin root folder is not removable as expected');
125 // Make sure the folder is within Moodle installation tree.
126 if (strpos($pluginfo->rootdir, $CFG->dirroot) !== 0) {
127 throw new moodle_exception('err_unexpected_plugin_rootdir', 'core_plugin', '',
128 array('plugin' => $pluginfo->component, 'rootdir' => $pluginfo->rootdir, 'dirroot' => $CFG->dirroot),
129 'plugin root folder not in the moodle dirroot');
132 // So long, and thanks for all the bugs.
133 fulldelete($pluginfo->rootdir);
134 cache::make('core', 'pluginlist')->purge();
135 redirect($PAGE->url);
138 $checker = available_update_checker::instance();
140 // Filtering options.
141 $options = array(
142 'updatesonly' => $updatesonly,
143 'contribonly' => $contribonly,
146 if ($fetchremote) {
147 require_sesskey();
148 $checker->fetch();
149 redirect(new moodle_url($PAGE->url, $options));
152 $deployer = available_update_deployer::instance();
153 if ($deployer->enabled()) {
154 $myurl = new moodle_url($PAGE->url, array('updatesonly' => $updatesonly, 'contribonly' => $contribonly));
155 $deployer->initialize($myurl, new moodle_url('/admin'));
157 $deploydata = $deployer->submitted_data();
158 if (!empty($deploydata)) {
159 echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata);
160 die();
164 echo $output->plugin_management_page($pluginman, $checker, $options);