MDL-71473 message: Remove jabber output notification

Jabber is not widely used these days so message_jabber has been removed
from Moodle core.
This commit is contained in:
Sara Arjona 2021-08-16 13:10:48 +02:00
parent 1d700796ca
commit f471a7d23a
13 changed files with 48 additions and 572 deletions

View File

@ -1726,6 +1726,7 @@ class core_plugin_manager {
'cachestore' => array('memcache'),
'enrol' => array('authorize'),
'qformat' => array('webct'),
'message' => array('jabber'),
'quizaccess' => array('safebrowser'),
'report' => array('search'),
'repository' => array('alfresco'),
@ -1911,7 +1912,7 @@ class core_plugin_manager {
),
'message' => array(
'airnotifier', 'email', 'jabber', 'popup'
'airnotifier', 'email', 'popup'
),
'mnetservice' => array(

View File

@ -2717,5 +2717,48 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021090200.01);
}
if ($oldversion < 2021091100.01) {
// If message_jabber is no longer present, remove it.
if (!file_exists($CFG->dirroot . '/message/output/jabber/message_output_jabber.php')) {
// Remove Jabber from the notification plugins list.
$DB->delete_records('message_processors', ['name' => 'jabber']);
// Remove user preference settings.
$DB->delete_records('user_preferences', ['name' => 'message_processor_jabber_jabberid']);
$sql = 'SELECT *
FROM {user_preferences} up
WHERE ' . $DB->sql_like('up.name', ':name', false, false) . ' AND ' .
$DB->sql_like('up.value', ':value', false, false);
$params = [
'name' => 'message_provider_%',
'value' => '%jabber%',
];
$jabbersettings = $DB->get_recordset_sql($sql, $params);
foreach ($jabbersettings as $jabbersetting) {
// Remove 'jabber' from the value.
$jabbersetting->value = implode(',', array_diff(explode(',', $jabbersetting->value), ['jabber']));
$DB->update_record('user_preferences', $jabbersetting);
}
$jabbersettings->close();
// Clean config settings.
unset_config('jabberhost');
unset_config('jabberserver');
unset_config('jabberusername');
unset_config('jabberpassword');
unset_config('jabberport');
// Remove default notification preferences.
$like = $DB->sql_like('name', '?', true, true, false, '|');
$params = [$DB->sql_like_escape('jabber_provider_', '|') . '%'];
$DB->delete_records_select('config_plugins', $like, $params);
// Clean config config settings.
unset_all_config_for_plugin('message_jabber');
}
upgrade_main_savepoint(true, 2021091100.01);
}
return true;
}

View File

@ -1,111 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy class for requesting user data.
*
* @package message_jabber
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace message_jabber\privacy;
defined('MOODLE_INTERNAL') || die();
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\contextlist;
use \core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\userlist;
use \core_privacy\local\request\approved_userlist;
/**
* Privacy class for requesting user data.
*
* @package message_jabber
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\request\plugin\provider {
/**
* Returns meta data about this system.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection) : collection {
$collection->link_external_location('External Jabber server.', [
'userto' => 'privacy:metadata:userto',
'userfrom' => 'privacy:metadata:userfrom',
'smallmessage' => 'privacy:metadata:smallmessage',
'contexturl' => 'privacy:metadata:contexturl',
], 'privacy:metadata:externalpurpose');
return $collection;
}
/**
* Get the list of contexts that contain user information for the specified user.
*
* @param int $userid The user to search.
* @return contextlist The contextlist containing the list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid) : contextlist {
return new contextlist();
}
/**
* Get the list of users who have data within a context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public static function get_users_in_context(userlist $userlist) {
}
/**
* Export all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts to export information for.
*/
public static function export_user_data(approved_contextlist $contextlist) {
}
/**
* Delete all use data which matches the specified deletion_criteria.
*
* @param context $context A user context.
*/
public static function delete_data_for_all_users_in_context(\context $context) {
}
/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public static function delete_data_for_users(approved_userlist $userlist) {
}
/**
* Delete all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function delete_data_for_user(approved_contextlist $contextlist) {
}
}

View File

@ -1,37 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Jabber message processor installation code
*
* @package message_jabber
* @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Install the Jabber message processor
*/
function xmldb_message_jabber_install(){
global $DB;
$result = true;
$provider = new stdClass();
$provider->name = 'jabber';
$DB->insert_record('message_processors', $provider);
return $result;
}

View File

@ -1,48 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Upgrade code for jabber message processor
*
* @package message_jabber
* @copyright 2008 Luis Rodrigues
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Upgrade code for the jabber message processor
*
* @param int $oldversion The version that we are upgrading from
*/
function xmldb_message_jabber_upgrade($oldversion) {
global $CFG;
// Automatically generated Moodle v3.6.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v3.7.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v3.8.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v3.9.0 release upgrade line.
// Put any upgrade step following this.
return true;
}

View File

