Totara Learn Open Discussions

Auto enrolment plugin: problem enrolment date

 
Liesbet Daelemans
Auto enrolment plugin: problem enrolment date
by Liesbet Daelemans - Wednesday, 1 June 2022, 2:09 PM
Group PartnersGroup TXP Site Administrator

Hi,

We are testing the auto enrolment plugin from Moodle on Totara 15.5

For some courses, there is no enrolment date added when the user enrols in a course with auto enrolment. By investigating this, I see that this problem only occurs in ‘old’ courses that were created in 2019 or before.

I’m investigating now if this could be due to the transition from Moodle to Totara when all courses where imported in Totara (the transition was in September 2019) 

Does anyone see the same problem with the auto enrolment plugin on Totara? What could be the cause? And how to resolve this?

Thank you!


Olumuyiwa Taiwo
Re: Auto enrolment plugin: problem enrolment date
by Olumuyiwa Taiwo - Wednesday, 1 June 2022, 5:31 PM
Group Partners

We are seeing a similar issue with the auto enrolment (enrol_auto) and audience (enrol_cohort) enrolment in a TL12.42 instance.

Also, the issue reported at https://totara.community/local/publictracker/issuedetail.php?key=TL-33758 is probably related or has the same root cause.

Our investigation so far has not indicated that this is related to the age of courses (hence my saying 'similar' rather than 'the same'), but after seeing your post we are going to look at that.

What we have found by looking at the code is that the issue started occurring following a change that was made in TL12.41 to fix the handling of incorrect course enrolment timestamps when creating course completion records - https://totara.community/local/publictracker/issuedetail.php?key=TL-33158

Unfortunately Totara Support have been unable to replicate the issue, so in the meantime we have patched both enrol_auto and enrol_cohort to include the timestamp of current time when calling the core enrol_user() function.

That is not a good solution, as it would require patching a several existing enrolment plugins that may be affected by the issue.

Liesbet Daelemans
Re: Auto enrolment plugin: problem enrolment date
by Liesbet Daelemans - Thursday, 2 June 2022, 5:47 AM
Group PartnersGroup TXP Site Administrator

Thank you, Olumuyiwa. 
Further investigation is showing the completionstartonenrol field in the database is set to 1 for courses where no enrolment data is added. (Correct working courses have the value 0 in this field). 


Any experiences with this setting?


Olumuyiwa Taiwo
Re: Auto enrolment plugin: problem enrolment date
by Olumuyiwa Taiwo - Friday, 3 June 2022, 7:47 PM
Group Partners

Hi Liesbet,

We don't have any experience with that setting.

Mark Carey
Re: Auto enrolment plugin: problem enrolment date
by Mark Carey - Wednesday, 22 June 2022, 8:20 PM
Group Partners
I think this started with 12.41. 

  • We have evidence from several sites that it's been happening before that, but those records are very old so I'll discount them.  I think it was introduced in 12.41. On the sites I'm investigating, the update was very clearly when the problem started.
  • It's seen in self-enrolment and audience enrolment at least. While the enrolment is performed and recorded, the 'Time enrolled’ is not recorded and therefore not available to key reports.
  • It's intermittent - sometimes it happens and sometimes it doesn't, which explains why it's hard to reproduce. It feels like the process just doesn't complete.
  • This can be a serious legal issue for clients where completion of compliance training once assigned must be accurate.

I understand that the missing enrol date is course_completion.timeenrolled, as opposed to the time the user was enrolled in the course.

The observable effect is:

  • The enrolment date/time is being recorded in the logs and can be seen from the front end in the Completion Editor in the course 
  • In the logs there is a date-time record of ‘Enrolled via cohort’ and ‘Learner role assigned’

  • But the ‘Time enrolled’ record is ‘Time enrolled: Not set (0)’. If the user was enrolled it would be like this ‘Time enrolled: 10 May 2022, 10:32 (1652178728)’, and that matches the date/time of the enrolment.

  • What it means is that the ‘Date enrolled’ doesn’t appear in Course Completion or Record of Learning Reports.

TL-33158        Fixed the handling of incorrect course enrolment timestamps when creating course completion records
                   Previously, the course completion module set the enrolment date to the
                   current time when there were no user enrolment records. This led to the
                   problem where reports that used the completion data showed the wrong
                   enrolment dates.
                   
                   This patch changes this; now the enrolment time is zero when the course
                   completion record is created for unenrolled users. It is only when the user
                   actually enrols in a course that the timeenrolled value in the completion
                   record is updated.


These code extracts appears to be relevant (I'm not a developer but these were reported to me as part of a developer's investigation):

* completion_completion->_save() now records the status as COMPLETION_STATUS_NOTYETSTARTED (10) when no timeenrolled,  timestarted and timecompleted is provided. Previously, it resulted in status 0 which has no corresponding constant   and is therefore invalid. Any customisations which rely on status 0 should be redesigned around this change.
This code is in the completion_completion->_save() function (referred to above)

$sql = "
        SELECT
            ue.timestart
        FROM
            {user_enrolments} ue
        JOIN
            {enrol} e
        ON (e.id = ue.enrolid AND e.courseid = :courseid)
        WHERE
            ue.userid = :userid
        AND ue.status = :active
        AND e.status = :enabled
        AND (
            ue.timeend = 0
         OR ue.timeend > :now
        )
        AND ue.timestart < :now2
        ORDER BY
            ue.timestart ASC
    ";
    $params = array(
        'enabled'   => ENROL_INSTANCE_ENABLED,
        'active'    => ENROL_USER_ACTIVE,
        'userid'    => $this->userid,
        'courseid'  => $this->course,
        'now'       => $now,
        'now2'      => $now
    );

    if ($enrolments = $DB->get_record_sql($sql, $params, IGNORE_MULTIPLE)) {
        $this->timeenrolled = $enrolments->timestart;
    } else {
        $this->timeenrolled = 0;
    }
}


Craig Eves
Re: Auto enrolment plugin: problem enrolment date
by Craig Eves (Totara Support) - Sunday, 26 June 2022, 2:16 PM
Group Totara

Hi Mark

There is another ticket linked to TL-33158 that has not been fixed yet. This one is TL-33758 

Program enrolment plugin does not update timestarted column in the user_enrolment table

Are the times that the date isn't updated related to courses in programs?

I will link this posting to the ticket and try and progress this.

regards



Tom Wood
Re: Auto enrolment plugin: problem enrolment date
by Tom Wood - Wednesday, 28 September 2022, 3:51 AM
Group Totara

Hi Mark,


Following the creation of TL-34753, a fix for this issue has been included in 13.24, 14.16, 15.11 & 16.5, which were released today.

For further details of this change and all other fixes and improvements that were included in the releases, please see the release notes in the Totara community.

Please don't hesitate to let us know if you have any further problems,

Thanks
Totara Product Support

Liesbet Daelemans
Re: Auto enrolment plugin: problem enrolment date
by Liesbet Daelemans - Tuesday, 4 October 2022, 2:08 AM
Group PartnersGroup TXP Site Administrator

Thank you, Tom!
We discovered this problem when releasing the auto enrolment plugin in May this year.

We searched for the cause (as you can read higher in this discussion) and the 'in some cases' are courses that were migrated from Moodle. Those courses had a different completionstartonenrol value than courses created directly in Totara.
We manually changed the completionstartonenrol field in the database to solve the problem.


Glad to hear Totara is fixing bugs for this plugin!