Permalink
Browse files

MDL-32009 messaging: Add message processor uninstall functionality

  • Loading branch information...
1 parent 6f4f0b5 commit 0210ce10077f10fb0f92e4a0b50758e943eb838f Ruslan Kabalin committed Aug 5, 2011
Showing with 45 additions and 3 deletions.
  1. +31 −3 admin/message.php
  2. +2 −0 lang/en/message.php
  3. +1 −0 lib/messagelib.php
  4. +11 −0 lib/pluginlib.php
View
34 admin/message.php
@@ -24,6 +24,7 @@
require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->dirroot . '/message/lib.php');
require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->libdir.'/messagelib.php');
// This is an admin page
admin_externalpage_setup('managemessageoutputs');
@@ -34,6 +35,10 @@
// Get the submitted params
$disable = optional_param('disable', 0, PARAM_INT);
$enable = optional_param('enable', 0, PARAM_INT);
+$uninstall = optional_param('uninstall', '', PARAM_INT);
+$confirm = optional_param('confirm', 0, PARAM_BOOL);
+
+$headingtitle = get_string('managemessageoutputs', 'message');
if (!empty($disable) && confirm_sesskey()) {
if (!$processor = $DB->get_record('message_processors', array('id'=>$disable))) {
@@ -42,14 +47,37 @@
$DB->set_field('message_processors', 'enabled', '0', array('id'=>$processor->id)); // Disable output
}
-if (!empty($enable) && confirm_sesskey() ) {
+if (!empty($enable) && confirm_sesskey()) {
if (!$processor = $DB->get_record('message_processors', array('id'=>$enable))) {
print_error('outputdoesnotexist', 'message');
}
$DB->set_field('message_processors', 'enabled', '1', array('id'=>$processor->id)); // Enable output
}
-if ($disable || $enable) {
+if (!empty($uninstall) && confirm_sesskey()) {
+ echo $OUTPUT->header();
+ echo $OUTPUT->heading($headingtitle);
+
+ if (!$processor = $DB->get_record('message_processors', array('id'=>$uninstall))) {
+ print_error('outputdoesnotexist', 'message');
+ }
+
+ $processorname = get_string('pluginname', 'message_'.$processor->name);
+
+ if (!$confirm) {
+ echo $OUTPUT->confirm(get_string('processordeleteconfirm', 'message', $processorname), 'message.php?uninstall='.$processor->id.'&confirm=1', 'message.php');
+ echo $OUTPUT->footer();
+ exit;
+
+ } else {
+ message_processor_uninstall($processor->name);
+ $a->processor = $processorname;
+ $a->directory = $CFG->dirroot.'/message/output/'.$processor->name;
+ notice(get_string('processordeletefiles', 'message', $a), 'message.php');
+ }
+}
+
+if ($disable || $enable || $uninstall) {
$url = new moodle_url('message.php');
redirect($url);
}
@@ -65,6 +93,6 @@
// Display the page
echo $OUTPUT->header();
-echo $OUTPUT->heading(get_string('managemessageoutputs', 'message'));
+echo $OUTPUT->heading($headingtitle);
echo $messageoutputs;
echo $OUTPUT->footer();
View
2 lang/en/message.php
@@ -109,6 +109,8 @@
$string['page-message-x'] = 'Any message pages';
$string['private_config'] = 'Popup message window';
$string['processortag'] = 'Destination';
+$string['processordeleteconfirm'] = 'You are about to completely delete message processor \'{$a}\'. This will completely delete everything in the database associated with this processor. Are you SURE you want to continue?';
+$string['processordeletefiles'] = 'All data associated with the processor \'{$a->processor}\' has been deleted from the database. To complete the deletion (and prevent the processor re-installing itself), you should now delete this directory from your server: {$a->directory}';
$string['providers_config'] = 'Configure notification methods for incoming messages';
$string['providerstag'] = 'Source';
$string['recent'] = 'Recent';
View
1 lib/messagelib.php
@@ -477,6 +477,7 @@ function message_processor_uninstall($name) {
$transaction = $DB->start_delegated_transaction();
$DB->delete_records('message_processors', array('name' => $name));
+ $DB->delete_records_select('config_plugins', "plugin = ?", array("message_{$name}"));
// delete permission preferences only, we do not care about loggedin/loggedoff
// defaults, they will be removed on the next attempt to update the preferences
$DB->delete_records_select('config_plugins', "plugin = 'message' AND ".$DB->sql_like('name', '?', false), array("{$name}_provider_%"));
View
11 lib/pluginlib.php
@@ -1563,6 +1563,17 @@ public function is_enabled() {
return parent::is_enabled();
}
}
+
+ /**
+ * @see plugintype_interface::get_uninstall_url()
+ */
+ public function get_uninstall_url() {
+ if (isset($this->processors[$this->name])) {
+ return new moodle_url('message.php', array('uninstall' => $this->processors[$this->name]->id, 'sesskey' => sesskey()));
+ } else {
+ return parent::get_uninstall_url();
+ }
+ }
}
/**

0 comments on commit 0210ce1

Please sign in to comment.