Commit 358fb4dc authored by Petr Skoda's avatar Petr Skoda
Browse files

MDL-29688 fix user enrolment modification event

Fixed invalid event name and usage.
parent 3a81b376
...@@ -170,7 +170,7 @@ class enrol_database_plugin extends enrol_plugin { ...@@ -170,7 +170,7 @@ class enrol_database_plugin extends enrol_plugin {
if ($e = $DB->get_record('user_enrolments', array('userid'=>$user->id, 'enrolid'=>$instance->id))) { if ($e = $DB->get_record('user_enrolments', array('userid'=>$user->id, 'enrolid'=>$instance->id))) {
// reenable enrolment when previously disable enrolment refreshed // reenable enrolment when previously disable enrolment refreshed
if ($e->status == ENROL_USER_SUSPENDED) { if ($e->status == ENROL_USER_SUSPENDED) {
$DB->set_field('user_enrolments', 'status', ENROL_USER_ACTIVE, array('enrolid'=>$instance->id, 'userid'=>$user->id)); $this->update_user_enrol($instance, $user->id, ENROL_USER_ACTIVE);
} }
} else { } else {
$roleid = reset($roles); $roleid = reset($roles);
...@@ -231,7 +231,7 @@ class enrol_database_plugin extends enrol_plugin { ...@@ -231,7 +231,7 @@ class enrol_database_plugin extends enrol_plugin {
} else if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND or $unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) { } else if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND or $unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
// disable // disable
if ($instance->ustatus != ENROL_USER_SUSPENDED) { if ($instance->ustatus != ENROL_USER_SUSPENDED) {
$DB->set_field('user_enrolments', 'status', ENROL_USER_SUSPENDED, array('enrolid'=>$instance->id, 'userid'=>$user->id)); $this->update_user_enrol($instance, $user->id, ENROL_USER_SUSPENDED);
} }
if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) { if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
role_unassign_all(array('contextid'=>$context->id, 'userid'=>$user->id, 'component'=>'enrol_database', 'itemid'=>$instance->id)); role_unassign_all(array('contextid'=>$context->id, 'userid'=>$user->id, 'component'=>'enrol_database', 'itemid'=>$instance->id));
...@@ -488,7 +488,7 @@ class enrol_database_plugin extends enrol_plugin { ...@@ -488,7 +488,7 @@ class enrol_database_plugin extends enrol_plugin {
// reenable enrolment when previously disable enrolment refreshed // reenable enrolment when previously disable enrolment refreshed
if ($current_status[$userid] == ENROL_USER_SUSPENDED) { if ($current_status[$userid] == ENROL_USER_SUSPENDED) {
$DB->set_field('user_enrolments', 'status', ENROL_USER_ACTIVE, array('enrolid'=>$instance->id, 'userid'=>$userid)); $this->update_user_enrol($instance, $userid, ENROL_USER_ACTIVE);
if ($verbose) { if ($verbose) {
mtrace(" unsuspending: $userid ==> $course->shortname"); mtrace(" unsuspending: $userid ==> $course->shortname");
} }
...@@ -520,7 +520,7 @@ class enrol_database_plugin extends enrol_plugin { ...@@ -520,7 +520,7 @@ class enrol_database_plugin extends enrol_plugin {
continue; continue;
} }
if ($status != ENROL_USER_SUSPENDED) { if ($status != ENROL_USER_SUSPENDED) {
$DB->set_field('user_enrolments', 'status', ENROL_USER_SUSPENDED, array('enrolid'=>$instance->id, 'userid'=>$userid)); $this->update_user_enrol($instance, $userid, ENROL_USER_SUSPENDED);
if ($verbose) { if ($verbose) {
mtrace(" suspending: $userid ==> $course->shortname"); mtrace(" suspending: $userid ==> $course->shortname");
} }
......
...@@ -258,7 +258,7 @@ class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_oper ...@@ -258,7 +258,7 @@ class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_oper
foreach ($user->enrolments as $enrolment) { foreach ($user->enrolments as $enrolment) {
$enrolment->courseid = $enrolment->enrolmentinstance->courseid; $enrolment->courseid = $enrolment->enrolmentinstance->courseid;
$enrolment->enrol = 'manual'; $enrolment->enrol = 'manual';
events_trigger('user_unenrol_modified', $enrolment); events_trigger('user_enrol_modified', $enrolment);
} }
} }
return true; return true;
......
...@@ -6,3 +6,4 @@ information provided here is intended especially for developers. ...@@ -6,3 +6,4 @@ information provided here is intended especially for developers.
required changes in code: required changes in code:
* load_temp_role() is deprecated, use load_temp_course_role() instead, temp role not loaded * load_temp_role() is deprecated, use load_temp_course_role() instead, temp role not loaded
* remove_temp_role() is deprecated, use remove_temp_course_roles() instead * remove_temp_role() is deprecated, use remove_temp_course_roles() instead
* 'user_unenrol_modified' event was renamed to 'user_enrol_modified'
...@@ -73,7 +73,7 @@ course_content_removed - object course table record + context property ...@@ -73,7 +73,7 @@ course_content_removed - object course table record + context property
course_deleted - object course table record + context property course_deleted - object course table record + context property
user_enrolled - object record from user_enrolments table + courseid,enrol user_enrolled - object record from user_enrolments table + courseid,enrol
user_unenrol_modified - object record from user_enrolments table + courseid,enrol user_enrol_modified - object record from user_enrolments table + courseid,enrol
user_unenrolled - object record from user_enrolments table + courseid,enrol,lastenrol user_unenrolled - object record from user_enrolments table + courseid,enrol,lastenrol
==== cohort related events === ==== cohort related events ===
......
...@@ -1103,6 +1103,7 @@ abstract class enrol_plugin { ...@@ -1103,6 +1103,7 @@ abstract class enrol_plugin {
$context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST); $context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST);
$inserted = false; $inserted = false;
$updated = false;
if ($ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) { if ($ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
//only update if timestart or timeend or status are different. //only update if timestart or timeend or status are different.
if ($ue->timestart != $timestart or $ue->timeend != $timeend or (!is_null($status) and $ue->status != $status)) { if ($ue->timestart != $timestart or $ue->timeend != $timeend or (!is_null($status) and $ue->status != $status)) {
...@@ -1114,6 +1115,8 @@ abstract class enrol_plugin { ...@@ -1114,6 +1115,8 @@ abstract class enrol_plugin {
$ue->modifierid = $USER->id; $ue->modifierid = $USER->id;
$ue->timemodified = time(); $ue->timemodified = time();
$DB->update_record('user_enrolments', $ue); $DB->update_record('user_enrolments', $ue);
$updated = true;
} }
} else { } else {
$ue = new stdClass(); $ue = new stdClass();
...@@ -1143,6 +1146,10 @@ abstract class enrol_plugin { ...@@ -1143,6 +1146,10 @@ abstract class enrol_plugin {
$ue->courseid = $courseid; $ue->courseid = $courseid;
$ue->enrol = $name; $ue->enrol = $name;
events_trigger('user_enrolled', $ue); events_trigger('user_enrolled', $ue);
} else if ($updated) {
$ue->courseid = $courseid;
$ue->enrol = $name;
events_trigger('user_enrol_modified', $ue);
} }
// reset primitive require_login() caching // reset primitive require_login() caching
...@@ -1160,8 +1167,8 @@ abstract class enrol_plugin { ...@@ -1160,8 +1167,8 @@ abstract class enrol_plugin {
/** /**
* Store user_enrolments changes and trigger event. * Store user_enrolments changes and trigger event.
* *
* @param object $ue * @param stdClass $instance
* @param int $user id * @param int $userid
* @param int $status * @param int $status
* @param int $timestart * @param int $timestart
* @param int $timeend * @param int $timeend
...@@ -1206,7 +1213,7 @@ abstract class enrol_plugin { ...@@ -1206,7 +1213,7 @@ abstract class enrol_plugin {
// trigger event // trigger event
$ue->courseid = $instance->courseid; $ue->courseid = $instance->courseid;
$ue->enrol = $instance->name; $ue->enrol = $instance->name;
events_trigger('user_unenrol_modified', $ue); events_trigger('user_enrol_modified', $ue);
} }
/** /**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment