mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-47162 core_message: debug whenever courseid is missing
Instead of silently defaulting to SITEID when courseid (coming from message_send()/\core\message\manager::send_message()) is missing, now a debugging message is shown to allow developers to fix their messages to, always, include courseid. Raw creation of events via message_sent::create() missing other[courseid] leads to coding exception since now (there shouldn't be any legacy use, as far as they are always created via create_from_ids() when sending a message. Updated upgrade.txt notes a little bit, added references the 3.6 final deprecation issue (MDL-55449) and covered with unit tests.
This commit is contained in:
parent
9d0e8a4f6d
commit
a29bcf7819
5 changed files with 78 additions and 5 deletions
|
@ -44,10 +44,11 @@ defined('MOODLE_INTERNAL') || die();
|
|||
class message_sent extends base {
|
||||
/**
|
||||
* Create event using ids.
|
||||
* @todo MDL-55449 Make $courseid mandatory in Moodle 3.6
|
||||
* @param int $userfromid
|
||||
* @param int $usertoid
|
||||
* @param int $messageid
|
||||
* @param int|null $courseid
|
||||
* @param int|null $courseid course id the event is related with. Use SITEID if no relation exists.
|
||||
* @return message_sent
|
||||
*/
|
||||
public static function create_from_ids($userfromid, $usertoid, $messageid, $courseid = null) {
|
||||
|
@ -58,8 +59,13 @@ class message_sent extends base {
|
|||
$userfromid = 0;
|
||||
}
|
||||
|
||||
// TODO: MDL-55449 Make $courseid mandatory in Moodle 3.6.
|
||||
if (is_null($courseid)) {
|
||||
// Arrived here with not defined $courseid to associate the event with.
|
||||
// Let's default to SITEID and perform debugging so devs are aware. MDL-47162.
|
||||
$courseid = SITEID;
|
||||
debugging('message_sent::create_from_ids() needs a $courseid to be passed, nothing was detected. Please, change ' .
|
||||
'the call to include it, using SITEID if the message is unrelated to any real course.', DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
$event = self::create(array(
|
||||
|
@ -152,7 +158,7 @@ class message_sent extends base {
|
|||
}
|
||||
|
||||
if (!isset($this->other['courseid'])) {
|
||||
debugging('The \'courseid\' value must be set in other.', DEBUG_DEVELOPER);
|
||||
throw new \coding_exception('The \'courseid\' value must be set in other.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ class manager {
|
|||
*
|
||||
* NOTE: to be used from message_send() only.
|
||||
*
|
||||
* @todo MDL-55449 Drop support for stdClass in Moodle 3.6
|
||||
* @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
|
||||
|
@ -58,11 +59,13 @@ class manager {
|
|||
public static function send_message($eventdata, \stdClass $savemessage, array $processorlist) {
|
||||
global $CFG;
|
||||
|
||||
// TODO MDL-55449 Drop support for stdClass in Moodle 3.6.
|
||||
if (!($eventdata instanceof \stdClass) && !($eventdata instanceof message)) {
|
||||
// Not a valid object.
|
||||
throw new \coding_exception('Message should be of type stdClass or \core\message\message');
|
||||
}
|
||||
|
||||
// TODO MDL-55449 Drop support for stdClass in Moodle 3.6.
|
||||
if ($eventdata instanceof \stdClass) {
|
||||
if (!isset($eventdata->courseid)) {
|
||||
$eventdata->courseid = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue