Course meta-link enrolment creates and deletes 100s of users ever hour

Course meta-link enrolment creates and deletes 100s of users ever hour

by Brian Merritt -
Number of replies: 15
Picture of Particularly helpful Moodlers

Every time the cron on the course meta-link enrolment runs, it creates new enrolments and then deletes them, every hour.

We have removed any circular references but don't know how to 

Moodle version is 3.8.3 if that helps

Once an hour Moodle spends all it's time enrolling and unenrolling users for no apparent reason.


Average of ratings: -
In reply to Brian Merritt

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Randy Thornton -
Picture of Documentation writers
Brian,

Could you explain the course relationships? How many child courses sync enrolments into the meta course, how many enrolments are there, and what enrolment method do you use in the child courses to first get the users in?

If you are adding and removing lots of enrolments to large number of child courses on a regular basis, say 100 per day for 10 courses, then that's 1,000 changes to sync up to the Meta course. The key will be to see eliminate the initial enrolments in various child courses as the problem. If you child course enrolments are steady, then only the changes to those should synchronize up to the meta course.

Also, since you mention circular references, be sure that you are not doing this: "There is one limitation: you cannot 'nest' metacourses" (https://docs.moodle.org/310/en/Course_meta_link#Examples_of_meta-linked_courses). A diagram of the enrolment flow can help sort that out.
In reply to Randy Thornton

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Brian Merritt -
Picture of Particularly helpful Moodlers
Hi Randy

Thanks for coming back, and link is useful.

Will have a look through the various enrolments and see if I can create some sort of map, thanks!
In reply to Brian Merritt

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Randy Thornton -
Picture of Documentation writers
Brian,

If you have some SQL report plugins like Config Reports (and access to it), this query I did some time ago will show you the relationships in a list: https://docs.moodle.org/310/en/ad-hoc_contributed_reports#All_Meta_courses_with_Parent_and_Child_course_relationships

Randy
In reply to Randy Thornton

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Brian Merritt -
Picture of Particularly helpful Moodlers
Thanks Randy - I have used that and deleted a couple of circular relationships.

Further testing on the dev platform has revealed the issue appears to be a bug (or perhaps unexpected behaviour is a better word) relating to suspended users.

We create many users via LDAP and after they go their own way we suspend them, rather than delete them. That way any existing student or teacher enrolments and associated data are maintained.

However, whilst these users are enrolled in "Parent Course 1" the course meta-link also enrols them in "Child Course 1 and 2". Course meta-link adds the enrolment as a part of the cron job to Child 1 and 2 (let's call that phase 1) and then deletes the enrolment as a part of the same cron job (phase 2).

So with the cron job running once an hour, that equates to hundreds of thousands of enrolments and un-enrolments per day, consuming significant database connections and processing resources.

Not sure if anyone else is suspending users which are still enrolled in a Parent Course and finding this behaviour - if yes I think I will raise this as a tracker.
In reply to Brian Merritt

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Randy Thornton -
Picture of Documentation writers
Brian,

Do you mean suspend the account or suspend the enrolment in a course? In either case, this is how I would expect it to work. A site level account suspension has no effect on anything other than the user ability to log in: enrolments are intact.

A course level enrolment suspension affect several things, like Grade book views, but they are still enroled in the course fully. If a user has a course enrolment and role assignment in the child course, the synchronisation should handle it up to the Parent course (and maintain its suspension status, too.)

This should not really matter if you clear up the circular enrollments. If the suspended user is still enrolled in the Parent course, that is where the actual activity data is and where it should stay.

One thing to consider is you can change the enrolment method of those suspended users in the Parent course: double enrol them as Manual but suspended, then remove them from the Child course enrolment. It will retain the student data in the Parent under a Manual enrolment but take them out of the sync sequence since there's no point any more if they aren't logging in. No point in syncing around lots of old users.
In reply to Randy Thornton

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Brian Merritt -
Picture of Particularly helpful Moodlers
Hi Randy

The trigger appears to the Parent having an enrolment method such as LDAP, which can include adding suspended users, and these users are then enrolled in children and removed from children in every cron job. The problem is trying to keep the suspended user in the Parent course.
In reply to Brian Merritt

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Randy Thornton -
Picture of Documentation writers
Brian,

I'm a bit confused why that would be the issue: if you are enrolling a user and suspending them in the Parent course directly via LDAP, then they won't be part of the Meta process at all. Unless the LDAP enrollment is trying to remove them, nothing should touch them. They won't be synched anywhere.

The Meta process should only be synchronizing the users from the Child courses into the Parent, and those will have a Meta-link enrollment type in the Parent regardless of how they got in Child course and what type of enrollment they have there.
In reply to Randy Thornton

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Brian Merritt -
Picture of Particularly helpful Moodlers
Sorry - my bad! The culprit is database enrolment, not ldap

Any user suspended in database enrolment to the parent gets added to each child and removed as a part of the cron process. At a minimum it seems to be an unwanted feature. The reason users are suspended in database enrolment is so that their work is not deleted when they move to alumni (one Moodle instance serves all academic years. Major courses are rolled over new without users, but a number of the supporting courses are not, hence the problem.
In reply to Randy Thornton

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Brian Merritt -
Picture of Particularly helpful Moodlers
@randy - is there a way to do manual enrolments with user suspended to prove my case? Or another method preferably simpler to set up than database enrolment?
In reply to Brian Merritt

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Randy Thornton -
Picture of Documentation writers
Manual is the simplest to work with for setting up suspensions. You can do it in bulk with the Upload user using the enrolstatus field if you want: https://docs.moodle.org/310/en/Upload_users#Enrolment_fields.

The issue for external db enrolments (and for Cohorts too for that matter) is that the setting of how to handle suspended enrolments is a global setting for everyone in that method, not per user. So, when you set up the External unenrol action, you don't have any choice but to apply that to everyone.
In reply to Randy Thornton

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Brian Merritt -
Picture of Particularly helpful Moodlers
I / we really appreciate your time on this! Will do that next.

I set up a Moodle 3.8.3 instance with cron and both database and course meta-link enrolments but removing a user from the database appears to have no effect because the database setting on the live system is to keep the user enrolled. Unless I have missed a trick, external database doesn't have a suspend attribute per se. You just remove the user from the external database and the Moodle setting decides whether to remove the parent enrolment or not, in the case of the system I am working with.

We got up to nearly 1 million meta-link enrolment creations and deletions per day, so had to turn meta-link enrolment down to a once per day early in the morning cron task whilst we debug this.
In reply to Randy Thornton

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Brian Merritt -
Picture of Particularly helpful Moodlers
Hi Randy - I ended up having to dig into the php code, and found the config plugin option "enrol_meta" "unenrolaction" which my client had set to 0 (zero), which basically says delete all enrolments if either the parent course user is unenroled (not the case) or where the role assigned is different to the one expected in the meta link child. I will review the roles set, but in the meantime we can set the unenrolaction to 1 which is just leave the enrolment in place which is what they do on the parent anyway.
In reply to Brian Merritt

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Randy Thornton -
Picture of Documentation writers
So, they had different settings on how to handle the unenrolment in the different courses in the link? That would certainly mess things up.
In reply to Randy Thornton

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Brian Merritt -
Picture of Particularly helpful Moodlers
What makes it complicated is the setting for "keep enrolling new students but leave existing students enrolled" is called "disable enrolment" on the settings. It was only looking at the code (often necessary with Moodle I guess) that we could see what was happening.
In reply to Brian Merritt

Re: Course meta-link enrolment creates and deletes 100s of users ever hour

by Randy Thornton -
Picture of Documentation writers
Ah, yes, since for external db enrolments, it is keying off whether the user is even present in the external db table or not. If they are, it is handling them normally, and if not, it does whatever that settings indicates for unenrol.

It would be a lot clearer if there was a column for status in the external table, which would mirror what is actually happening in the Moodle enrolments database. But, it doesn't.