@ -1,42 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'message_jabber', language 'en'
*
* @package message_jabber
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['configjabberhost'] = 'The server to connect to to send jabber message notifications';
$string['configjabberserver'] = 'XMPP host ID (can be left empty if the same as Jabber host)';
$string['configjabberusername'] = 'The username to use when connecting to the Jabber server';
$string['configjabberpassword'] = 'The password to use when connecting to the Jabber server';
$string['configjabberport'] = 'The port to use when connecting to the Jabber server';
$string['jabberhost'] = 'Jabber host';
$string['jabberid'] = 'Jabber ID';
$string['jabberserver'] = 'Jabber server';
$string['jabberusername'] = 'Jabber username';
$string['jabberpassword'] = 'Jabber password';
$string['jabberport'] = 'Jabber port';
$string['notconfigured'] = 'The Jabber server hasn\'t been configured so Jabber messages cannot be sent';
$string['pluginname'] = 'Jabber';
$string['privacy:metadata:contexturl'] = 'The URL to view the event.';
$string['privacy:metadata:externalpurpose'] = 'This information is sent to an external Jabber server to be ultimately delivered as a notification message to the recipient.';
$string['privacy:metadata:smallmessage'] = 'A section of the message.';
$string['privacy:metadata:userfrom'] = 'The user sending the notification message.';
$string['privacy:metadata:userto'] = 'The recipient of the notification message.';

View File

@ -1,180 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Jabber message processor to send messages by jabber
*
* @package message_jabber
* @copyright 2008 Luis Rodrigues
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
require_once($CFG->dirroot.'/message/output/lib.php');
/**
* The jabber message processor
*
* @package message_jabber
* @copyright 2008 Luis Rodrigues
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_output_jabber extends message_output {
/**
* Processes the message and sends a notification via jabber
*
* @param stdClass $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
* @return true if ok, false if error
*/
function send_message($eventdata){
global $CFG;
// Skip any messaging of suspended and deleted users.
if ($eventdata->userto->auth === 'nologin' or $eventdata->userto->suspended or $eventdata->userto->deleted) {
return true;
}
if (!empty($CFG->noemailever)) {
// hidden setting for development sites, set in config.php if needed
debugging('$CFG->noemailever is active, no jabber message sent.', DEBUG_MINIMAL);
return true;
}
if (PHPUNIT_TEST) {
// No connection to external servers allowed in phpunit tests.
return true;
}
//hold onto jabber id preference because /admin/cron.php sends a lot of messages at once
static $jabberaddresses = array();
if (!array_key_exists($eventdata->userto->id, $jabberaddresses)) {
$jabberaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_jabber_jabberid', null, $eventdata->userto->id);
}
$jabberaddress = $jabberaddresses[$eventdata->userto->id];
//calling s() on smallmessage causes Jabber to display things like &lt; Jabber != a browser
$jabbermessage = fullname($eventdata->userfrom).': '.$eventdata->smallmessage;
if (!empty($eventdata->contexturl)) {
$jabbermessage .= "\n".get_string('view').': '.$eventdata->contexturl;
}
$jabbermessage .= "\n(".get_string('noreply','message').')';
$conn = new \BirknerAlex\XMPPHP\XMPP($CFG->jabberhost,$CFG->jabberport,$CFG->jabberusername,$CFG->jabberpassword,'moodle',$CFG->jabberserver);
// No need to track the presence during the sending message process.
$conn->track_presence = false;
try {
//$conn->useEncryption(false);
$conn->connect();
$conn->processUntil('session_start');
$conn->presence();
$conn->message($jabberaddress, $jabbermessage);
$conn->disconnect();
} catch(\BirknerAlex\XMPPHP\Exception $e) {
debugging($e->getMessage());
return false;
}
return true;
}
/**
* Creates necessary fields in the messaging config form.
*
* @param array $preferences An array of user preferences
*/
function config_form($preferences){
global $CFG;
if (!$this->is_system_configured()) {
return get_string('notconfigured','message_jabber');
} else {
return get_string('jabberid', 'message_jabber').': <input size="30" name="jabber_jabberid" value="'.s($preferences->jabber_jabberid).'" />';
}
}
/**
* Parses the submitted form data and saves it into preferences array.
*
* @param stdClass $form preferences form class
* @param array $preferences preferences array
*/
function process_form($form, &$preferences){
if (isset($form->jabber_jabberid) && !empty($form->jabber_jabberid)) {
$preferences['message_processor_jabber_jabberid'] = $form->jabber_jabberid;
}
}
/**
* Loads the config data from database to put on the form during initial form display
*
* @param array $preferences preferences array
* @param int $userid the user id
*/
function load_data(&$preferences, $userid){
$preferences->jabber_jabberid = get_user_preferences( 'message_processor_jabber_jabberid', '', $userid);
}
/**
* Tests whether the Jabber settings have been configured
* @return boolean true if Jabber is configured
*/
function is_system_configured() {
global $CFG;
return (!empty($CFG->jabberhost) && !empty($CFG->jabberport) && !empty($CFG->jabberusername) && !empty($CFG->jabberpassword));
}
/**
* Tests whether the Jabber settings have been configured on user level
* @param object $user the user object, defaults to $USER.
* @return bool has the user made all the necessary settings
* in their profile to allow this plugin to be used.
*/
function is_user_configured($user = null) {
global $USER;
if (is_null($user)) {
$user = $USER;
}
return (bool)get_user_preferences('message_processor_jabber_jabberid', null, $user->id);
}
}
/*
*
* $f = fopen('/tmp/event_jabberx', 'a+');
fwrite($f, date('l dS \of F Y h:i:s A')."\n");
fwrite($f, "from: $message->userfromid\n");
fwrite($f, "userto: $message->usertoid\n");
fwrite($f, "subject: $message->subject\n");
fclose($f);
$savemessage = new stdClass();
$savemessage->useridfrom = 3;
$savemessage->useridto = 2;
$savemessage->subject = 'IM';
$savemessage->fullmessage = 'full';
$savemessage->timecreated = time();
$a = new message_output_jabber();
$a->send_message($savemessage);
* */

