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 {
if ($e = $DB->get_record('user_enrolments', array('userid'=>$user->id, 'enrolid'=>$instance->id))) {
// reenable enrolment when previously disable enrolment refreshed
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 {
$roleid = reset($roles);
......@@ -231,7 +231,7 @@ class enrol_database_plugin extends enrol_plugin {
} else if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND or $unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
// disable
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) {
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 {
// reenable enrolment when previously disable enrolment refreshed
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) {
mtrace(" unsuspending: $userid ==> $course->shortname");
}
......@@ -520,7 +520,7 @@ class enrol_database_plugin extends enrol_plugin {
continue;
}
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) {
mtrace(" suspending: $userid ==> $course->shortname");
}
......
......@@ -258,7 +258,7 @@ class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_oper
foreach ($user->enrolments as $enrolment) {
$enrolment->courseid = $enrolment->enrolmentinstance->courseid;
$enrolment->enrol = 'manual';
events_trigger('user_unenrol_modified', $enrolment);
events_trigger('user_enrol_modified', $enrolment);
}
}
return true;
......
......@@ -6,3 +6,4 @@ information provided here is intended especially for developers.
required changes in code:
* 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
* 'user_unenrol_modified' event was renamed to 'user_enrol_modified'
......@@ -73,7 +73,7 @@ course_content_removed - 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_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
==== cohort related events ===
......
......@@ -1103,6 +1103,7 @@ abstract class enrol_plugin {
$context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST);
$inserted = false;
$updated = false;
if ($ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
//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)) {
......@@ -1114,6 +1115,8 @@ abstract class enrol_plugin {
$ue->modifierid = $USER->id;
$ue->timemodified = time();
$DB->update_record('user_enrolments', $ue);
$updated = true;
}
} else {
$ue = new stdClass();
......@@ -1143,6 +1146,10 @@ abstract class enrol_plugin {
$ue->courseid = $courseid;
$ue->enrol = $name;
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
......@@ -1160,8 +1167,8 @@ abstract class enrol_plugin {
/**
* Store user_enrolments changes and trigger event.
*
* @param object $ue
* @param int $user id
* @param stdClass $instance
* @param int $userid
* @param int $status
* @param int $timestart
* @param int $timeend
......@@ -1206,7 +1213,7 @@ abstract class enrol_plugin {
// trigger event
$ue->courseid = $instance->courseid;
$ue->enrol = $instance->name;
events_trigger('user_unenrol_modified', $ue);
events_trigger('user_enrol_modified', $ue);
}
/**
......
Markdown is supported
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