I have tested it locally on a test server, but I wouldn't recommend anyone using it on a production server until someone knowlegded enough (Martin L.? Penny Leach?, Patrick Li?) reviews it.
Also, as English is not my native language, someone should have a look at the descriptions of each configuration page field (corrections are welcome!).
This new version is heavily based on work done by Marting Langhoff (as part of their tairawhiti development branch), but all of the bugs are mine.
I have patches against MOODLE_15_STABLE, HEAD and MOODLE_16_MULTIENROL. As they are very small, I will follow up to this message with each one of them (pity I can only attach one file per post).
Fixes, corrections, patches and comments are very welcome!
Saludos. Iñaki.
Merry Christmas! Bon Nadal! Felíz Navidad!
(PS:Good luck that I was monitoring this forum! It's safer bet to post them to the enrolment plugins forum.)
Thank you very much for improving the database enrolment plugin


After that's done, we should try and re-merge this patch against the result. How did you develop it? The patch seems to hint at being done on GIT -- perhaps you can rebase it? (See discussions on git list about git-rebase)
I hate to ask you to re-work this when you sent us really good patches against all known versions of the code... but we have several branches where things were happening (HEAD, artena, MOODLE_16_MULTIENROL and yours).
If you have it in git as I suspect, perhaps you can send me a string of patches generated with git-format-patch --mbox --signoff -o somedir ?
Yes, I have a local git repository where I have done all the changes (just the database enrolment plugin so far). I merge upstream from your git repository for MOODLE_15_STABLE (and much the same for HEAD and MULTIENROL).
I'll have a look at that rebase thing -- I'm rather new to git-- and see what I can do (ditto for the patches).
Saludos. Iñaki.
P.S. I have quickly read your email, but I've been really busy today. I'll read it carefully tomorrow and send you a response asap.
If you have been doing small granular commits in your local git repo, you should be able to export just those commits. There are some options:
- use
gitk
and right click on the commits and hit "write commit to file" - use
git-format-patch --mbox -o .patchesforupstream --signoff <upstreambranch>
- use
git-rebase <upstreambranch>
and thengit-format-patch --mbox -o .patchesforupstream --signoff <upstreambranch>
Actually you can probably get away without doing git-rebase
, as it may get more complicated if the rebase fails with conflicts.
If that happens you will have a .dotest directory that has all the patches it's trying to apply. If you resolve the conflict, then do git-am --resolved
and it will continue rebasing (or you can do cg-reset;git-am --skip
if you want to skip it).
To break out of the rebasing if it's not working for you and you want to cancel, you have to restore your local head (usually called master) to what it was before you started rebasing. git-rebase
hides it in .git/ORIG_HEAD
-- just cp .git/ORIG_HEAD .git/refs/heads/master ; cg-reset
.
All greek?
Mostly, but in the end I have taken the easy road (this time). As I have only one thing to patch (enrolment database + associated lang file), I have checked out a clean git HEAD repository, copied my files over the ones there, and thanks to a little cg/git magic (cg-commit + git-format-patch), voila! a patch ready to go
I promise I'll do my homework and test all the things you have written above, but I didn't want to mess too much with this too right now
Saludos. Iñaki.
P.S. The patch is attached to this message.
I have reworked the patch to comply with everything you told me by email (renaming, undescores, etc.)
I have tested both installation from scratch and upgrading from an existing stock1.6dev install. Obviously, teacher enrolment/unenrolment only works if you fill in the new config variables, but the rest of the functionality is completely working even without them.
One small "gotcha" with respect to course autocreation tough. In the current 1.6dev version, autocreated courses get their fullname, shortname and 'externalid' value from the value found in the (student) enrolment table. The new version uses config variables to specify the (external) table where courses' details are to be found, and the names of the fields where the above informations are stored. So unless you fill in this new variables, courses won't be autocreated (in fact you'll get SQL errors in your logs). Should I code something to fall-back to existing behaviour in case you don't fill in the values?
In addition to that, I have reworked the patch for 1.5.3+. Now it should work with existing installations aswell. To get the new functionality you have to fill in the new config variables, just like the 1.6dev version, but existing functionality works as expected.
Saludos. Iñaki.
How is going your improved database enrolment plugin ? i just found this thread and wanna know if the plugin is usable enough to apply to the moodle instalation of the univerity i`m working for.
If I were you, I would test it in a lab environment first and see if you find any trouble with it (and report it back to me, so I can fix it
Saludos. Iñaki.
patch -p1 < enrol_database_moodle_15_stable.diff
from my moodle folder and it seems to have applied properly and the config screen updates correctly. I entered the values and made the mysql tables. I then attempted to run the sync against and empty database for testing connectivity etc and I get the following errors (there are more, but I figured this gets the idea across). I am testing this on a debian linux box, 2.6 kernel, php PHP 4.4.0-4 (cli).
php enrol_database_sync.php
Notice: Use of undefined constant enrol_db_ - assumed 'enrol_db_' in /usr/share/moodle/enrol/database/enrol.php on line 582
Notice: Use of undefined constant _coursefield - assumed '_coursefield' in /usr/share/moodle/enrol/database/enrol.php on line 582
Notice: Use of undefined constant enrol_db_ - assumed 'enrol_db_' in /usr/share/moodle/enrol/database/enrol.php on line 583
Notice: Use of undefined constant _table - assumed '_table' in /usr/share/moodle/enrol/database/enrol.php on line 583
Notice: Use of undefined constant enrol_db_ - assumed 'enrol_db_' in /usr/share/moodle/enrol/database/enrol.php on line 584
Notice: Use of undefined constant _userfield - assumed '_userfield' in /usr/share/moodle/enrol/database/enrol.php on line 584
Notice: Undefined property: enrol_db_student_userfield in /usr/share/moodle/enrol/database/enrol.php on line 584
Notice: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the rightsyntax to use near 'IS NOT NULL' at line 3 STATEMENT: SELECT DISTINCT course_id
FROM enrollment_student
WHERE IS NOT NULL in /usr/share/moodle/enrol/database/enrol.php on line 588
I used this sync in combination with the ldad auth sync. I ran the user sync first.
Looking at the raw mdl_user_students table enrolments seem to be assigned and the courses were created. However when I enter a course and look at the participants list it is empty. Some courses will show the correctly assigned teacher others nothing.
If I login as a student the correct list of courses shows up in the My Courses list.
Any ideas what would cause this behavior?
I have fixed that, and the new version I have just posted works ok in my test 1.5.3+ version (PHP 4.3.x, MySQL 4.0.x, Apache 1.3.x), and I don't see the behaviour you are describing.
Would you give it a try?
Saludos. Iñaki.
P.S. I have just see that in unenrols students ok, but teachers are not unenroled when running enrol_database_sync.php (but they are when they log in). I'll have a look at it asap.
Cleared out my moodle folder with patched files. Reloaded via apt-get to the latest 1.53. Applied your new patch as before. Logged in and let the database updates run.
I accessed the fresh moodle site with the prior data and I could now see enrollments under participants.
Attempted to run the sync code again. Got some errors based on changed configs, default settings, etc. Updated config settings and ran the sync again and it worked.
Accessed courses again and now I can't see students in the participants list. However if I go under the screen to manually edit student enrollments the students show up there. I do notice that in the raw database user_students none of the students have start or end dates on their enrollments. I don't know if this is causing the issue, but thought it might have something to do with it.
Finally only some teachers are showing up to their assigned courses. Initially they were all showing up, so this may be an issue with subsequent syncs. I will look into this further. Perhaps it is related to the issue you have seen.
I can send you a mysql dump of my test database if you get to the point where you want to look at it. Or perhaps this week I can move my testing site to a publically accessible server.
Running the sync code without setting all the config first is risky at least. There is no check to see if all the variables are filled in, so almost anything could happen (from syntax errors to data deletion). Don't do it
I don't think this is related at all. When you enrol a student manually, the timestart and timeend values are set to 0 too, unless the course has an enrolment duration asigned.
Speakig of which, I have just seen we are not taking this enrolment period into account right now neither for students nor for teachers. I know we have to do it for students, but I'm not sure about teachers. Should teacher enrolments respect that enrolment period too? (manually adding teachers completely ignores this value).
Saludos. Iñaki.
I have just uploaded a new version of the patch (and the whole patchesforupstream series) which includes code to honor the enrolment period for the course.
Saludos. Iñaki.
Could you send me that database dump? (better yet, put it somewhere and send me a link to it, via email). I'm not able to reproduce this behaviour in my test environment. Now that I think of it, would you put a database dump done before any syncing is done, and another one after the sync is done?
Saludos. Iñaki.
P.S. I have just see that in unenrols students ok, but teachers are not unenroled when running enrol_database_sync.php (but they are when they log in). I'll have a look at it asap.
where $remotecoursfield is the name of the field for the course id in the enrolment db and $remoteuserfield is just the same for the user (student/teacher).
To test the plugin, I simply deleted all the contents of the table ($dbtable) where we make the relationship between teachers and courses (just to test the code unenrols every teacher in Moodle). The final result is that no teacher is unenroled when I run the sync script (but they are when they login, as the code paths are quite different).
The reason is the condition 'WHERE $remoteuserfield IS NOT NULL'. If the table is empty, we don't get any records. In addition to that, there is a test just after the query that quits processing if there are no records at all. So every teacher remains enroled. Much the same goes for students (or should go, as I haven't tested this case in such detail, but the code path is the same for both students and teachers).
So the question is, what should we do if we don't get any records from the external enrolment table? Should we keep current moodle enrolments or should we delete them? I guess we should delete them (they will be deleted as soon as the student/teacher logs in), but I would like to hear other (more informed) opinions on this.
Saludos. Iñaki.
[Edit] PS: While researching all this, I have found a new bug in the code (a real stupid mistake on my part), so I'm uploading a new version of the patch right now.
I know this thread is here since last December but I saw it only yesterday.
I tried to patch my 1.5.3+ fresh local Moodle installation with the file enrol_database_moodle_15_stable.diff I found in http://orodruin.escomposlinux.org/~iarenaza/moodle/
but I got the error message
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.
Where am I wrong? What can I do?
Thank you in advance.
I don't know where you got enrol_database_moodle_15_stable.diff from, but there is nothing called like that at the URL you mention
Get enrol_database_moodle_153_20060126.diff.gz (latest as of this writing). It's a gzipped file, so you need to gunzip it first, and then apply the patch.
Saludos. Iñaki.
I downloaded the file enrol_database_moodle_153_20060126.diff.gz file, i decompressed it and I tried the patch but I still got the same error.
May I ask for an help?
I am on MacOs X (unix).
Thank you.

Saludos. Iñaki.
it is now working better but, maybe, I am missing something.
This is what I get.
I updated the /moodle/lang/en/enrol_database.php manually so, I believe, I am mot missing a lot.
What does it mean "Hunk #1 succeeded at 1 with fuzz 1"?

As for the fuzz, it basically says the patch has gone ok, but the lines where the patch should be applied are a little bit different.
Here is a new patch, made against 1.5.3+ (current as of today).
Saludos. Iñaki.
I used it as total stupid beginner guy.
I still didn't prove its value because of the following little questions.
1) As I understand I have to create a student table (and a teacher table) without correlations like... user_table -> users_vs_courses. This means that I have to create more records for the same student asking for more than one course. Nothing against this solution. I just ask for confirmation.
2) it is not really simple (TO ME) understand what the course id is. Is it really the id of the course? If so... where can I (simple moodle user) find it? I should not be allowed to access the mySQL mdl_course table. Ok the short course name is not unique but... I need to know where to read the course ID.
3) Ok I create the external database with two table inside and a student in it. And now? Is the cron responsible to send Moodle to look for new students and teachers?
4) How can I distinguish between "teacher" and "editing teacher" and "hidden teacher"?
5) Which feedback do I receive? Where can I find it?
Thank you for this very interesting solution.
Looking forward for continuing this test.
Say you have a table in that database that has (at least) the following information:
school_student_id, school_course_id
for each and every student that is enrolled into one or more courses, where school_ student_id is the way you identify a student in your academic management system, and much the same goes for school_course_id. For example, in our system, the fields that store these informations are called 'IDAL' (IDentificador de ALumno) which is a numerical id and 'IDASIG' (IDentificador de ASIGnatura), which is an alphanumeric id (like LD2005A).
If you somehow relate this school_student_id with a given Moodle user, and school_course_id with a given Moodle_course, then you can automatically enrol everyone into their courses.
Just the same for the teachers if you have a table that has at least:
school_teacher_id, school_course_id
Of course, you need to relate school_student_id, school_teacher_id and school_course_id to something inside Moodle. Also, bear in mind the table for the teachers and the one for the students may not be the same (it's not in our system).
So you need to tell Moodle which are all the tables you need, and what names have the fields in those tables with the data you need to relate both worlds (Moodle and your external database).
Finally, it's possible (if you want to) autocreate non-existent courses when a student or teacher needs to be enrolled into it. Say you external tables have a tuple that says student '123456' has to be enrolled in course 'LD2005', but that course doesn't exist yet. If you have another external table where all of your courses are stored, with their full name, shortname and school_course_id (the same we used in the students/teachers tables), the plugin can autocreate the course in Moodle (empty or from a given course template) and enroll the student, all in the same go.
Now to the questions
Yes. You have to create one record for every course the student is enrolled into. Just the same for the teachers.
The course id is something (anything) you use to refer to one course. In our system, courses have a fullname (64 characters long, in Spanish and Basque), a shortname (15 characters long in Spanish and Basque again) and a short identifier (8 characters long) that we use as a key and that we call IDASIG. This is what the plugin calls the course id.
Then, when we create courses inside Moodle, we put this IDASIG value in the 'ID Number' field of Moodle courses (which is called 'idnumber' in the database). That way, we can relate both without much trouble.
You can use enrol_database_sync.php (from the command line!) to sync your external database with Moodle, or you can wait until students and teachers log in. Everytime users log in Moodle, Moodle updates their enrolled courses as part of the login process.
Right now, you can't. The plugin currently knows about "students" and "teachers". The rationale behind is that "editing teacher" and "hidden teacher" is something only Moodle knows about. Your normal academic management system doesn't make this difference. So you don't probably have this differentiating information in your external database.
But I guess we could add a couple of new options to catter for this.
If you run the enrol_database_sync.php script, you get the output in the screen (or in your mail, if you run it from cron in Linux/Unix). If you don't use the script and let the work be done when the users log in, you'll get the output in your webserver's logs (or wherever you are sending your PHP error logs).
The logs basically say which student/teacher has been enrolled/unenrolled into/from which course, which courses have been auto-created and any problems encountered (non-existent user, non-existent course, problems connecting to the external database, etc.).
I hope this helps you.
Saludos. Iñaki.
I am starting to understand the environment.
I will continue my test at the light of this explanations.
I'll come back to you to tell my opinion in terms of feebdack and new issue I believe correct.
Bye.
I am still understanding. I beleieve you have as "Primary method of enrolment" the "External Database" and I didn't know you can have more than one enrollment methods at the same time. My problem is... how can it be used (the "External Database" as "Primary method of enrolment")? How can the database select only new students? At the end of the enrollment period I may have thousand of enrollments? Am I wasting server time if the list of 10.000 users has only 1 new name with respect of the last Moodle users update?
But, I told you, let me start with nothing.
In the row of the title of the "section page" (the one with the header4 tag) the col span is wrong.
It is written:
<tr>
<td colspan="2">
<h4><?php print_string("serversettings", "enrol_database") ?></h4>
</td>
</tr>
instead of:
<tr>
<td colspan="3">
<h4><?php print_string("serversettings", "enrol_database") ?></h4>
</td>
</tr>
Thank you for your patience during my Moodle training.
Happy to understand your good work.
Right now, you can just have a primary method of enrolment and internal enrolment (at most). There is a development branch that allows multiple sources of enrollment simultaneously, but it's still experimental and has not been integrated in the official versions of Moodle.
Well, it depends. If you go the sync script route, you may say you're wasting your server time (not that I'd say so) processing your 10,000 users if you are only thinking about new enrolments. But if you take into account that your users can be unenrolled automatically as soon as the enrolment period ends, I wouldn't call it wasted time.
Anyway, if you don't use the sync script and just let Moodle enrol/unenrol students and teachers when they log in (which is the default), then you aren't doing any extra work on your server (to be honest, you are doing just a little bit more work when they log in, but just once at login time).
Thank you very much for the 'bug report'
Saludos. Iñaki.
but I still am not able to use your plugin.
By reading and reading your answers I understood you have your students into moodle and an external db with connections between students (teachers) and courses.
Right (I hope!!!)
But... who do you add students to Moodle without enrolling them into a course?
Soory.
Right
We are using LDAP authentication, wich autocreates users in Moodle (either when they log in, on in a batch with auth_ldap_sync.php) if you want it to.
Bear in mind that Moodle users are neither students nor teachers unless they are enrolled as students/teachers in one or more courses. So using LDAP, database, flat-file uploading and maybe other authentication methods (I havn't explored them all), you can add your students to Moodle without enrolling them into a course.
This 'improved' plugin deals with the enrolment part only. Creating users is an authentication issue, and as such, is not treated in my patch.
Saludos. Iñaki.
I'm working in the windows environment and need some basic guidance on the methods used to apply patches. Any help would be greatly appreciated. We are in the process of bringing up a new moodle installation and I believe your patches will complete our automation efforts. Many thanks for your efforts!
--Ron
I have gotten around the patch question. I was working too late last night. I have found what I needed and successfully applied the patch. However, I am now getting database errors when executing the sync script. It complatins about being able to connect. It is picking up the appropriate credentials as they are repeated correctly in the error message. I successfully use a connection to the same database for external authentication so I know it should work.
Any ideas?
--Ron
Ok, go to lines 547-550, where you'll find:
// Try to connect to the external databaseand add the following line (the bold one):
$enroldb = &ADONewConnection($CFG->enrol_dbtype);
if ($enroldb->PConnect($CFG->enrol_dbhost,$CFG->enrol_dbuser,
$CFG->enrol_dbpass,$CFG->enrol_dbname)) {
// Try to connect to the external database
$enroldb = &ADONewConnection($CFG->enrol_dbtype);
$enroldb->debug = true;
if ($enroldb->PConnect($CFG->enrol_dbhost,$CFG->enrol_dbuser,
$CFG->enrol_dbpass,$CFG->enrol_dbname)) {
and then try again an see what error details you get.
Saludos. Iñaki.
Here's the update.
Last night I was able to get things working, somewhat. Everything seems to be working fine at login; courses are built, students are enrolled. This part is great!
However, when I attempt to run the sync script from the commandlineI am still getting an error attaching to the database: (address, user, password, db masked in log below)
--Ron
Warning: mssql_pconnect(): Unable to connect to server: xxx.xxx.xxx.xx in D:\moo
dle\moodle\lib\adodb\drivers\adodb-mssql.inc.php on line 506
xxx.xxx.xxx.xx: Connection error to server 'xxx.xxx.xxx.xx' with user 'username'
Notice: Error connecting to enrolment DB backend with: xxx.xxx.xxx.xx,username,password
,database in D:\moodle\moodle\enrol\database\enrol.php on line 563
<div class="notifyproblem" align="center">enrol/database cannot connect to serve
r</div><br />
Warning: mssql_pconnect(): Unable to connect to server: xxx.xxx.xxx.xx in D:\moo
dle\moodle\lib\adodb\drivers\adodb-mssql.inc.php on line 506
xxx.xxx.xxx.xx: Connection error to server 'xxx.xxx.xxx.xx' with user 'username'
Notice: Error connecting to enrolment DB backend with: xxx.xxx.xxx.xx,username,password
,database in D:\moodle\moodle\enrol\database\enrol.php on line 563
<div class="notifyproblem" align="center">enrol/database cannot connect to serve
r</div><br />
1.- Make sure your php CLI has the MS-SQL extension loaded and activated (it might be using a differente configuration that your web server PHP extension).
2.- Let's try with non-persistent connections. Edit moodle/enrol/database/enrol.php and go to line 549, and change:
to
and tell me if it makes any difference. By the way, are you running this with Apache or IIS?
Saludos. Iñaki.
This looks very interesting! I can't test this in the middle of the semester, but is there more info on how it auto-creates courses and auto-assigns teachers? I assume that one needs to add fields to the current 2-field external database table which just has student id and course id, is that correct?
As for the course creation, you need to specify the table where the course details are stored, and the name of the relevant fields as well.
This way, you could have everything in one table, or use completely different tables for each part: students, teachers, courses (which is our situation).
Saludos. Iñaki.
This seems just what I need. Can I ask a question though? If I use auto-course creation, will all the courses end up in the same category - the one I have chosen from the drop down list?
Would it be difficult to amend the code so that new courses end up in the required category particularly if I supply this information at runtime. My categories are Year Groups (1-13) and if I arrange for the id of Year 7 to be 7 etc it wouldn't be too difficult to work out that the course called "Year 7 ICT" should go in the Year 7 category. Can this be done?
Thank you