2009-05-26 02:46:09 +00:00
< ? php
2008-07-24 08:38:03 +00:00
2009-05-26 02:46:09 +00:00
// 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/>.
2008-07-24 08:38:03 +00:00
/**
2008-07-31 08:01:46 +00:00
* messagelib . php - Contains generic messaging functions for the message system
2008-07-24 08:38:03 +00:00
*
2010-07-25 13:35:05 +00:00
* @ package core
* @ subpackage message
* @ copyright Luis Rodrigues and Martin Dougiamas
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
2008-07-24 08:38:03 +00:00
*/
2010-07-25 13:35:05 +00:00
defined ( 'MOODLE_INTERNAL' ) || die ();
2011-05-19 17:25:39 +01:00
require_once ( dirname ( dirname ( __FILE__ )) . '/message/lib.php' );
2008-07-24 08:38:03 +00:00
/**
2009-11-07 10:27:57 +00:00
* Called when a message provider wants to send a message .
2008-07-24 08:38:03 +00:00
* This functions checks the user ' s processor configuration to send the given type of message ,
* then tries to send it .
2009-11-07 10:27:57 +00:00
*
* Required parameter $eventdata structure :
2010-11-09 06:47:53 +00:00
* component string component name . must exist in message_providers
* name string message type name . must exist in message_providers
2011-05-27 10:07:26 +01:00
* userfrom object | int the user sending the message
* userto object | int the message recipient
2010-10-27 08:47:33 +00:00
* subject string the message subject
2009-11-07 10:27:57 +00:00
* fullmessage - the full message in a given format
* fullmessageformat - the format if the full message ( FORMAT_MOODLE , FORMAT_HTML , .. )
* fullmessagehtml - the full version ( the message processor will choose with one to use )
* smallmessage - the small version of the message
2010-10-26 08:00:29 +00:00
* contexturl - if this is a notification then you can specify a url to view the event . For example the forum post the user is being notified of .
* contexturlname - the display text for contexturl
2009-11-07 10:27:57 +00:00
*
2010-11-09 06:47:53 +00:00
* @ param object $eventdata information about the message ( component , userfrom , userto , ... )
2011-02-10 13:25:38 +08:00
* @ return int | false the ID of the new message or false if there was a problem with a processor
2008-07-24 08:38:03 +00:00
*/
2009-11-07 10:27:57 +00:00
function message_send ( $eventdata ) {
2008-07-24 08:38:03 +00:00
global $CFG , $DB ;
2011-02-10 13:25:38 +08:00
//new message ID to return
$messageid = false ;
2009-11-07 10:30:03 +00:00
//TODO: we need to solve problems with database transactions here somehow, for now we just prevent transactions - sorry
$DB -> transactions_forbidden ();
2009-11-07 10:27:57 +00:00
2010-10-27 08:47:33 +00:00
if ( is_int ( $eventdata -> userto )) {
2011-05-27 10:04:33 +01:00
$eventdata -> userto = $DB -> get_record ( 'user' , array ( 'id' => $eventdata -> userto ));
2010-10-27 08:47:33 +00:00
}
if ( is_int ( $eventdata -> userfrom )) {
2011-05-27 10:04:33 +01:00
$eventdata -> userfrom = $DB -> get_record ( 'user' , array ( 'id' => $eventdata -> userfrom ));
2010-10-27 08:47:33 +00:00
}
2011-12-29 16:47:40 +01:00
if ( ! isset ( $eventdata -> userto -> auth ) or ! isset ( $eventdata -> userto -> suspended ) or ! isset ( $eventdata -> userto -> deleted )) {
$eventdata -> userto = $DB -> get_record ( 'user' , array ( 'id' => $eventdata -> userto -> id ));
}
2010-10-27 08:47:33 +00:00
2010-07-06 01:52:32 +00:00
//after how long inactive should the user be considered logged off?
2008-07-24 08:38:03 +00:00
if ( isset ( $CFG -> block_online_users_timetosee )) {
$timetoshowusers = $CFG -> block_online_users_timetosee * 60 ;
} else {
2010-07-06 01:52:32 +00:00
$timetoshowusers = 300 ; //5 minutes
2008-07-24 08:38:03 +00:00
}
2010-07-06 01:52:32 +00:00
// Work out if the user is logged in or not
2010-11-19 05:18:34 +00:00
if ( ! empty ( $eventdata -> userto -> lastaccess ) && ( time () - $timetoshowusers ) < $eventdata -> userto -> lastaccess ) {
2008-07-24 08:38:03 +00:00
$userstate = 'loggedin' ;
2010-07-06 01:52:32 +00:00
} else {
$userstate = 'loggedoff' ;
2008-07-24 08:38:03 +00:00
}
2009-11-01 11:31:16 +00:00
2010-07-06 01:52:32 +00:00
// Create the message object
2010-09-21 08:07:44 +00:00
$savemessage = new stdClass ();
2008-07-24 08:38:03 +00:00
$savemessage -> useridfrom = $eventdata -> userfrom -> id ;
$savemessage -> useridto = $eventdata -> userto -> id ;
$savemessage -> subject = $eventdata -> subject ;
$savemessage -> fullmessage = $eventdata -> fullmessage ;
$savemessage -> fullmessageformat = $eventdata -> fullmessageformat ;
$savemessage -> fullmessagehtml = $eventdata -> fullmessagehtml ;
$savemessage -> smallmessage = $eventdata -> smallmessage ;
2010-10-08 02:49:53 +00:00
2010-10-25 09:29:34 +00:00
if ( ! empty ( $eventdata -> notification )) {
$savemessage -> notification = $eventdata -> notification ;
2010-10-08 02:49:53 +00:00
} else {
2010-10-25 09:29:34 +00:00
$savemessage -> notification = 0 ;
2010-10-08 02:49:53 +00:00
}
2010-10-26 08:00:29 +00:00
if ( ! empty ( $eventdata -> contexturl )) {
$savemessage -> contexturl = $eventdata -> contexturl ;
} else {
$savemessage -> contexturl = null ;
}
if ( ! empty ( $eventdata -> contexturlname )) {
$savemessage -> contexturlname = $eventdata -> contexturlname ;
} else {
$savemessage -> contexturlname = null ;
}
2010-10-08 02:49:53 +00:00
$savemessage -> timecreated = time ();
2008-07-24 08:38:03 +00:00
2011-05-19 17:25:39 +01:00
// Fetch enabled processors
$processors = get_message_processors ( true );
// Fetch default (site) preferences
$defaultpreferences = get_message_output_default_preferences ();
// Preset variables
$processorlist = array ();
$preferencebase = $eventdata -> component . '_' . $eventdata -> name ;
// Fill in the array of processors to be used based on default and user preferences
foreach ( $processors as $processor ) {
// First find out permissions
$defaultpreference = $processor -> name . '_provider_' . $preferencebase . '_permitted' ;
2011-05-31 09:46:22 +01:00
if ( isset ( $defaultpreferences -> { $defaultpreference })) {
2011-05-19 17:25:39 +01:00
$permitted = $defaultpreferences -> { $defaultpreference };
} else {
2010-11-09 06:12:04 +00:00
//MDL-25114 They supplied an $eventdata->component $eventdata->name combination which doesn't
2011-05-19 17:25:39 +01:00
//exist in the message_provider table (thus there is no default settings for them)
2011-10-22 14:28:18 +02:00
$preferrormsg = get_string ( 'couldnotfindpreference' , 'message' , $preferencename ); //TODO: undefined $preferencename
2010-11-09 06:12:04 +00:00
throw new coding_exception ( $preferrormsg , 'blah' );
2010-11-09 06:01:20 +00:00
}
2011-05-19 17:25:39 +01:00
// Find out if user has configured this output
2011-08-16 14:06:11 +08:00
// Some processors cannot function without settings from the user
2011-05-31 09:07:38 +01:00
$userisconfigured = $processor -> object -> is_user_configured ( $eventdata -> userto );
2011-05-19 17:25:39 +01:00
2011-06-24 14:19:40 +08:00
// DEBUG: notify if we are forcing unconfigured output
2011-05-31 09:07:38 +01:00
if ( $permitted == 'forced' && ! $userisconfigured ) {
2011-05-19 17:25:39 +01:00
debugging ( 'Attempt to force message delivery to user who has "' . $processor -> name . '" output unconfigured' , DEBUG_NORMAL );
}
2011-11-16 13:01:55 +08:00
// Warn developers that necessary data is missing regardless of how the processors are configured
if ( ! isset ( $eventdata -> userto -> emailstop )) {
debugging ( 'userto->emailstop is not set. Retrieving it from the user table' );
$eventdata -> userto -> emailstop = $DB -> get_field ( 'user' , 'emailstop' , array ( 'id' => $eventdata -> userto -> id ));
}
2011-05-19 17:25:39 +01:00
// Populate the list of processors we will be using
2011-05-31 09:07:38 +01:00
if ( $permitted == 'forced' && $userisconfigured ) {
2011-11-16 13:01:55 +08:00
// An admin is forcing users to use this message processor. Use this processor unconditionally.
2011-05-19 17:25:39 +01:00
$processorlist [] = $processor -> name ;
2011-08-16 14:06:11 +08:00
} else if ( $permitted == 'permitted' && $userisconfigured && ! $eventdata -> userto -> emailstop ) {
2011-11-16 13:01:55 +08:00
// User has not disabled notifications
// See if user set any notification preferences, otherwise use site default ones
2011-05-19 17:25:39 +01:00
$userpreferencename = 'message_provider_' . $preferencebase . '_' . $userstate ;
if ( $userpreference = get_user_preferences ( $userpreferencename , null , $eventdata -> userto -> id )) {
if ( in_array ( $processor -> name , explode ( ',' , $userpreference ))) {
$processorlist [] = $processor -> name ;
}
2011-05-31 09:46:22 +01:00
} else if ( isset ( $defaultpreferences -> { $userpreferencename })) {
2011-05-19 17:25:39 +01:00
if ( in_array ( $processor -> name , explode ( ',' , $defaultpreferences -> { $userpreferencename }))) {
$processorlist [] = $processor -> name ;
}
}
}
2008-08-02 00:04:29 +00:00
}
2008-07-24 08:38:03 +00:00
2011-05-19 17:25:39 +01:00
if ( empty ( $processorlist ) && $savemessage -> notification ) {
2010-10-25 09:29:34 +00:00
//if they have deselected all processors and its a notification mark it read. The user doesnt want to be bothered
2010-10-28 07:12:39 +00:00
$savemessage -> timeread = time ();
2011-02-10 13:25:38 +08:00
$messageid = $DB -> insert_record ( 'message_read' , $savemessage );
2008-07-24 08:38:03 +00:00
} else { // Process the message
2010-10-08 02:33:54 +00:00
// Store unread message just in case we can not send it
2011-02-10 13:25:38 +08:00
$messageid = $savemessage -> id = $DB -> insert_record ( 'message' , $savemessage );
2010-10-27 08:47:33 +00:00
$eventdata -> savedmessageid = $savemessage -> id ;
2009-11-01 11:31:16 +00:00
2010-10-08 02:33:54 +00:00
// Try to deliver the message to each processor
2011-05-19 17:25:39 +01:00
if ( ! empty ( $processorlist )) {
2010-10-25 09:29:34 +00:00
foreach ( $processorlist as $procname ) {
2011-05-19 17:25:39 +01:00
if ( ! $processors [ $procname ] -> object -> send_message ( $eventdata )) {
debugging ( 'Error calling message processor ' . $procname );
2011-02-10 13:25:38 +08:00
$messageid = false ;
2008-07-24 08:38:03 +00:00
}
}
2011-05-19 17:25:39 +01:00
2010-10-29 08:02:42 +00:00
//if messaging is disabled and they previously had forum notifications handled by the popup processor
//or any processor that puts a row in message_working then the notification will remain forever
//unread. To prevent this mark the message read if messaging is disabled
if ( empty ( $CFG -> messaging )) {
require_once ( $CFG -> dirroot . '/message/lib.php' );
2011-02-10 13:25:38 +08:00
$messageid = message_mark_message_read ( $savemessage , time ());
2010-10-29 08:02:42 +00:00
} else if ( $DB -> count_records ( 'message_working' , array ( 'unreadmessageid' => $savemessage -> id )) == 0 ){
//if there is no more processors that want to process this we can move message to message_read
2010-10-25 09:29:34 +00:00
require_once ( $CFG -> dirroot . '/message/lib.php' );
2011-02-10 13:25:38 +08:00
$messageid = message_mark_message_read ( $savemessage , time (), true );
2010-10-25 09:29:34 +00:00
}
2010-10-08 02:33:54 +00:00
}
2008-07-24 08:38:03 +00:00
}
2011-02-10 13:25:38 +08:00
return $messageid ;
2008-07-24 08:38:03 +00:00
}
2008-07-31 08:01:46 +00:00
/**
* This code updates the message_providers table with the current set of providers
2011-05-27 09:28:09 +01:00
*
2009-06-19 14:25:56 +00:00
* @ param $component - examples : 'moodle' , 'mod_forum' , 'block_quiz_results'
2011-05-31 10:05:39 +01:00
* @ return boolean
2008-07-31 08:01:46 +00:00
*/
function message_update_providers ( $component = 'moodle' ) {
global $DB ;
// load message providers from files
$fileproviders = message_get_providers_from_file ( $component );
// load message providers from the database
$dbproviders = message_get_providers_from_db ( $component );
foreach ( $fileproviders as $messagename => $fileprovider ) {
if ( ! empty ( $dbproviders [ $messagename ])) { // Already exists in the database
2011-05-31 10:55:30 +01:00
// check if capability has changed
2008-07-31 08:01:46 +00:00
if ( $dbproviders [ $messagename ] -> capability == $fileprovider [ 'capability' ]) { // Same, so ignore
// exact same message provider already present in db, ignore this entry
unset ( $dbproviders [ $messagename ]);
continue ;
} else { // Update existing one
2010-09-21 08:07:44 +00:00
$provider = new stdClass ();
2009-11-07 10:27:57 +00:00
$provider -> id = $dbproviders [ $messagename ] -> id ;
$provider -> capability = $fileprovider [ 'capability' ];
2008-07-31 08:01:46 +00:00
$DB -> update_record ( 'message_providers' , $provider );
unset ( $dbproviders [ $messagename ]);
continue ;
}
} else { // New message provider, add it
2010-09-21 08:07:44 +00:00
$provider = new stdClass ();
2008-07-31 08:01:46 +00:00
$provider -> name = $messagename ;
$provider -> component = $component ;
$provider -> capability = $fileprovider [ 'capability' ];
2011-05-20 15:10:27 +01:00
$transaction = $DB -> start_delegated_transaction ();
2008-07-31 08:01:46 +00:00
$DB -> insert_record ( 'message_providers' , $provider );
2011-05-20 15:10:27 +01:00
message_set_default_message_preference ( $component , $messagename , $fileprovider );
$transaction -> allow_commit ();
2008-07-31 08:01:46 +00:00
}
}
foreach ( $dbproviders as $dbprovider ) { // Delete old ones
$DB -> delete_records ( 'message_providers' , array ( 'id' => $dbprovider -> id ));
2011-05-31 10:55:30 +01:00
$DB -> delete_records_select ( 'config_plugins' , " plugin = 'message' AND " . $DB -> sql_like ( 'name' , '?' , false ), array ( " %_provider_ { $component } _ { $dbprovider -> name } _% " ));
$DB -> delete_records_select ( 'user_preferences' , $DB -> sql_like ( 'name' , '?' , false ), array ( " message_provider_ { $component } _ { $dbprovider -> name } _% " ));
2008-07-31 08:01:46 +00:00
}
2011-05-31 10:05:39 +01:00
return true ;
2008-07-31 08:01:46 +00:00
}
2011-06-01 11:44:36 +01:00
/**
* This function populates default message preferences for all existing providers
* when the new message processor is added .
*
* @ param string $processorname The name of message processor plugin ( e . g . 'email' , 'jabber' )
* @ return void
* @ throws invalid_parameter_exception if $processorname does not exist
*/
function message_update_processors ( $processorname ) {
global $DB ;
// validate if our processor exists
$processor = $DB -> get_records ( 'message_processors' , array ( 'name' => $processorname ));
if ( empty ( $processor )) {
throw new invalid_parameter_exception ();
}
$providers = $DB -> get_records_sql ( 'SELECT DISTINCT component FROM {message_providers}' );
$transaction = $DB -> start_delegated_transaction ();
foreach ( $providers as $provider ) {
// load message providers from files
$fileproviders = message_get_providers_from_file ( $provider -> component );
foreach ( $fileproviders as $messagename => $fileprovider ) {
message_set_default_message_preference ( $provider -> component , $messagename , $fileprovider , $processorname );
}
}
$transaction -> allow_commit ();
}
2011-05-20 15:10:27 +01:00
/**
* Setting default messaging preference for particular message provider
2011-05-27 09:28:09 +01:00
*
2011-05-20 15:10:27 +01:00
* @ param string $component The name of component ( e . g . moodle , mod_forum , etc . )
* @ param string $messagename The name of message provider
* @ param array $fileprovider The value of $messagename key in the array defined in plugin messages . php
2011-06-01 11:44:36 +01:00
* @ param string $processorname The optinal name of message processor
2011-05-27 09:28:09 +01:00
* @ return void
2011-05-20 15:10:27 +01:00
*/
2011-06-01 11:44:36 +01:00
function message_set_default_message_preference ( $component , $messagename , $fileprovider , $processorname = '' ) {
2011-05-20 15:10:27 +01:00
global $DB ;
// Fetch message processors
2011-06-01 11:44:36 +01:00
$condition = null ;
// If we need to process a particular processor, set the select condition
if ( ! empty ( $processorname )) {
$condition = array ( 'name' => $processorname );
}
$processors = $DB -> get_records ( 'message_processors' , $condition );
2011-05-20 15:10:27 +01:00
// load default messaging preferences
$defaultpreferences = get_message_output_default_preferences ();
2011-05-27 09:28:09 +01:00
// Setting default preference
2011-05-20 15:10:27 +01:00
$componentproviderbase = $component . '_' . $messagename ;
$loggedinpref = array ();
$loggedoffpref = array ();
2011-05-27 09:28:09 +01:00
// set 'permitted' preference first for each messaging processor
2011-05-20 15:10:27 +01:00
foreach ( $processors as $processor ) {
$preferencename = $processor -> name . '_provider_' . $componentproviderbase . '_permitted' ;
2011-05-27 09:28:09 +01:00
// if we do not have this setting yet, set it
2011-05-31 09:46:22 +01:00
if ( ! isset ( $defaultpreferences -> { $preferencename })) {
2011-05-20 15:10:27 +01:00
// determine plugin default settings
$plugindefault = 0 ;
if ( isset ( $fileprovider [ 'defaults' ][ $processor -> name ])) {
$plugindefault = $fileprovider [ 'defaults' ][ $processor -> name ];
}
// get string values of the settings
list ( $permitted , $loggedin , $loggedoff ) = translate_message_default_setting ( $plugindefault , $processor -> name );
// store default preferences for current processor
set_config ( $preferencename , $permitted , 'message' );
// save loggedin/loggedoff settings
if ( $loggedin ) {
$loggedinpref [] = $processor -> name ;
}
if ( $loggedoff ) {
$loggedoffpref [] = $processor -> name ;
}
}
}
2011-05-27 09:28:09 +01:00
// now set loggedin/loggedoff preferences
2011-05-20 15:10:27 +01:00
if ( ! empty ( $loggedinpref )) {
$preferencename = 'message_provider_' . $componentproviderbase . '_loggedin' ;
2011-06-01 11:44:36 +01:00
if ( isset ( $defaultpreferences -> { $preferencename })) {
// We have the default preferences for this message provider, which
// likely means that we have been adding a new processor. Add defaults
// to exisitng preferences.
$loggedinpref = array_merge ( $loggedinpref , explode ( ',' , $defaultpreferences -> { $preferencename }));
}
2011-05-20 15:10:27 +01:00
set_config ( $preferencename , join ( ',' , $loggedinpref ), 'message' );
}
if ( ! empty ( $loggedoffpref )) {
$preferencename = 'message_provider_' . $componentproviderbase . '_loggedoff' ;
2011-06-01 11:44:36 +01:00
if ( isset ( $defaultpreferences -> { $preferencename })) {
// We have the default preferences for this message provider, which
// likely means that we have been adding a new processor. Add defaults
// to exisitng preferences.
$loggedoffpref = array_merge ( $loggedoffpref , explode ( ',' , $defaultpreferences -> { $preferencename }));
}
2011-05-20 15:10:27 +01:00
set_config ( $preferencename , join ( ',' , $loggedoffpref ), 'message' );
}
}
2008-07-31 08:01:46 +00:00
/**
* Returns the active providers for the current user , based on capability
2011-06-13 12:21:48 +02:00
*
2011-06-13 15:06:19 +08:00
* This function has been deprecated please use { @ see message_get_providers_for_user ()} instead .
2011-05-27 09:28:09 +01:00
*
2011-06-13 15:06:19 +08:00
* @ deprecated since 2.1
* @ todo Remove in 2.2
2008-07-31 08:01:46 +00:00
* @ return array of message providers
*/
function message_get_my_providers () {
2011-06-13 15:06:19 +08:00
global $USER ;
return message_get_providers_for_user ( $USER -> id );
}
2008-07-31 08:01:46 +00:00
/**
2011-05-28 08:46:47 +01:00
* Returns the active providers for the user specified , based on capability
2011-05-27 09:28:09 +01:00
*
2011-05-28 08:46:47 +01:00
* @ param int $userid id of user
2008-07-31 08:01:46 +00:00
* @ return array of message providers
*/
2011-05-28 08:46:47 +01:00
function message_get_providers_for_user ( $userid ) {
2011-07-05 15:23:37 +01:00
global $DB , $CFG ;
2008-07-31 08:01:46 +00:00
$systemcontext = get_context_instance ( CONTEXT_SYSTEM );
2010-10-25 09:29:34 +00:00
$providers = $DB -> get_records ( 'message_providers' , null , 'name' );
2008-07-31 08:01:46 +00:00
// Remove all the providers we aren't allowed to see now
foreach ( $providers as $providerid => $provider ) {
if ( ! empty ( $provider -> capability )) {
2011-05-28 08:46:47 +01:00
if ( ! has_capability ( $provider -> capability , $systemcontext , $userid )) {
2008-07-31 08:01:46 +00:00
unset ( $providers [ $providerid ]); // Not allowed to see this
}
}
2011-07-05 15:23:37 +01:00
// Ensure user is not allowed to configure instantmessage if it is globally disabled.
if ( ! $CFG -> messaging && $provider -> name == 'instantmessage' ) {
unset ( $providers [ $providerid ]);
}
2008-07-31 08:01:46 +00:00
}
return $providers ;
}
/**
* Gets the message providers that are in the database for this component .
2011-05-27 09:28:09 +01:00
*
2008-07-31 08:01:46 +00:00
* @ param $component - examples : 'moodle' , 'mod/forum' , 'block/quiz_results'
* @ return array of message providers
*
* INTERNAL - to be used from messagelib only
*/
function message_get_providers_from_db ( $component ) {
global $DB ;
2009-11-07 10:27:57 +00:00
return $DB -> get_records ( 'message_providers' , array ( 'component' => $component ), '' , 'name, id, component, capability' ); // Name is unique per component
2008-07-31 08:01:46 +00:00
}
/**
* Loads the messages definitions for the component ( from file ) . If no
* messages are defined for the component , we simply return an empty array .
2011-05-27 09:28:09 +01:00
*
2009-06-19 14:25:56 +00:00
* @ param $component - examples : 'moodle' , 'mod_forum' , 'block_quiz_results'
2008-07-31 08:01:46 +00:00
* @ return array of message providerss or empty array if not exists
*
* INTERNAL - to be used from messagelib only
*/
function message_get_providers_from_file ( $component ) {
2009-06-19 14:25:56 +00:00
$defpath = get_component_directory ( $component ) . '/db/messages.php' ;
2008-07-31 08:01:46 +00:00
$messageproviders = array ();
if ( file_exists ( $defpath )) {
require ( $defpath );
}
foreach ( $messageproviders as $name => $messageprovider ) { // Fix up missing values if required
if ( empty ( $messageprovider [ 'capability' ])) {
$messageproviders [ $name ][ 'capability' ] = NULL ;
}
2011-05-20 15:10:27 +01:00
if ( empty ( $messageprovider [ 'defaults' ])) {
$messageproviders [ $name ][ 'defaults' ] = array ();
}
2008-07-31 08:01:46 +00:00
}
return $messageproviders ;
}
/**
2011-06-02 09:27:05 +01:00
* Remove all message providers for particular plugin and corresponding settings
2011-05-27 09:28:09 +01:00
*
2011-06-02 09:27:05 +01:00
* @ param string $component - examples : 'moodle' , 'mod_forum' , 'block_quiz_results'
2011-05-27 09:28:09 +01:00
* @ return void
2008-07-31 08:01:46 +00:00
*/
2011-06-02 09:27:05 +01:00
function message_provider_uninstall ( $component ) {
2010-09-17 07:58:04 +00:00
global $DB ;
2010-10-25 09:29:34 +00:00
2011-05-20 15:10:27 +01:00
$transaction = $DB -> start_delegated_transaction ();
$DB -> delete_records ( 'message_providers' , array ( 'component' => $component ));
$DB -> delete_records_select ( 'config_plugins' , " plugin = 'message' AND " . $DB -> sql_like ( 'name' , '?' , false ), array ( " %_provider_ { $component } _% " ));
$DB -> delete_records_select ( 'user_preferences' , $DB -> sql_like ( 'name' , '?' , false ), array ( " message_provider_ { $component } _% " ));
$transaction -> allow_commit ();
2008-08-02 00:04:29 +00:00
}
2011-06-02 09:27:05 +01:00
/**
* Remove message processor
*
* @ param string $name - examples : 'email' , 'jabber'
* @ return void
*/
function message_processor_uninstall ( $name ) {
global $DB ;
$transaction = $DB -> start_delegated_transaction ();
$DB -> delete_records ( 'message_processors' , array ( 'name' => $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_% " ));
$transaction -> allow_commit ();
}