Skip to content

Commit

Permalink
Merge branch 'w43_MDL-29964_m22_fixenrolevents' of git://github.com/s…
Browse files Browse the repository at this point in the history
…kodak/moodle
  • Loading branch information
Sam Hemelryk committed Nov 1, 2011
2 parents d29f4e0 + 0c2701f commit f94d606
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/enrollib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1133,14 +1133,6 @@ public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timesta
$inserted = true;
}

if ($roleid) {
if ($this->roles_protected()) {
role_assign($roleid, $userid, $context->id, 'enrol_'.$name, $instance->id);
} else {
role_assign($roleid, $userid, $context->id);
}
}

if ($inserted) {
// add extra info and trigger event
$ue->courseid = $courseid;
Expand All @@ -1152,6 +1144,15 @@ public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timesta
events_trigger('user_enrol_modified', $ue);
}

if ($roleid) {
// this must be done after the enrolment event so that the role_assigned event is trigerred aftwerwards
if ($this->roles_protected()) {
role_assign($roleid, $userid, $context->id, 'enrol_'.$name, $instance->id);
} else {
role_assign($roleid, $userid, $context->id);
}
}

// reset primitive require_login() caching
if ($userid == $USER->id) {
if (isset($USER->enrol['enrolled'][$courseid])) {
Expand Down

0 comments on commit f94d606

Please sign in to comment.