From 26d859e0ecd49ee32b5b0d414c9a119281db9b48 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Fri, 9 Mar 2012 16:18:58 +0000 Subject: [PATCH 1/3] MDL-32009 messaging: Refator get_settings_url plugintype method No need to duplicate checks since we have them in one place. --- lib/pluginlib.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 9d788a765ed..b2be2b9c7da 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -1529,16 +1529,28 @@ class plugintype_enrol extends plugintype_base implements plugin_information { */ class plugintype_message extends plugintype_base implements plugin_information { + private $processors; + + protected function __construct() { + global $CFG; + require_once($CFG->dirroot . '/message/lib.php'); + $this->processors = get_message_processors(); + } + /** * @see plugin_information::get_settings_url() */ public function get_settings_url() { - if (file_exists($this->full_path('settings.php')) or file_exists($this->full_path('settingstree.php'))) { - return new moodle_url('/admin/settings.php', array('section' => 'messagesetting' . $this->name)); + if (isset($this->processors[$this->name])) { + $processor = $this->processors[$this->name]; } else { return parent::get_settings_url(); } + + if ($processor->available && $processor->hassettings) { + return new moodle_url('settings.php', array('section' => 'messagesetting'.$processor->name)); + } } } From 6f4f0b5228bc9354cc95233806cf11421b4fc098 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Mon, 12 Mar 2012 15:02:16 +0000 Subject: [PATCH 2/3] MDL-32009 messaging: Add is_enabled method to plugintype_message --- lib/pluginlib.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/pluginlib.php b/lib/pluginlib.php index b2be2b9c7da..7b7259dfcc5 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -1552,6 +1552,17 @@ class plugintype_message extends plugintype_base implements plugin_information { return new moodle_url('settings.php', array('section' => 'messagesetting'.$processor->name)); } } + + /** + * @see plugintype_interface::is_enabled() + */ + public function is_enabled() { + if (isset($this->processors[$this->name])) { + return $this->processors[$this->name]->configured && $this->processors[$this->name]->enabled; + } else { + return parent::is_enabled(); + } + } } /** From 0210ce10077f10fb0f92e4a0b50758e943eb838f Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Fri, 5 Aug 2011 14:01:38 +0100 Subject: [PATCH 3/3] MDL-32009 messaging: Add message processor uninstall functionality --- admin/message.php | 34 +++++++++++++++++++++++++++++++--- lang/en/message.php | 2 ++ lib/messagelib.php | 1 + lib/pluginlib.php | 11 +++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/admin/message.php b/admin/message.php index 8daf613defa..fde314de43f 100644 --- a/admin/message.php +++ b/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 @@ require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); // 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 @@ if (!empty($disable) && confirm_sesskey()) { $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 @@ $messageoutputs = $renderer->manage_messageoutputs($processors); // Display the page echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('managemessageoutputs', 'message')); +echo $OUTPUT->heading($headingtitle); echo $messageoutputs; echo $OUTPUT->footer(); \ No newline at end of file diff --git a/lang/en/message.php b/lang/en/message.php index 60993bc4ca6..ee4c015a07e 100644 --- a/lang/en/message.php +++ b/lang/en/message.php @@ -109,6 +109,8 @@ $string['permitted'] = 'Permitted'; $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'; diff --git a/lib/messagelib.php b/lib/messagelib.php index 9619b96d88f..b2bdec3ad40 100644 --- a/lib/messagelib.php +++ b/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_%")); diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 7b7259dfcc5..1a336d899c0 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -1563,6 +1563,17 @@ class plugintype_message extends plugintype_base implements plugin_information { 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(); + } + } } /**