From bc795b98e96743fa29654abbaa4f17a681303987 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Fri, 9 Mar 2012 16:18:58 +0000 Subject: [PATCH 1/4] MDL-32009 messaging: Refator get_settings_url plugintype method No need to duplicate checks since we have them in one place. --- lib/pluginlib.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 150d42c69c6..14c18a27284 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -2288,12 +2288,14 @@ class plugininfo_enrol extends plugininfo_base { class plugininfo_message extends plugininfo_base { 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)); - } else { - return parent::get_settings_url(); + $processors = get_message_processors(); + if (isset($processors[$this->name])) { + $processor = $processors[$this->name]; + if ($processor->available && $processor->hassettings) { + return new moodle_url('settings.php', array('section' => 'messagesetting'.$processor->name)); + } } + return parent::get_settings_url(); } } From bede23f7bc528ac22151f1ae89f1c8646e12a722 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Mon, 12 Mar 2012 15:02:16 +0000 Subject: [PATCH 2/4] MDL-32009 messaging: Add is_enabled method to plugintype_message --- lib/pluginlib.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 14c18a27284..45b3d14ce2d 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -2297,6 +2297,18 @@ class plugininfo_message extends plugininfo_base { } return parent::get_settings_url(); } + + /** + * @see plugintype_interface::is_enabled() + */ + public function is_enabled() { + $processors = get_message_processors(); + if (isset($processors[$this->name])) { + return $processors[$this->name]->configured && $processors[$this->name]->enabled; + } else { + return parent::is_enabled(); + } + } } From 3f9d9e285672967755f00859c00fc02e2ff9ae59 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Tue, 3 Apr 2012 14:48:54 +0100 Subject: [PATCH 3/4] MDL-32009 messaging: Add message processor uninstall functionality --- admin/message.php | 33 ++++++++++++++++++++++++++++++--- lang/en/message.php | 2 ++ lib/messagelib.php | 1 + lib/pluginlib.php | 12 ++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/admin/message.php b/admin/message.php index 8daf613defa..8e78fc30231 100644 --- a/admin/message.php +++ b/admin/message.php @@ -34,6 +34,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', 0, PARAM_INT); +$confirm = optional_param('confirm', false, PARAM_BOOL); + +$headingtitle = get_string('managemessageoutputs', 'message'); if (!empty($disable) && confirm_sesskey()) { if (!$processor = $DB->get_record('message_processors', array('id'=>$disable))) { @@ -42,14 +46,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 +92,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 0048a0070ff..b92986af055 100644 --- a/lang/en/message.php +++ b/lang/en/message.php @@ -108,6 +108,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 5d2f6533a14..03b93e32e46 100644 --- a/lib/messagelib.php +++ b/lib/messagelib.php @@ -480,6 +480,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 45b3d14ce2d..26d4ed934de 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -2309,6 +2309,18 @@ class plugininfo_message extends plugininfo_base { return parent::is_enabled(); } } + + /** + * @see plugintype_interface::get_uninstall_url() + */ + public function get_uninstall_url() { + $processors = get_message_processors(); + if (isset($processors[$this->name])) { + return new moodle_url('message.php', array('uninstall' => $processors[$this->name]->id, 'sesskey' => sesskey())); + } else { + return parent::get_uninstall_url(); + } + } } From c9e34994cbdcff9c5bb8318ed860d69e375c1891 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Thu, 12 Apr 2012 11:03:11 +0100 Subject: [PATCH 4/4] MDL-32009 messaging: Fix using message processor term inconsistency. --- lang/en/message.php | 6 +++--- lang/en/plugin.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lang/en/message.php b/lang/en/message.php index b92986af055..fd25102a8f4 100644 --- a/lang/en/message.php +++ b/lang/en/message.php @@ -53,7 +53,7 @@ $string['editmymessage'] = 'Messaging'; $string['emailmessages'] = 'Email messages when I am offline'; $string['emailtagline'] = 'This is a copy of a message sent to you at "{$a->sitename}". Go to {$a->url} to reply.'; $string['emptysearchstring'] = 'You must search for something'; -$string['errorcallingprocessor'] = 'Error calling defined processor'; +$string['errorcallingprocessor'] = 'Error calling defined output'; $string['errortranslatingdefault'] = 'Error translating default setting provided by plugin, using system defaults instead.'; $string['forced'] = 'Forced'; $string['formorethan'] = 'For more than'; @@ -108,8 +108,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['processordeleteconfirm'] = 'You are about to completely delete message output \'{$a}\'. This will completely delete everything in the database associated with this output. Are you SURE you want to continue?'; +$string['processordeletefiles'] = 'All data associated with the output \'{$a->processor}\' has been deleted from the database. To complete the deletion (and prevent the output 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/lang/en/plugin.php b/lang/en/plugin.php index 1b6ae6cbd26..3bc89ef8d37 100644 --- a/lang/en/plugin.php +++ b/lang/en/plugin.php @@ -91,8 +91,8 @@ $string['type_gradingform'] = 'Advanced grading method'; $string['type_gradingform_plural'] = 'Advanced grading methods'; $string['type_local'] = 'Local plugin'; $string['type_local_plural'] = 'Local plugins'; -$string['type_message'] = 'Messaging processor'; -$string['type_message_plural'] = 'Messaging processors'; +$string['type_message'] = 'Messaging output'; +$string['type_message_plural'] = 'Messaging outputs'; $string['type_mnetservice'] = 'MNet service'; $string['type_mnetservice_plural'] = 'MNet services'; $string['type_mod'] = 'Activity module';