Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-37974 add "Disable course enrolment" expiration action for manual…

… enrolments

Commit amended by Petr Skoda to match recommended coding style.
  • Loading branch information...
commit 80f1c6adc0703faf026906607f6d26b1820c60cd 1 parent b3be471
@MorrisR2 MorrisR2 authored skodak committed
View
8 enrol/manual/lib.php
@@ -340,7 +340,7 @@ public function sync(progress_trace $trace, $courseid = null) {
$rs->close();
unset($instances);
- } else if ($action == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
+ } else if ($action == ENROL_EXT_REMOVED_SUSPENDNOROLES or $action == ENROL_EXT_REMOVED_SUSPEND) {
$instances = array();
$sql = "SELECT ue.*, e.courseid, c.id AS contextid
FROM {user_enrolments} ue
@@ -355,8 +355,10 @@ public function sync(progress_trace $trace, $courseid = null) {
$instances[$ue->enrolid] = $DB->get_record('enrol', array('id'=>$ue->enrolid));
}
$instance = $instances[$ue->enrolid];
- // Always remove all manually assigned roles here, this may break enrol_self roles but we do not want hardcoded hacks here.
- role_unassign_all(array('userid'=>$ue->userid, 'contextid'=>$ue->contextid, 'component'=>'', 'itemid'=>0), true);
+ if ($action == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
+ // Remove all manually assigned roles here, this may break enrol_self roles but we do not want hardcoded hacks here.
+ role_unassign_all(array('userid'=>$ue->userid, 'contextid'=>$ue->contextid, 'component'=>'', 'itemid'=>0), true);
+ }
$this->update_user_enrol($instance, $ue->userid, ENROL_USER_SUSPENDED);
$trace->output("suspending expired user $ue->userid in course $instance->courseid", 1);
}
View
1  enrol/manual/settings.php
@@ -33,6 +33,7 @@
// it describes what should happend when users are not supposed to be enerolled any more.
$options = array(
ENROL_EXT_REMOVED_KEEP => get_string('extremovedkeep', 'enrol'),
+ ENROL_EXT_REMOVED_SUSPEND => get_string('extremovedsuspend', 'enrol'),
ENROL_EXT_REMOVED_SUSPENDNOROLES => get_string('extremovedsuspendnoroles', 'enrol'),
ENROL_EXT_REMOVED_UNENROL => get_string('extremovedunenrol', 'enrol'),
);
View
24 enrol/manual/tests/lib_test.php
@@ -304,6 +304,30 @@ public function test_expired() {
$this->assertEquals(4, $DB->count_records('role_assignments', array('roleid'=>$studentrole->id)));
$this->assertEquals(0, $DB->count_records('role_assignments', array('roleid'=>$teacherrole->id)));
$this->assertEquals(1, $DB->count_records('role_assignments', array('roleid'=>$managerrole->id)));
+
+
+ $manualplugin->set_config('expiredaction', ENROL_EXT_REMOVED_SUSPEND);
+ $manualplugin->enrol_user($instance1, $user3->id, $studentrole->id, 0, $now-60);
+ $manualplugin->enrol_user($instance3, $user3->id, $teacherrole->id, 0, $now-60*60);
+ $maninstance1 = $DB->get_record('enrol', array('courseid'=>$course1->id, 'enrol'=>'manual'), '*', MUST_EXIST);
+ $maninstance2 = $DB->get_record('enrol', array('courseid'=>$course3->id, 'enrol'=>'manual'), '*', MUST_EXIST);
+
+ $this->assertEquals(6, $DB->count_records('user_enrolments'));
+ $this->assertEquals(7, $DB->count_records('role_assignments'));
+ $this->assertEquals(5, $DB->count_records('role_assignments', array('roleid'=>$studentrole->id)));
+ $this->assertEquals(1, $DB->count_records('role_assignments', array('roleid'=>$teacherrole->id)));
+ $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance1->id, 'userid'=>$user3->id, 'status'=>ENROL_USER_ACTIVE)));
+ $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance2->id, 'userid'=>$user3->id, 'status'=>ENROL_USER_ACTIVE)));
+
+ $manualplugin->sync($trace, null);
+ $this->assertEquals(6, $DB->count_records('user_enrolments'));
+ $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$instance1->id, 'userid'=>$user3->id)));
+ $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$instance3->id, 'userid'=>$user3->id)));
+ $this->assertEquals(7, $DB->count_records('role_assignments'));
+ $this->assertEquals(5, $DB->count_records('role_assignments', array('roleid'=>$studentrole->id)));
+ $this->assertEquals(1, $DB->count_records('role_assignments', array('roleid'=>$teacherrole->id)));
+ $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance1->id, 'userid'=>$user3->id, 'status'=>ENROL_USER_SUSPENDED)));
+ $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance2->id, 'userid'=>$user3->id, 'status'=>ENROL_USER_SUSPENDED)));
}
public function test_send_expiry_notifications() {
Please sign in to comment.
Something went wrong with that request. Please try again.