Skip to content

Commit

Permalink
MDL-39088 migrate module uninstallation to plugin_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jun 27, 2013
1 parent ba7ce5e commit cd79930
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 40 deletions.
39 changes: 4 additions & 35 deletions admin/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -136,7 +102,10 @@
$missing = false;
}

$delete = "<a href=\"modules.php?delete=$module->name&amp;sesskey=".sesskey()."\">$strdelete</a>";
$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")) {
Expand Down
2 changes: 0 additions & 2 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions lang/en/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
25 changes: 23 additions & 2 deletions lib/pluginlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<p>'.get_string('uninstallextraconfirmmod', 'core_plugin', array('instances'=>$count, 'courses'=>$courses)).'</p>';
}

/**
Expand Down
1 change: 0 additions & 1 deletion mod/forum/lang/en/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit cd79930

Please sign in to comment.