From cd79930e4ddfcdcd107a69f0a6e812ae3efa5cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Wed, 26 Jun 2013 13:30:24 +0200 Subject: [PATCH] MDL-39088 migrate module uninstallation to plugin_manager --- admin/modules.php | 39 ++++--------------------------------- lang/en/moodle.php | 2 -- lang/en/plugin.php | 1 + lib/pluginlib.php | 25 ++++++++++++++++++++++-- mod/forum/lang/en/forum.php | 1 - 5 files changed, 28 insertions(+), 40 deletions(-) diff --git a/admin/modules.php b/admin/modules.php index 33d2fbbff4e47..1364321b63974 100644 --- a/admin/modules.php +++ b/admin/modules.php @@ -13,8 +13,6 @@ $show = optional_param('show', '', PARAM_PLUGIN); $hide = optional_param('hide', '', PARAM_PLUGIN); - $delete = optional_param('delete', '', PARAM_PLUGIN); - $confirm = optional_param('confirm', '', PARAM_BOOL); /// Print headings @@ -73,38 +71,6 @@ admin_get_root(true, false); // settings not required - only pages } - if (!empty($delete) and confirm_sesskey()) { - echo $OUTPUT->header(); - echo $OUTPUT->heading($stractivities); - - if (get_string_manager()->string_exists('modulename', $delete)) { - $strmodulename = get_string('modulename', $delete); - } else { - $strmodulename = $delete; - } - - if (!$confirm) { - echo $OUTPUT->confirm(get_string("moduledeleteconfirm", "", $strmodulename), "modules.php?delete=$delete&confirm=1", "modules.php"); - echo $OUTPUT->footer(); - exit; - - } else { // Delete everything!! - - if ($delete == "forum") { - print_error("cannotdeleteforummodule", 'forum'); - } - - uninstall_plugin('mod', $delete); - $a = new stdClass(); - $a->module = $strmodulename; - $a->directory = "$CFG->dirroot/mod/$delete"; - echo $OUTPUT->notification(get_string("moduledeletefiles", "", $a), 'notifysuccess'); - echo $OUTPUT->continue_button("modules.php"); - echo $OUTPUT->footer(); - exit; - } - } - echo $OUTPUT->header(); echo $OUTPUT->heading($stractivities); @@ -136,7 +102,10 @@ $missing = false; } - $delete = "name&sesskey=".sesskey()."\">$strdelete"; + $delete = ''; + if ($deleteurl = plugin_manager::instance()->get_uninstall_url('mod_'.$module->name)) { + $delete = html_writer::link($deleteurl, $strdelete); + } if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") || file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) { diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 0ff10e41d7e74..474d7bb7f3a42 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1056,8 +1056,6 @@ $string['modified'] = 'Modified'; $string['modchooserenable'] = 'Activity chooser on'; $string['modchooserdisable'] = 'Activity chooser off'; -$string['moduledeleteconfirm'] = 'You are about to completely delete the module \'{$a}\'. This will completely delete everything in the database associated with this activity module. Are you SURE you want to continue?'; -$string['moduledeletefiles'] = 'All data associated with the module \'{$a->module}\' has been deleted from the database. To complete the deletion (and prevent the module re-installing itself), you should now delete this directory from your server: {$a->directory}'; $string['moduleintro'] = 'Description'; $string['modulesetup'] = 'Setting up module tables'; $string['modulesuccess'] = '{$a} tables have been set up correctly'; diff --git a/lang/en/plugin.php b/lang/en/plugin.php index 0b17af6da148a..e65e1ea7f186e 100644 --- a/lang/en/plugin.php +++ b/lang/en/plugin.php @@ -153,6 +153,7 @@ $string['uninstalldeleteconfirmexternal'] = 'It appears that the current version of the plugin has been obtained via source code management system ({$a}) checkout. If you remove the plugin folder, you may loose important local modifications of the code. Please ensure that you definitely want to remove the plugin folder before continuing.'; $string['uninstallextraconfirmblock'] = 'There are {$a->instances} instances of this block.'; $string['uninstallextraconfirmenrol'] = 'There are {$a->enrolments} user enrolments.'; +$string['uninstallextraconfirmmod'] = 'There are {$a->instances} instances of this module in {$a->courses} courses.'; $string['uninstalling'] = 'Uninstalling {$a->name}'; $string['version'] = 'Version'; $string['versiondb'] = 'Current version'; diff --git a/lib/pluginlib.php b/lib/pluginlib.php index e82c6882b2bdf..3be9fc4b579dd 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -3423,8 +3423,29 @@ public function is_uninstall_allowed() { } } - public function get_uninstall_url() { - return new moodle_url('/admin/modules.php', array('delete' => $this->name, 'sesskey' => sesskey())); + /** + * Return warning with number of activities and number of affected courses. + * + * @return string + */ + public function get_uninstall_extra_warning() { + global $DB; + + if (!$module = $DB->get_record('modules', array('name'=>$this->name))) { + return ''; + } + + if (!$count = $DB->count_records('course_modules', array('module'=>$module->id))) { + return ''; + } + + $sql = "SELECT COUNT(course) + FROM {course_modules} + WHERE module = :mid + GROUP BY course"; + $courses = $DB->count_records_sql($sql, array('mid'=>$module->id)); + + return '

'.get_string('uninstallextraconfirmmod', 'core_plugin', array('instances'=>$count, 'courses'=>$courses)).'

'; } /** diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index 111a31fa17a0b..d3cc361d12af2 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -57,7 +57,6 @@ $string['cannotaddteacherforumto'] = 'Could not add converted teacher forum instance to section 0 in the course'; $string['cannotcreatediscussion'] = 'Could not create new discussion'; $string['cannotcreateinstanceforteacher'] = 'Could not create new course module instance for the teacher forum'; -$string['cannotdeleteforummodule'] = 'You can not delete the forum module.'; $string['cannotdeletepost'] = 'You can\'t delete this post!'; $string['cannoteditposts'] = 'You can\'t edit other people\'s posts!'; $string['cannotfinddiscussion'] = 'Could not find the discussion in this forum';