mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-47162 core_message: Add course id to message eventdata
This commit is contained in:
parent
577bd70d38
commit
cc350fd9c8
34 changed files with 345 additions and 76 deletions
|
@ -122,7 +122,7 @@ abstract class scanner {
|
|||
$subject = get_string('emailsubject', 'antivirus', format_string($site->fullname));
|
||||
$admins = get_admins();
|
||||
foreach ($admins as $admin) {
|
||||
$eventdata = new \stdClass();
|
||||
$eventdata = new \core\message\message();
|
||||
$eventdata->component = 'moodle';
|
||||
$eventdata->name = 'errors';
|
||||
$eventdata->userfrom = get_admin();
|
||||
|
|
|
@ -33,6 +33,7 @@ defined('MOODLE_INTERNAL') || die();
|
|||
* Extra information about event.
|
||||
*
|
||||
* - int messageid: the id of the message.
|
||||
* - int courseid: the id of the related course.
|
||||
* }
|
||||
*
|
||||
* @package core
|
||||
|
@ -46,9 +47,10 @@ class message_sent extends base {
|
|||
* @param int $userfromid
|
||||
* @param int $usertoid
|
||||
* @param int $messageid
|
||||
* @param int|null $courseid
|
||||
* @return message_sent
|
||||
*/
|
||||
public static function create_from_ids($userfromid, $usertoid, $messageid) {
|
||||
public static function create_from_ids($userfromid, $usertoid, $messageid, $courseid = null) {
|
||||
// We may be sending a message from the 'noreply' address, which means we are not actually sending a
|
||||
// message from a valid user. In this case, we will set the userid to 0.
|
||||
// Check if the userid is valid.
|
||||
|
@ -56,6 +58,10 @@ class message_sent extends base {
|
|||
$userfromid = 0;
|
||||
}
|
||||
|
||||
if (is_null($courseid)) {
|
||||
$courseid = SITEID;
|
||||
}
|
||||
|
||||
$event = self::create(array(
|
||||
'userid' => $userfromid,
|
||||
'context' => \context_system::instance(),
|
||||
|
@ -64,7 +70,8 @@ class message_sent extends base {
|
|||
// In earlier versions it can either be the id in the 'message_read' or 'message' table.
|
||||
// Now it is always the id from 'message' table. Please note that the record is still moved
|
||||
// to the 'message_read' table later when message marked as read.
|
||||
'messageid' => $messageid
|
||||
'messageid' => $messageid,
|
||||
'courseid' => $courseid
|
||||
)
|
||||
));
|
||||
|
||||
|
@ -143,6 +150,10 @@ class message_sent extends base {
|
|||
if (!isset($this->other['messageid'])) {
|
||||
throw new \coding_exception('The \'messageid\' value must be set in other.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['courseid'])) {
|
||||
debugging('The \'courseid\' value must be set in other.', DEBUG_DEVELOPER);
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_objectid_mapping() {
|
||||
|
@ -155,6 +166,7 @@ class message_sent extends base {
|
|||
$othermapped = array();
|
||||
// The messages table could vary for older events - so cannot be mapped.
|
||||
$othermapped['messageid'] = array('db' => base::NOT_MAPPED, 'restore' => base::NOT_MAPPED);
|
||||
$othermapped['courseid'] = array('db' => base::NOT_MAPPED, 'restore' => base::NOT_MAPPED);
|
||||
return $othermapped;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ class manager {
|
|||
*
|
||||
* NOTE: to be used from message_send() only.
|
||||
*
|
||||
* @param \stdClass|\core\message\message $eventdata fully prepared event data for processors
|
||||
* @param \core\message\message $eventdata fully prepared event data for processors
|
||||
* @param \stdClass $savemessage the message saved in 'message' table
|
||||
* @param array $processorlist list of processors for target user
|
||||
* @return int $messageid the id from 'message' or 'message_read' table (false is not returned)
|
||||
|
@ -63,11 +63,24 @@ class manager {
|
|||
throw new \coding_exception('Message should be of type stdClass or \core\message\message');
|
||||
}
|
||||
|
||||
if ($eventdata instanceof \stdClass) {
|
||||
if (!isset($eventdata->courseid)) {
|
||||
$eventdata->courseid = null;
|
||||
}
|
||||
|
||||
debugging('eventdata as \stdClass is deprecated. Please use core\message\message instead.', DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/message/lib.php'); // This is most probably already included from messagelib.php file.
|
||||
|
||||
if (empty($processorlist)) {
|
||||
// Trigger event for sending a message - we need to do this before marking as read!
|
||||
\core\event\message_sent::create_from_ids($eventdata->userfrom->id, $eventdata->userto->id, $savemessage->id)->trigger();
|
||||
\core\event\message_sent::create_from_ids(
|
||||
$eventdata->userfrom->id,
|
||||
$eventdata->userto->id,
|
||||
$savemessage->id,
|
||||
$eventdata->courseid
|
||||
)->trigger();
|
||||
|
||||
if ($savemessage->notification or empty($CFG->messaging)) {
|
||||
// If they have deselected all processors and its a notification mark it read. The user doesn't want to be bothered.
|
||||
|
@ -132,7 +145,12 @@ class manager {
|
|||
}
|
||||
|
||||
// Trigger event for sending a message - must be done before marking as read.
|
||||
\core\event\message_sent::create_from_ids($eventdata->userfrom->id, $eventdata->userto->id, $savemessage->id)->trigger();
|
||||
\core\event\message_sent::create_from_ids(
|
||||
$eventdata->userfrom->id,
|
||||
$eventdata->userto->id,
|
||||
$savemessage->id,
|
||||
$eventdata->courseid
|
||||
)->trigger();
|
||||
|
||||
if (empty($CFG->messaging)) {
|
||||
// If messaging is disabled and they previously had forum notifications handled by the popup processor
|
||||
|
|
|
@ -56,6 +56,12 @@ defined('MOODLE_INTERNAL') || die();
|
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class message {
|
||||
/** @var int Course id. */
|
||||
private $courseid;
|
||||
|
||||
/** @var string Module name. */
|
||||
private $modulename;
|
||||
|
||||
/** @var string Component name. */
|
||||
private $component;
|
||||
|
||||
|
@ -104,10 +110,31 @@ class message {
|
|||
/** @var string Name of the attachment. Note:- not all processors support this.*/
|
||||
private $attachname;
|
||||
|
||||
/** @var int The time the message was created.*/
|
||||
private $timecreated;
|
||||
|
||||
/** @var array a list of properties that is allowed for each message. */
|
||||
private $properties = array('component', 'name', 'userfrom', 'userto', 'subject', 'fullmessage', 'fullmessageformat',
|
||||
'fullmessagehtml', 'smallmessage', 'notification', 'contexturl', 'contexturlname', 'savedmessageid',
|
||||
'replyto', 'attachment', 'attachname');
|
||||
private $properties = array(
|
||||
'courseid',
|
||||
'modulename',
|
||||
'component',
|
||||
'name',
|
||||
'userfrom',
|
||||
'userto',
|
||||
'subject',
|
||||
'fullmessage',
|
||||
'fullmessageformat',
|
||||
'fullmessagehtml',
|
||||
'smallmessage',
|
||||
'notification',
|
||||
'contexturl',
|
||||
'contexturlname',
|
||||
'replyto',
|
||||
'savedmessageid',
|
||||
'attachment',
|
||||
'attachname',
|
||||
'timecreated'
|
||||
);
|
||||
|
||||
/** @var array property to store any additional message processor specific content */
|
||||
private $additionalcontent = array();
|
||||
|
|
|
@ -798,7 +798,7 @@ class checker {
|
|||
array('style' => 'font-size:smaller; color:#333;')));
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
$message = new \stdClass();
|
||||
$message = new \core\message\message();
|
||||
$message->component = 'moodle';
|
||||
$message->name = 'availableupdate';
|
||||
$message->userfrom = get_admin();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue