mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
Merge branch 'MDL-26119_message_logging' of git://github.com/andyjdavis/moodle
This commit is contained in:
commit
64529cb6d2
4 changed files with 31 additions and 16 deletions
|
@ -45,17 +45,17 @@ defined('MOODLE_INTERNAL') || die();
|
|||
* contexturlname - the display text for contexturl
|
||||
*
|
||||
* @param object $eventdata information about the message (component, userfrom, userto, ...)
|
||||
* @return boolean success
|
||||
* @return int|false the ID of the new message or false if there was a problem with a processor
|
||||
*/
|
||||
function message_send($eventdata) {
|
||||
global $CFG, $DB;
|
||||
|
||||
//new message ID to return
|
||||
$messageid = false;
|
||||
|
||||
//TODO: we need to solve problems with database transactions here somehow, for now we just prevent transactions - sorry
|
||||
$DB->transactions_forbidden();
|
||||
|
||||
//flag we'll return indicating that all processors ran successfully
|
||||
$success = true;
|
||||
|
||||
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));
|
||||
|
@ -130,10 +130,10 @@ function message_send($eventdata) {
|
|||
if ($processor=='none' && $savemessage->notification) {
|
||||
//if they have deselected all processors and its a notification mark it read. The user doesnt want to be bothered
|
||||
$savemessage->timeread = time();
|
||||
$DB->insert_record('message_read', $savemessage);
|
||||
$messageid = $DB->insert_record('message_read', $savemessage);
|
||||
} else { // Process the message
|
||||
// Store unread message just in case we can not send it
|
||||
$savemessage->id = $DB->insert_record('message', $savemessage);
|
||||
$messageid = $savemessage->id = $DB->insert_record('message', $savemessage);
|
||||
$eventdata->savedmessageid = $savemessage->id;
|
||||
|
||||
// Try to deliver the message to each processor
|
||||
|
@ -151,12 +151,12 @@ function message_send($eventdata) {
|
|||
|
||||
if (!$pclass->send_message($eventdata)) {
|
||||
debugging('Error calling message processor '.$procname);
|
||||
$success = false;
|
||||
$messageid = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
debugging('Error finding message processor '.$procname);
|
||||
$success = false;
|
||||
$messageid = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,16 +165,16 @@ function message_send($eventdata) {
|
|||
//unread. To prevent this mark the message read if messaging is disabled
|
||||
if (empty($CFG->messaging)) {
|
||||
require_once($CFG->dirroot.'/message/lib.php');
|
||||
message_mark_message_read($savemessage, time());
|
||||
$messageid = message_mark_message_read($savemessage, time());
|
||||
} 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
|
||||
require_once($CFG->dirroot.'/message/lib.php');
|
||||
message_mark_message_read($savemessage, time(), true);
|
||||
$messageid = message_mark_message_read($savemessage, time(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $success;
|
||||
return $messageid;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -41,8 +41,15 @@ $usergroup = optional_param('usergroup', VIEW_UNREAD_MESSAGES, PARAM_ALPHANUMEXT
|
|||
$history = optional_param('history', MESSAGE_HISTORY_SHORT, PARAM_INT);
|
||||
$search = optional_param('search', '', PARAM_CLEAN); //TODO: use PARAM_RAW, but make sure we use s() and p() properly
|
||||
|
||||
$user1id = optional_param('user', $USER->id, PARAM_INT);
|
||||
$user2id = optional_param('id', 0, PARAM_INT);
|
||||
//the same param as 1.9 and the param we have been logging. Use this parameter.
|
||||
$user1id = optional_param(MESSAGE_USER1_PARAM, $USER->id, PARAM_INT);
|
||||
//2.0 shipped using this param. Retaining it only for compatibility. It should be removed.
|
||||
$user1id = optional_param('user', $user1id, PARAM_INT);
|
||||
|
||||
//the same param as 1.9 and the param we have been logging. Use this parameter.
|
||||
$user2id = optional_param(MESSAGE_USER2_PARAM, 0, PARAM_INT);
|
||||
//2.0 shipped using this param. Retaining it only for compatibility. It should be removed.
|
||||
$user2id = optional_param('id', $user2id, PARAM_INT);
|
||||
|
||||
$addcontact = optional_param('addcontact', 0, PARAM_INT); // adding a contact
|
||||
$removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact
|
||||
|
@ -158,6 +165,9 @@ if ($currentuser && !empty($user2) && has_capability('moodle/site:sendmessage',
|
|||
|
||||
$messageid = message_post_message($user1, $user2, $data->message, FORMAT_MOODLE, 'direct');
|
||||
if (!empty($messageid)) {
|
||||
//including the id of the user sending the message in the logged URL so the URL works for admins
|
||||
//note message ID may be misleading as the message may potentially get a different ID when moved from message to message_read
|
||||
add_to_log(SITEID, 'message', 'write', 'index.php?user='.$user1->id.'&id='.$user2->id.'&history=1#m'.$messageid, $user1->id);
|
||||
redirect($CFG->wwwroot . '/message/index.php?usergroup='.$usergroup.'&id='.$user2->id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,9 @@ define('VIEW_BLOCKED','blockedusers');
|
|||
define('VIEW_COURSE','course_');
|
||||
define('VIEW_SEARCH','search');
|
||||
|
||||
define('MESSAGE_USER1_PARAM','user1');
|
||||
define('MESSAGE_USER2_PARAM','user2');
|
||||
|
||||
define('SHOW_ACTION_LINKS_IN_CONTACT_LIST', true);
|
||||
|
||||
define('MESSAGE_SEARCH_MAX_RESULTS', 200);
|
||||
|
@ -1547,6 +1550,7 @@ function message_format_message(&$message, &$user, $format='', $keywords='', $cl
|
|||
/**
|
||||
* Inserts a message into the database, but also forwards it
|
||||
* via other means if appropriate.
|
||||
* @return int|false the ID of the new message or false
|
||||
*/
|
||||
function message_post_message($userfrom, $userto, $message, $format, $messagetype) {
|
||||
global $SITE, $CFG, $USER;
|
||||
|
@ -1764,7 +1768,7 @@ function message_mark_messages_read($touserid, $fromuserid){
|
|||
* @param message an object with an object property ie $message->id which is an id in the message table
|
||||
* @param int $timeread the timestamp for when the message should be marked read. Usually time().
|
||||
* @param bool $messageworkingempty Is the message_working table already confirmed empty for this message?
|
||||
* @return void
|
||||
* @return int the ID of the message in the message_read table
|
||||
*/
|
||||
function message_mark_message_read($message, $timeread, $messageworkingempty=false) {
|
||||
global $DB;
|
||||
|
@ -1778,6 +1782,7 @@ function message_mark_message_read($message, $timeread, $messageworkingempty=fal
|
|||
if (!$messageworkingempty) {
|
||||
$DB->delete_records('message_working', array('unreadmessageid' => $messageid));
|
||||
}
|
||||
$DB->insert_record('message_read', $message);
|
||||
$messagereadid = $DB->insert_record('message_read', $message);
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
return $messagereadid;
|
||||
}
|
||||
|
|
|
@ -1154,7 +1154,7 @@ function quiz_send_notification_emails($course, $quiz, $attempt, $context, $cm)
|
|||
// send confirmation if required
|
||||
if ($sendconfirm) {
|
||||
// send the email and update stats
|
||||
switch (quiz_send_confirmation($a)) {
|
||||
switch (!empty(quiz_send_confirmation($a))) {
|
||||
case true:
|
||||
$emailresult['good']++;
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue