From d587f077ef87367dc9d69ecfee4320ef0a1bc090 Mon Sep 17 00:00:00 2001 From: Jerome Mouneyrac Date: Tue, 15 Mar 2011 17:27:27 +0800 Subject: [PATCH] MDL-26822 enrol_user now save the status + trivial typo change in a (bit) related file --- enrol/self/lib.php | 6 +++--- lib/enrollib.php | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/enrol/self/lib.php b/enrol/self/lib.php index 99f4779c8fc..6a5f38a2cd1 100644 --- a/enrol/self/lib.php +++ b/enrol/self/lib.php @@ -209,12 +209,12 @@ class enrol_self_plugin extends enrol_plugin { $enrol = enrol_get_plugin('self'); $timestart = time(); if ($instance->enrolperiod) { - $tineend = $timestart + $instance->enrolperiod; + $timeend = $timestart + $instance->enrolperiod; } else { - $tineend = 0; + $timeend = 0; } - $this->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $tineend); + $this->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $timeend); add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere! if ($instance->password and $instance->customint1 and $data->enrolpassword !== $instance->password) { diff --git a/lib/enrollib.php b/lib/enrollib.php index 5c338b5008f..ea867c5d3e6 100644 --- a/lib/enrollib.php +++ b/lib/enrollib.php @@ -1014,9 +1014,14 @@ abstract class enrol_plugin { $inserted = false; if ($ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) { - if ($ue->timestart != $timestart or $ue->timeend != $timeend) { - $ue->timestart = $timestart; + //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)) { + $ue->timestart = $timestart; $ue->timeend = $timeend; + if (!is_null($status)) { + $ue->status = $status; + } $ue->modifier = $USER->id; $ue->timemodified = time(); $DB->update_record('user_enrolments', $ue); @@ -1024,7 +1029,7 @@ abstract class enrol_plugin { } else { $ue = new stdClass(); $ue->enrolid = $instance->id; - $ue->status = ENROL_USER_ACTIVE; + $ue->status = is_null($status)?ENROL_USER_ACTIVE:$status; $ue->userid = $userid; $ue->timestart = $timestart; $ue->timeend = $timeend;