Can't get MySQL enrolment to work

Can't get MySQL enrolment to work

by Ben Wachtel -
Number of replies: 4
I have been trying to set up external database enrollment to a MySQL database. The user creation part is working fine -- when I log in, a new record is created in the user table, pulling in data from MySQL DB. However, no enrollment is created for that user.

I just updated to the latest Moodle stable release (1.9.6+) and am running it on a shared host running OS X Server.

I believe I have all of my External Database Server Settings entered correctly as well as the Enrolment (remote) database fields matching:
"idnumber" for Moodle course table equals "moodlecourse" field in my MySQL DB.
"idnumber" for Moodle user table equals "moodleuser" field in my MySQL DB.

The course is set up with the course ID number 9999, which is the same course number from "moodlecourse" in my MySQL DB.

(The course is set to be not enrollable, but my understanding is that this only affects Internal Enrollment, not external plugins, and anyway, I've tried it with the course set to enrollable as well.)

One thing that may or may not be relevant -- when I run enrol_database_sync.php and auth_db_sync_users.php remotely via OS X Terminal shell, nothing seems to happen and there is no output. I would have thought that this would create corresponding records in the Moodle user table for all of the records in my MySQL user table, as well as creating their enrollments.

Also, I found this here about an enrollment plugin patch:
http://tracker.moodle.org/browse/MDL-18144" title="Auto-link to Moodle Tracker">MDL-18144
Will this help? How do you install this patch?

I would appreciate any suggestions for what to look into to resolve this issue.

Thanks.
Average of ratings: -
In reply to Ben Wachtel

Re: Can't get MySQL enrolment to work

by Scott Krajewski -
Hi Ben,

Yes, you should get output when you run the enrol_database_sync.php script. Have you tried to run it with the highest error reporting on?

Have you tried connecting to the external database via command line on the moodle server to see if there's a mysql access issue?

-- Scott
In reply to Scott Krajewski

Re: Can't get MySQL enrolment to work

by Ben Wachtel -
Hi Scott,

Thanks for the response.

I am able to connect to the MySQL database via the command line. This particular database is also being accessed by a FileMaker Pro database and via PHP pages on a website, which are all working just fine.

I am looking into the output and error reports from our web host.

I just ran the auth_db_sync_users.php script and for the first time it actually imported all the users from my MySQL table.

However, I tried running the enrol_database_sync.php script and didn't do what I expected it should do, although the output in the command line said:
=== Syncing enrolments for role: admin ===
=== Syncing enrolments for role: coursecreator ===
=== Syncing enrolments for role: editingteacher ===
=== Syncing enrolments for role: teacher ===
=== Syncing enrolments for role: student ===
=== Syncing enrolments for role: guest ===
=== Syncing enrolments for role: user ===
=== Syncing enrolments for role: readonly ===
=== Syncing enrolments for role: registrar ===

Let me check out a couple of assumptions with you to make sure I'm doing this right:

External Database enrollment bypasses Internal Enrollment and the need to use an Enrollment Key.

That is, even though I am required to put in an Enrollment Key for every course, users who have an enrollment for that course verified by the external database don't need to enter it -- they should be automatically enrolled either on login or when the enrol_database_sync.php script is run, as long as they are also in the Moodle User table.

I can set "Course enrollable" in course settings to "No" and External Database enrollment will still work.

I've also included screenshots of my External Database enrollment settings and the settings for the test course I am working with:




Thanks again.

Regards,
Ben

In reply to Ben Wachtel

Re: Can't get MySQL enrolment to work

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

That is, even though I am required to put in an Enrollment Key for every course, users who have an enrollment for that course verified by the external database don't need to enter it -- they should be automatically enrolled either on login or when the enrol_database_sync.php script is run, as long as they are also in the Moodle User table.

Absolutely right smile

I can set "Course enrollable" in course settings to "No" and External Database enrollment will still work.

Right again.

I suspect the problem may lie in the authentication part of your site. Are you filling the users 'ID Number' with some information from your external auth db? Enrolment relies on 'ID Number' to match (moodle) internal users to (enrolment) external users. If it can match a given user, she won't be enrolled at all.

Saludos, Iñaki.

In reply to Iñaki Arenaza

Re: Can't get MySQL enrolment to work

by Ben Wachtel -
It seems to be working all of a sudden. On thing I changed was putting data in for "role" although I was under the impression that was optional and could be determined by the "default role" setting.

I'm still working with my web host to get cronjobs running for adding users and syncing enrollments, as I've only been able to get it to work running those scripts manually.

I also need to test whether it works when a user logs in.

Thanks for your help.

-Ben