MDL-39087 Implement a common interface for uninstalling general plugin
Plugins may use this general tool for uninstallation and eventually removal of the deployed source code. At the moment, this is implemented as a wrapper for the core function uninstall_plugin() with an extra hook in the relevant plugin info subclass. For non-standard add-ons, the tool can remove the deployed plugin source code as well, if the web server has required write permissions. Ideally, all add-ons installed via the new tool_installaddon should be removable via the web interface as well.
This commit is contained in:
+81
-2
@@ -27,6 +27,7 @@
|
||||
require_once(dirname(dirname(__FILE__)) . '/config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/pluginlib.php');
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
admin_externalpage_setup('pluginsoverview');
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
@@ -34,8 +35,88 @@ require_capability('moodle/site:config', context_system::instance());
|
||||
$fetchremote = optional_param('fetchremote', false, PARAM_BOOL);
|
||||
$updatesonly = optional_param('updatesonly', false, PARAM_BOOL);
|
||||
$contribonly = optional_param('contribonly', false, PARAM_BOOL);
|
||||
$uninstall = optional_param('uninstall', '', PARAM_COMPONENT);
|
||||
$delete = optional_param('delete', '', PARAM_COMPONENT);
|
||||
$confirmed = optional_param('confirm', false, PARAM_BOOL);
|
||||
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
|
||||
$pluginman = plugin_manager::instance();
|
||||
|
||||
if ($uninstall) {
|
||||
require_sesskey();
|
||||
$pluginfo = $pluginman->get_plugin_info($uninstall);
|
||||
|
||||
if (is_null($pluginfo)) {
|
||||
throw new moodle_exception('err_uninstalling_unknown_plugin', 'core_plugin', '', array('plugin' => $uninstall),
|
||||
'plugin_manager::get_plugin_info() returned null for the plugin to be uninstalled');
|
||||
}
|
||||
|
||||
$requiredby = $pluginman->other_plugins_that_require($pluginfo->component);
|
||||
if (!empty($requiredby)) {
|
||||
throw new moodle_exception('err_uninstalling_required_plugin', 'core_plugin', '',
|
||||
array('plugin' => $pluginfo->component, 'requiredby' => implode(', ', $requiredby)),
|
||||
'plugin_manager::other_plugins_that_require() returned non-empty array');
|
||||
}
|
||||
|
||||
if (!$confirmed) {
|
||||
$continueurl = new moodle_url($PAGE->url, array('uninstall' => $pluginfo->component, 'sesskey' => sesskey(), 'confirm' => 1));
|
||||
echo $output->plugin_uninstall_confirm_page($pluginman, $pluginfo, $continueurl);
|
||||
exit();
|
||||
|
||||
} else {
|
||||
$messages = array(); // Collect uninstall process messages here.
|
||||
$pluginman->uninstall_plugin($pluginfo->component, $messages);
|
||||
|
||||
if ($pluginman->is_plugin_folder_removable($pluginfo->component)) {
|
||||
$continueurl = new moodle_url($PAGE->url, array('delete' => $pluginfo->component, 'sesskey' => sesskey(), 'confirm' => 1));
|
||||
echo $output->plugin_uninstall_results_removable_page($pluginman, $pluginfo, $messages, $continueurl);
|
||||
exit();
|
||||
|
||||
} else {
|
||||
echo $output->plugin_uninstall_results_page($pluginman, $pluginfo, $messages);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($delete and $confirmed) {
|
||||
require_sesskey();
|
||||
$pluginfo = $pluginman->get_plugin_info($delete);
|
||||
|
||||
// Make sure we know the plugin.
|
||||
if (is_null($pluginfo)) {
|
||||
throw new moodle_exception('err_removing_unknown_plugin', 'core_plugin', '', array('plugin' => $delete),
|
||||
'plugin_manager::get_plugin_info() returned null for the plugin to be deleted');
|
||||
}
|
||||
|
||||
// Make sure it is not installed.
|
||||
if (!is_null($pluginfo->versiondb)) {
|
||||
throw new moodle_exception('err_removing_installed_plugin', 'core_plugin', '',
|
||||
array('plugin' => $pluginfo->component, 'versiondb' => $pluginfo->versiondb),
|
||||
'plugin_manager::get_plugin_info() returned not-null versiondb for the plugin to be deleted');
|
||||
}
|
||||
|
||||
// Make sure the folder is removable.
|
||||
if (!$pluginman->is_plugin_folder_removable($pluginfo->component)) {
|
||||
throw new moodle_exception('err_removing_unremovable_folder', 'core_plugin', '',
|
||||
array('plugin' => $pluginfo->component, 'rootdir' => $pluginfo->rootdir),
|
||||
'plugin root folder is not removable as expected');
|
||||
}
|
||||
|
||||
// Make sure the folder is within Moodle installation tree.
|
||||
if (strpos($pluginfo->rootdir, $CFG->dirroot) !== 0) {
|
||||
throw new moodle_exception('err_unexpected_plugin_rootdir', 'core_plugin', '',
|
||||
array('plugin' => $pluginfo->component, 'rootdir' => $pluginfo->rootdir, 'dirroot' => $CFG->dirroot),
|
||||
'plugin root folder not in the moodle dirroot');
|
||||
}
|
||||
|
||||
// So long, and thanks for all the bugs.
|
||||
fulldelete($pluginfo->rootdir);
|
||||
cache::make('core', 'pluginlist')->purge();
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
|
||||
$checker = available_update_checker::instance();
|
||||
|
||||
// Filtering options.
|
||||
@@ -50,8 +131,6 @@ if ($fetchremote) {
|
||||
redirect(new moodle_url($PAGE->url, $options));
|
||||
}
|
||||
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
|
||||
$deployer = available_update_deployer::instance();
|
||||
if ($deployer->enabled()) {
|
||||
$myurl = new moodle_url($PAGE->url, array('updatesonly' => $updatesonly, 'contribonly' => $contribonly));
|
||||
|
||||
Reference in New Issue
Block a user