MDL-79581 communication: Context is a mandatory field
The API was incorrectly assuming that all uses of the API were for a course, and that the instanceid of the communication instance was a course id. These assumptions are both entirely wrong. The API is intended to support a range of uses including use at the site, user, and activity levels. Furthermore, if a group were to be used, then the instanceid should be of that group's id, and therefore the contextid would need to be fetched or that group's course instead. The only solution here is to add a new contextid field to the table, and implement it all parts of the API.
This commit is contained in:
+4
-3
@@ -164,9 +164,10 @@ function user_update_user($user, $updatepassword = true, $triggerevent = true) {
|
||||
if (!empty($currentrecord) && isset($user->suspended) && $currentrecord->suspended !== $user->suspended) {
|
||||
foreach ($usercourses as $usercourse) {
|
||||
$communication = \core_communication\api::load_by_instance(
|
||||
'core_course',
|
||||
'coursecommunication',
|
||||
$usercourse->id
|
||||
context: \core\context\course::instance($usercourse->id),
|
||||
component: 'core_course',
|
||||
instancetype: 'coursecommunication',
|
||||
instanceid: $usercourse->id
|
||||
);
|
||||
// If the record updated the suspended for a user.
|
||||
if ($user->suspended === 0) {
|
||||
|
||||
Reference in New Issue
Block a user