Merge branch 'w24_MDL-37974_m26_manexpire' of git://github.com/skodak/moodle

This commit is contained in:
Dan Poltawski 2013-06-10 11:59:03 +08:00
commit 3178aacd9e
3 changed files with 35 additions and 5 deletions

View File

@ -340,7 +340,7 @@ class enrol_manual_plugin extends enrol_plugin {
$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,10 +355,15 @@ class enrol_manual_plugin extends enrol_plugin {
$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.
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);
$trace->output("suspending expired user $ue->userid in course $instance->courseid, roles unassigned", 1);
} else {
$this->update_user_enrol($instance, $ue->userid, ENROL_USER_SUSPENDED);
$trace->output("suspending expired user $ue->userid in course $instance->courseid, roles kept", 1);
}
}
$rs->close();
unset($instances);

View File

@ -33,6 +33,7 @@ if ($ADMIN->fulltree) {
// 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 File

@ -304,6 +304,30 @@ class enrol_manual_lib_testcase extends advanced_testcase {
$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() {