mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
message MDL-24873 changes to reduce server load and also get the forum's custom email headers passed through correctly
This commit is contained in:
parent
9e32912bca
commit
fe983847dd
4 changed files with 47 additions and 29 deletions
|
@ -33,9 +33,9 @@ defined('MOODLE_INTERNAL') || die();
|
|||
*
|
||||
* Required parameter $eventdata structure:
|
||||
* modulename -
|
||||
* userfrom
|
||||
* userto
|
||||
* subject
|
||||
* userfrom object the user sending the message
|
||||
* userto object the message recipient
|
||||
* subject string the message subject
|
||||
* 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)
|
||||
|
@ -55,6 +55,15 @@ function message_send($eventdata) {
|
|||
//TODO: we need to solve problems with database transactions here somehow, for now we just prevent transactions - sorry
|
||||
$DB->transactions_forbidden();
|
||||
|
||||
if (is_int($eventdata->userto)) {
|
||||
mtrace('message_send() userto is a user ID when it should be a user object');
|
||||
$eventdata->userto = $DB->get_record('user', array('id' => $eventdata->useridto));
|
||||
}
|
||||
if (is_int($eventdata->userfrom)) {
|
||||
mtrace('message_send() userfrom is a user ID when it should be a user object');
|
||||
$eventdata->userfrom = $DB->get_record('user', array('id' => $message->userfrom));
|
||||
}
|
||||
|
||||
//after how long inactive should the user be considered logged off?
|
||||
if (isset($CFG->block_online_users_timetosee)) {
|
||||
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
|
||||
|
@ -118,6 +127,7 @@ function message_send($eventdata) {
|
|||
} else { // Process the message
|
||||
// Store unread message just in case we can not send it
|
||||
$savemessage->id = $DB->insert_record('message', $savemessage);
|
||||
$eventdata->savedmessageid = $savemessage->id;
|
||||
|
||||
// Try to deliver the message to each processor
|
||||
if ($processor!='none') {
|
||||
|
@ -132,7 +142,7 @@ function message_send($eventdata) {
|
|||
if (class_exists($processclass)) {
|
||||
$pclass = new $processclass();
|
||||
|
||||
if (!$pclass->send_message($savemessage)) {
|
||||
if (!$pclass->send_message($eventdata)) {
|
||||
debugging('Error calling message processor '.$procname);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -35,23 +35,26 @@ require_once($CFG->dirroot.'/message/output/lib.php');
|
|||
class message_output_email extends message_output {
|
||||
/**
|
||||
* Processes the message (sends by email).
|
||||
* @param object $message the message to be sent
|
||||
* @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
|
||||
*/
|
||||
function send_message($message) {
|
||||
global $DB, $SITE;
|
||||
function send_message($eventdata) {
|
||||
global $SITE;
|
||||
|
||||
$userto = $DB->get_record('user', array('id' => $message->useridto));
|
||||
$userfrom = $DB->get_record('user', array('id' => $message->useridfrom));
|
||||
//hold onto email preference because /admin/cron.php sends a lot of messages at once
|
||||
static $useremailaddresses = array();
|
||||
|
||||
//check user preference for where user wants email sent
|
||||
$usertoemailaddress = get_user_preferences('message_processor_email_email', '', $message->useridto);
|
||||
if (!array_key_exists($eventdata->userto->id, $useremailaddresses)) {
|
||||
$useremailaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_email_email', $eventdata->userto->email, $eventdata->userto->id);
|
||||
}
|
||||
$usertoemailaddress = $useremailaddresses[$eventdata->userto->id];
|
||||
|
||||
if ( !empty($usertoemailaddress)) {
|
||||
$userto->email = $usertoemailaddress;
|
||||
}
|
||||
|
||||
$result = email_to_user($userto, $userfrom,
|
||||
$message->subject, $message->fullmessage, $message->fullmessagehtml);
|
||||
$result = email_to_user($eventdata->userto, $eventdata->userfrom,
|
||||
$eventdata->subject, $eventdata->fullmessage, $eventdata->fullmessagehtml);
|
||||
|
||||
return $result===true; //email_to_user() can return true, false or "emailstop"
|
||||
//return true;//do we want to report an error if email sending fails?
|
||||
|
|
|
@ -38,21 +38,20 @@ class message_output_jabber extends message_output {
|
|||
|
||||
/**
|
||||
* Processes the message (sends using jabber).
|
||||
* @param object $message the message to be sent
|
||||
* @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
|
||||
* @return true if ok, false if error
|
||||
*/
|
||||
function send_message($message){
|
||||
global $DB, $CFG;
|
||||
function send_message($eventdata){
|
||||
global $CFG;
|
||||
|
||||
if (!$userfrom = $DB->get_record('user', array('id' => $message->useridfrom))) {
|
||||
return false;
|
||||
}
|
||||
if (!$userto = $DB->get_record('user', array('id' => $message->useridto))) {
|
||||
return false;
|
||||
}
|
||||
if (!$jabberaddress = get_user_preferences('message_processor_jabber_jabberid', $userto->email, $userto->id)) {
|
||||
$jabberaddress = $userto->email;
|
||||
//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', $eventdata->userto->email, $eventdata->userto->id);
|
||||
}
|
||||
$jabberaddress = $jabberaddresses[$eventdata->userto->id];
|
||||
|
||||
$jabbermessage = fullname($userfrom).': '.$message->smallmessage;
|
||||
|
||||
$conn = new XMPPHP_XMPP($CFG->jabberhost,$CFG->jabberport,$CFG->jabberusername,$CFG->jabberpassword,'moodle',$CFG->jabberserver);
|
||||
|
|
|
@ -33,18 +33,24 @@ class message_output_popup extends message_output{
|
|||
* The popup doesn't send data only saves in the database for later use,
|
||||
* the popup_interface.php takes the message from the message table into
|
||||
* the message_read.
|
||||
* @param object $message the message to be sent
|
||||
* @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
|
||||
* @return true if ok, false if error
|
||||
*/
|
||||
public function send_message($message) {
|
||||
public function send_message($eventdata) {
|
||||
global $DB;
|
||||
|
||||
//hold onto the popup processor id because /admin/cron.php sends a lot of messages at once
|
||||
static $processorid = null;
|
||||
|
||||
//prevent users from getting popup notifications of messages to themselves (happens with forum notifications)
|
||||
if ($message->useridfrom!=$message->useridto) {
|
||||
$processor = $DB->get_record('message_processors', array('name'=>'popup'));
|
||||
if ($eventdata->userfrom->id!=$eventdata->userto->id) {
|
||||
if (empty($processorid)) {
|
||||
$processor = $DB->get_record('message_processors', array('name'=>'popup'));
|
||||
$processorid = $processor->id;
|
||||
}
|
||||
$procmessage = new stdClass();
|
||||
$procmessage->unreadmessageid = $message->id;
|
||||
$procmessage->processorid = $processor->id;
|
||||
$procmessage->unreadmessageid = $eventdata->savedmessageid;
|
||||
$procmessage->processorid = $processorid;
|
||||
|
||||
//save this message for later delivery
|
||||
$DB->insert_record('message_working', $procmessage);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue