mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
cron unenrolment of manual should takes place in the main cron, MDL-10181
This commit is contained in:
parent
eff9c473a6
commit
cf05753492
2 changed files with 11 additions and 30 deletions
|
@ -142,13 +142,19 @@
|
||||||
|
|
||||||
mtrace('Removing expired enrolments ...', ''); // See MDL-8785
|
mtrace('Removing expired enrolments ...', ''); // See MDL-8785
|
||||||
$timenow = time();
|
$timenow = time();
|
||||||
if ($oldenrolments = get_records_select('role_assignments', "timeend > 0 AND timeend < '$timenow'")) {
|
$somefound = false;
|
||||||
mtrace(count($oldenrolments).' to delete');
|
// find courses where limited enrolment is enabled
|
||||||
|
if($limitedcourses = get_records_select('course', 'enrolperiod > 0')) {
|
||||||
|
foreach($limitedcourses as $course) {
|
||||||
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||||
|
$oldenrolments = get_records_select('role_assignments', 'timeend > 0 AND timeend < ' . $timenow . ' AND contextid = ' . $context->id);
|
||||||
foreach ($oldenrolments as $oldenrolment) {
|
foreach ($oldenrolments as $oldenrolment) {
|
||||||
if (role_unassign($oldenrolment->roleid, $oldenrolment->userid, 0, $oldenrolment->contextid)) {
|
role_unassign($oldenrolment->roleid, $oldenrolment->userid, 0, $oldenrolment->contextid);
|
||||||
mtrace("Deleted expired role assignment $oldenrolment->roleid for user $oldenrolment->userid from context $oldenrolment->contextid");
|
$somefound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if($somefound) {
|
||||||
mtrace('Done');
|
mtrace('Done');
|
||||||
} else {
|
} else {
|
||||||
mtrace('none found');
|
mtrace('none found');
|
||||||
|
|
|
@ -232,31 +232,6 @@ function process_config($config) {
|
||||||
function cron() {
|
function cron() {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
|
|
||||||
// Delete all assignments from the database that have already expired
|
|
||||||
|
|
||||||
$timenow = time();
|
|
||||||
|
|
||||||
if ($assignments = get_records_sql("SELECT ra.*, c.instanceid as courseid FROM
|
|
||||||
{$CFG->prefix}role_assignments ra,
|
|
||||||
{$CFG->prefix}context c
|
|
||||||
WHERE ra.enrol = 'manual'
|
|
||||||
AND ra.timeend > 0
|
|
||||||
AND ra.timeend < $timenow
|
|
||||||
AND ra.contextid = c.id
|
|
||||||
AND c.contextlevel = ".CONTEXT_COURSE)) {
|
|
||||||
foreach ($assignments as $assignment) {
|
|
||||||
if ($course = get_record('course', 'id', $assignment->courseid)) {
|
|
||||||
if (empty($course->enrolperiod)) { // This overrides student timeend
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
role_unassign($assignment->roleid, $assignment->userid, 0, $assignment->contextid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Notify users about enrolments that are going to expire soon!
|
// Notify users about enrolments that are going to expire soon!
|
||||||
|
|
||||||
if (empty($CFG->lastexpirynotify)) {
|
if (empty($CFG->lastexpirynotify)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue