External database enrolment synchronization

External database enrolment synchronization

by Ken Herndon -
Number of replies: 6
I'm working with an external database to synchronize enrollments, and have experienced some strange behavior. The documentation (http://docs.moodle.org/en/External_database) states that if I populate my external table and then run the synchronization script (enrol_database_sync.php), then the proper roles will be assigned to the students.

This doesn't appear to be the case. Instead, it appears that each student must actually log in to Moodle before they are actually enrolled in their courses.

In fact, it seems that I don't have to run enrol_database_sync.php at all... if I add or remove entries from my external database table, the proper roles are assigned/unassigned when students log in.

What I would really like, however, is to set up a cron job that runs enrol_database_sync.php periodically and rely on this script to set up the enrollments WITHOUT requiring students to log in to "finish the job", so to speak. I want to make changes to my external database table, run the sync script, and immediately see a correct list of participants for each course (again, without waiting for students to log in).

Does this sound feasible?

Thanks...
Ken Herndon
Average of ratings: -
In reply to Ken Herndon

Re: External database enrolment synchronization

by Gary Marshall -

I believe that is what enrol_database_sync.php was designed for. It can have a bit of overhead so I would not run it more than once every few minutes.

The issue we ran into is that we have an external enrollment system. If the student is already logged into moodle and enrolls in another class they are forced to log out and back in to see it.;

I tried to track down where/how the role_assignments table gets sync'd at login but so far no luck. Any dev around that could answer that?

In reply to Gary Marshall

Re: External database enrolment synchronization

by mark Nicholls -
OK Thanks for the info. I will look into it. So how does it work in theory. Is it just enrollment by clicking to enroll or is there a little more to it.

I am just starting out in Moodle Life and so am not entirely up on the way it authenticates and logs users in to courses that they are enrolled in. I assume it adds it to the DB against the user account to state "yes they are allowed in".

May be a little enlightenment or perhaps somewhere to go for an overview?


In reply to Gary Marshall

Re: External database enrolment synchronization

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The problem is not the tables. The problem is the enrolments of a user are stored inside the user session as part of the login process (to cache them there and avoid lots of expensive database queries at each page load).

So even if you modify the role_assignment table (which is what enrol_database_sync.php does), the user session cache is not updated. Which means the user doesn't see the changes. The only way to 'update' the session cache is by logging out and logging in again.

Saludos. Iñaki.

In reply to Ken Herndon

Re: External database enrolment synchronization

by Jonathan Moore -
Ken,

Check your version of mysql. There is a reported bug regarding this, that bit me as well on a project. You need a mysql version 5.x install in order for the sync script to work properly, at least with Moodle 1.9. In my test case the bug caused the sync script to actually delete all external db enrollments when used on a mysql 4.x installation.

I just went to pull the bug number and I am having trouble finding it. It may have been fixed in more recent versions.

As others have pointed out, even when working properly, anyone currently logged into the system will not see their new enrollments until a login/logout sequence.


In reply to Jonathan Moore

Re: External database enrolment synchronization

by Jason Hollowell -
Picture of Particularly helpful Moodlers
I've just completed enrollment of around 2000 students using the 'upload user' and 'modify user' setting and it wasn't much fun smile

I'd like to setup flatfile enrollment or, better yet, an external database but am not sure I understand the issue here.

If I have my enrollments sync to an external database can I, as the admin, login to Moodle and see all the students enrolled in each course? Likewise, can teachers login and see the students in their courses?

It's ok if students have to logout and back in to see their own enrollments as long as the same enrollment can be viewed by the teachers and admin....Is that possible?

Jason