View File

@ -1,33 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Jabber configuration page
*
* @package message_jabber
* @copyright 2011 Lancaster University Network Services Limited
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configtext('jabberhost', get_string('jabberhost', 'message_jabber'), get_string('configjabberhost', 'message_jabber'), '', PARAM_RAW));
$settings->add(new admin_setting_configtext('jabberserver', get_string('jabberserver', 'message_jabber'), get_string('configjabberserver', 'message_jabber'), '', PARAM_RAW));
$settings->add(new admin_setting_configtext('jabberusername', get_string('jabberusername', 'message_jabber'), get_string('configjabberusername', 'message_jabber'), '', PARAM_RAW));
$settings->add(new admin_setting_configpasswordunmask('jabberpassword', get_string('jabberpassword', 'message_jabber'), get_string('configjabberpassword', 'message_jabber'), ''));
$settings->add(new admin_setting_configtext('jabberport', get_string('jabberport', 'message_jabber'), get_string('configjabberport', 'message_jabber'), 5222, PARAM_INT));
}

View File

@ -1,60 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Base class for unit tests for message_jabber.
*
* @package message_jabber
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
use \core_privacy\tests\provider_testcase;
/**
* Unit tests for message\output\jabber\classes\privacy\provider.php
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_jabber_testcase extends provider_testcase {
/**
* Basic setup for these tests.
*/
public function setUp(): void {
$this->resetAfterTest(true);
}
/**
* Test returning metadata.
*/
public function test_get_metadata() {
$collection = new \core_privacy\local\metadata\collection('message_jabber');
$collection = \message_jabber\privacy\provider::get_metadata($collection);
$this->assertNotEmpty($collection);
}
/**
* Test getting the context for the user ID related to this plugin.
*/
public function test_get_contexts_for_userid() {
$user = $this->getDataGenerator()->create_user();
$contextlist = \message_jabber\privacy\provider::get_contexts_for_userid($user->id);
$this->assertEmpty($contextlist);
}
}

View File

@ -1,29 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Jabber message processor version information
*
* @package message_jabber
* @copyright 2008 Luis Rodrigues
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2021052500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2021052500; // Requires this Moodle version.
$plugin->component = 'message_jabber'; // Full name of the plugin (used for diagnostics)

View File

@ -61,33 +61,3 @@ Feature: Manage notification preferences - Email
And I follow "Preferences" in the user menu
And I click on "Message preferences" "link"
And the field "Email" matches value "0"
Scenario: Config jabber
Given the following config values are set as admin:
| jabberhost | jabber.org |
| jabberusername | moodlemessageservice |
| jabberpassword | password |
When I log in as "admin"
And I navigate to "Messaging > Notification settings" in site administration
And I set the field "jabber" to "1"
And I press "Save changes"
And I click on "Settings" "link" in the "Jabber" "table_row"
And I navigate to "Messaging > Notification settings" in site administration
And I press "Save changes"
And I log out
And I log in as "student1"
And I open messaging
And I open messaging settings preferences
Then I should not see "Notification preferences"
And I should not see "Jabber"
And I open the notification popover
And I follow "Notification preferences"
And I click on "Jabber" "link"
And I should see "Jabber ID"
And I set the field "jabber_jabberid" to "student1@jabber.org"
And I click on "Save changes" "button" in the ".modal-dialog" "css_element"
And I am on homepage
And I open messaging
And I open messaging settings preferences
And I should see "Notification preferences"
And I should see "Jabber"

View File

@ -6,6 +6,8 @@ information provided here is intended especially for developers.
The following functions have been finally deprecated and can not be used anymore:
* can_post_message()
* get_individual_conversations_between_users()
* The message_jabber notification has been completely removed from core. It has been moved to the plugins database repository, so
it can still be installed as a third-party plugin.
=== 3.11.2 ===

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2021091100.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021091100.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev (Build: 20210911)'; // Human-friendly version name