mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-20191 more plugin uninstall cleanup and improvements
This commit is contained in:
parent
c927b7cf8e
commit
2138244c03
1 changed files with 20 additions and 36 deletions
|
@ -131,13 +131,8 @@ function uninstall_plugin($type, $name) {
|
||||||
global $CFG, $DB, $OUTPUT;
|
global $CFG, $DB, $OUTPUT;
|
||||||
|
|
||||||
// recursively uninstall all the subplugins first
|
// recursively uninstall all the subplugins first
|
||||||
try {
|
|
||||||
$subpluginlocations = plugin_supports($type, $name, FEATURE_MOD_SUBPLUGINS);
|
$subpluginlocations = plugin_supports($type, $name, FEATURE_MOD_SUBPLUGINS);
|
||||||
} catch (Exception $e) {
|
if (is_array($subpluginlocations)) {
|
||||||
// the plugin does not support plugin_supports() yet - this is probably a subplugin
|
|
||||||
$subpluginlocations = null;
|
|
||||||
}
|
|
||||||
if (!empty($subpluginlocations)) {
|
|
||||||
foreach ($subpluginlocations as $subplugintype => $notusedlocationpath) {
|
foreach ($subpluginlocations as $subplugintype => $notusedlocationpath) {
|
||||||
$subplugins = get_plugin_list($subplugintype);
|
$subplugins = get_plugin_list($subplugintype);
|
||||||
foreach ($subplugins as $subpluginname => $notusedpluginpath) {
|
foreach ($subplugins as $subpluginname => $notusedpluginpath) {
|
||||||
|
@ -146,17 +141,24 @@ function uninstall_plugin($type, $name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$pluginname = $type . '_' . $name; // eg. 'qtype_multichoice' or 'workshopgrading_accumulative'
|
$component = $type . '_' . $name; // eg. 'qtype_multichoice' or 'workshopgrading_accumulative' or 'mod_forum'
|
||||||
|
|
||||||
|
if ($type === 'mod') {
|
||||||
|
$pluginname = $name; // eg. 'forum'
|
||||||
|
$strpluginname = get_string('modulename', $pluginname);
|
||||||
|
} else {
|
||||||
|
$pluginname = $component;
|
||||||
$strpluginname = get_string('pluginname', $pluginname); // replaces string 'modulename'
|
$strpluginname = get_string('pluginname', $pluginname); // replaces string 'modulename'
|
||||||
|
}
|
||||||
echo $OUTPUT->heading($pluginname);
|
echo $OUTPUT->heading($pluginname);
|
||||||
|
|
||||||
$plugindirectory = get_plugin_directory($type, $name);
|
$plugindirectory = get_plugin_directory($type, $name);
|
||||||
$uninstalllib = $plugindirectory . '/db/uninstall.php';
|
$uninstalllib = $plugindirectory . '/db/uninstall.php';
|
||||||
if (file_exists($uninstalllib)) {
|
if (file_exists($uninstalllib)) {
|
||||||
require_once($uninstalllib);
|
require_once($uninstalllib);
|
||||||
$uninstallfunction = $pluginname . '_uninstall'; // eg. 'mod_workshop_uninstall()'
|
$uninstallfunction = 'xmldb_' . $pluginname . '_uninstall'; // eg. 'xmldb_workshop_uninstall()'
|
||||||
if (function_exists($uninstallfunction)) {
|
if (function_exists($uninstallfunction)) {
|
||||||
if (! $uninstallfunction() ) {
|
if (!$uninstallfunction()) {
|
||||||
echo $OUTPUT->notification('Encountered a problem running uninstall function for '. $pluginname);
|
echo $OUTPUT->notification('Encountered a problem running uninstall function for '. $pluginname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,9 +167,6 @@ function uninstall_plugin($type, $name) {
|
||||||
if ('mod' === $type) {
|
if ('mod' === $type) {
|
||||||
// perform cleanup tasks specific for activity modules
|
// perform cleanup tasks specific for activity modules
|
||||||
|
|
||||||
$pluginname = $name; // activity modules are expceptions for historical reasons
|
|
||||||
$strpluginname = get_string('modulename', $pluginname); // exception again - to be replaced in all langpacks
|
|
||||||
|
|
||||||
if (!$module = $DB->get_record('modules', array('name' => $name))) {
|
if (!$module = $DB->get_record('modules', array('name' => $name))) {
|
||||||
print_error('moduledoesnotexist', 'error');
|
print_error('moduledoesnotexist', 'error');
|
||||||
}
|
}
|
||||||
|
@ -190,9 +189,7 @@ function uninstall_plugin($type, $name) {
|
||||||
$DB->execute($sql, array($module->id));
|
$DB->execute($sql, array($module->id));
|
||||||
|
|
||||||
// delete all the course module records
|
// delete all the course module records
|
||||||
if (!$DB->delete_records('course_modules', array('module' => $module->id))) {
|
$DB->delete_records('course_modules', array('module' => $module->id));
|
||||||
echo $OUTPUT->notification("Error occurred while deleting all $strpluginname records in course_modules table");
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete module contexts
|
// delete module contexts
|
||||||
if ($coursemods) {
|
if ($coursemods) {
|
||||||
|
@ -204,9 +201,7 @@ function uninstall_plugin($type, $name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete the module entry itself
|
// delete the module entry itself
|
||||||
if (!$DB->delete_records('modules', array('name' => $module->name))) {
|
$DB->delete_records('modules', array('name' => $module->name));
|
||||||
echo $OUTPUT->notification("Error occurred while deleting the $strpluginname record from modules table");
|
|
||||||
}
|
|
||||||
|
|
||||||
// cleanup the gradebook
|
// cleanup the gradebook
|
||||||
require_once($CFG->libdir.'/gradelib.php');
|
require_once($CFG->libdir.'/gradelib.php');
|
||||||
|
@ -218,7 +213,7 @@ function uninstall_plugin($type, $name) {
|
||||||
$uninstallfunction = $module->name . '_uninstall';
|
$uninstallfunction = $module->name . '_uninstall';
|
||||||
if (function_exists($uninstallfunction)) {
|
if (function_exists($uninstallfunction)) {
|
||||||
debugging("{$uninstallfunction}() has been deprecated. Use the plugin's db/uninstall.php instead", DEBUG_DEVELOPER);
|
debugging("{$uninstallfunction}() has been deprecated. Use the plugin's db/uninstall.php instead", DEBUG_DEVELOPER);
|
||||||
if (! $uninstallfunction() ) {
|
if (!$uninstallfunction()) {
|
||||||
echo $OUTPUT->notification('Encountered a problem running uninstall function for '. $module->name.'!');
|
echo $OUTPUT->notification('Encountered a problem running uninstall function for '. $module->name.'!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,32 +223,21 @@ function uninstall_plugin($type, $name) {
|
||||||
// perform clean-up taks common for all the plugin/subplugin types
|
// perform clean-up taks common for all the plugin/subplugin types
|
||||||
|
|
||||||
// delete calendar events
|
// delete calendar events
|
||||||
if (!$DB->delete_records('event', array('modulename' => $pluginname))) {
|
$DB->delete_records('event', array('modulename' => $pluginname));
|
||||||
echo $OUTPUT->notification("Error occurred while deleting all $strpluginname records in calendar event table");
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete all the logs
|
// delete all the logs
|
||||||
if (!$DB->delete_records('log', array('module' => $pluginname))) {
|
$DB->delete_records('log', array('module' => $pluginname));
|
||||||
echo $OUTPUT->notification("Error occurred while deleting all $strpluginname records in log table");
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete log_display information
|
// delete log_display information
|
||||||
if (!$DB->delete_records('log_display', array('module' => $pluginname))) {
|
$DB->delete_records('log_display', array('module' => $pluginname));
|
||||||
echo $OUTPUT->notification("Error occurred while deleting all $strpluginname records in log_display table");
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete the module configuration records
|
// delete the module configuration records
|
||||||
if (!unset_all_config_for_plugin($pluginname)) {
|
unset_all_config_for_plugin($pluginname);
|
||||||
echo $OUTPUT->notification(get_string('errordeletingconfig', 'admin', $strpluginname));
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete the plugin tables
|
// delete the plugin tables
|
||||||
$xmldbfilepath = $plugindirectory . '/db/install.xml';
|
$xmldbfilepath = $plugindirectory . '/db/install.xml';
|
||||||
drop_plugin_tables($pluginname, $xmldbfilepath, false);
|
drop_plugin_tables($pluginname, $xmldbfilepath, false);
|
||||||
|
|
||||||
// the following functions do not accept $pluginname
|
|
||||||
$component = get_plugin_directory($type, $name, false); // eg. 'mod/forum'
|
|
||||||
|
|
||||||
// delete the capabilities that were defined by this module
|
// delete the capabilities that were defined by this module
|
||||||
capabilities_cleanup($component);
|
capabilities_cleanup($component);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue