Skip to content

Commit

Permalink
MDL-29688 fix user enrolment modification event
Browse files Browse the repository at this point in the history
Fixed invalid event name and usage.
  • Loading branch information
skodak committed Oct 23, 2011
1 parent 3a81b37 commit 358fb4d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions enrol/database/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function sync_user_enrolments($user) {
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);
Expand Down Expand Up @@ -231,7 +231,7 @@ public function sync_user_enrolments($user) {
} 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));
Expand Down Expand Up @@ -488,7 +488,7 @@ public function sync_enrolments($verbose = false) {

// 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");
}
Expand Down Expand Up @@ -520,7 +520,7 @@ public function sync_enrolments($verbose = false) {
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");
}
Expand Down
2 changes: 1 addition & 1 deletion enrol/manual/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function process(course_enrolment_manager $manager, array $users, stdClas
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;
Expand Down
1 change: 1 addition & 0 deletions enrol/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion lib/db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
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 ===
Expand Down
13 changes: 10 additions & 3 deletions lib/enrollib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timesta
$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)) {
Expand All @@ -1114,6 +1115,8 @@ public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timesta
$ue->modifierid = $USER->id;
$ue->timemodified = time();
$DB->update_record('user_enrolments', $ue);

$updated = true;
}
} else {
$ue = new stdClass();
Expand Down Expand Up @@ -1143,6 +1146,10 @@ public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timesta
$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
Expand All @@ -1160,8 +1167,8 @@ public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timesta
/**
* 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
Expand Down Expand Up @@ -1206,7 +1213,7 @@ public function update_user_enrol(stdClass $instance, $userid, $status = NULL, $
// trigger event
$ue->courseid = $instance->courseid;
$ue->enrol = $instance->name;
events_trigger('user_unenrol_modified', $ue);
events_trigger('user_enrol_modified', $ue);
}

/**
Expand Down

0 comments on commit 358fb4d

Please sign in to comment.