Tuesday, September 2, 2014

Monitoring the buggy synch users moodle script - external database

We have been running and external DB authentication synch for about 9 months.  Accounts are created and then pulled by moodle via the moodle plugin authentication external DB.  I am using moodle 2.2

A couple weeks ago, I have a problem with this process.  The script was failing with a SQL error that moodle would cause when a user from the external DB was attempted to be inserted - when it should not.  The account was already there, so moodle should skip it.  I blogged here in more detail about the problem and resolution.

Friday, as I was getting ready to leave for the long weekend.  I ran/peeked at the cron.php script on the moodle.  While peeking, saw a error message.  I do not have a lot of debugging info. showing on the production site, but enough to see the *error writing to DB* error.

I turned on Developer level debugging, ran the script again and with saw the same error blogged about in the linked message.  This time, I did not panic, as I had a pretty good idea where the problem was.  Why was moodle trying to insert or create a user when they were already in the mdl_user table?

The problem that I found and remembered reading about while initially solving this issue - a record in the source or primary user table with a *case inconsistency.  In other words, a username that had upper case letters.  Moodle does not allow upper case letters when account is created manually.  This is the bug.

I double checked the authentication type on the account already in moodle, and it was external DB.  So this account was already created in moodle via a entry in my external DB user table.  When I looked in that table and found the same username BUT with a couple capitol letters in the username, I thought that was the problem.  I corrected the username on the external DB side, REMOVING THE UPPERCASE syntax with lowercase.

I ran the script again and the error was gone.  The account coming from the external DB was judged by moodle to already be in place - thank you.

Why did moodle judge the record as not already in place while the username has two uppercase letters?  Shoudnt moodle simply force them to lowercase and avoid the issue?  Moodle forces usernames, when you create manually, to lowercase - why does the external DB script synch_users.php act differently?

Not sure of the answer - but the solution, I am sure of.

Solution = change uppercase letters in external DB username to all lowercase - then moodle behaves as expected.

No comments:

Post a Comment