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... That is, if I add or remove entries to/from my external database table, the proper roles are assigned/unassigned when students log in. Running the sync script doesn't seem to do anything at all except generate a large amount of output on the command line.
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 reasonable?
Thanks...
Ken Herndon
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... That is, if I add or remove entries to/from my external database table, the proper roles are assigned/unassigned when students log in. Running the sync script doesn't seem to do anything at all except generate a large amount of output on the command line.
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 reasonable?
Thanks...
Ken Herndon
Of course it does. And as long as all of your users already exist in Moodle (i.e., they have a user account) enrol_database_sync.php will do its job (we are using it, and it does certainly work )
On the other hand, if those user accounts don't exist yet, the script won't do anything at all but crying out loud: this user doesn't exist, so I can't enrol him/her!
So make sure all the required user accounts exist beforehand.
Saludos. Iñaki.
I'm seeing the same behavior... Courses are auto created but no roles assigned. I'm looking into it further.
Users do exist -- first I did a user sync from ldap which created about 20,000 accounts...
The only output I'm getting from the script is...
=== Syncing enrolments for role: admin ===
=== Syncing enrolments for role: coursecreator ===
=== Syncing enrolments for role: editinginstructor ===
=== Syncing enrolments for role: instructor ===
=== Syncing enrolments for role: student ===
=== Syncing enrolments for role: guest ===
=== Syncing enrolments for role: user ===
A quick glance at the enrol_database_sync.php file seems to indicate I should be seeing more... Hopefully I can figure out what's happening -- anybody else having issues with syncing database enrollments?
enrol_database_sync version I have is -- enrol_database_sync.php,v 1.6.2.1 2008/01/02 22:35:33 skodak
Thanks!
Neil S
Users do exist -- first I did a user sync from ldap which created about 20,000 accounts...
The only output I'm getting from the script is...
=== Syncing enrolments for role: admin ===
=== Syncing enrolments for role: coursecreator ===
=== Syncing enrolments for role: editinginstructor ===
=== Syncing enrolments for role: instructor ===
=== Syncing enrolments for role: student ===
=== Syncing enrolments for role: guest ===
=== Syncing enrolments for role: user ===
A quick glance at the enrol_database_sync.php file seems to indicate I should be seeing more... Hopefully I can figure out what's happening -- anybody else having issues with syncing database enrollments?
enrol_database_sync version I have is -- enrol_database_sync.php,v 1.6.2.1 2008/01/02 22:35:33 skodak
Thanks!
Neil S
The issue seems to be coming from the enrol.php sync function around lines:
375 if (!$CFG->enrol_db_disableunenrol) {
376 $sql = "
377 SELECT ra.roleid, ra.userid, ra.contextid
378 FROM {$CFG->prefix}role_assignments ra
379 LEFT OUTER JOIN ({$CFG->prefix}context cn
380 JOIN {$CFG->prefix}course c ON cn.contextlevel = ".CONTEXT_COURSE." AND cn.instanceid = c.id)
381 ON ra.contextid = cn.id
382 WHERE ra.enrol = 'database'" .
383 ($have_role ? ' AND ra.roleid = '.$role->id : '') .
384 ($extcourses
385 ? " AND (c.id IS NULL OR c.{$CFG->enrol_localcoursefield} NOT IN (" . join(",", array_map(array(&$db, 'quote '), $extcourses)) . "))"
386 : '');
I suspect this sql statement is returning too many rows???
Neil S
375 if (!$CFG->enrol_db_disableunenrol) {
376 $sql = "
377 SELECT ra.roleid, ra.userid, ra.contextid
378 FROM {$CFG->prefix}role_assignments ra
379 LEFT OUTER JOIN ({$CFG->prefix}context cn
380 JOIN {$CFG->prefix}course c ON cn.contextlevel = ".CONTEXT_COURSE." AND cn.instanceid = c.id)
381 ON ra.contextid = cn.id
382 WHERE ra.enrol = 'database'" .
383 ($have_role ? ' AND ra.roleid = '.$role->id : '') .
384 ($extcourses
385 ? " AND (c.id IS NULL OR c.{$CFG->enrol_localcoursefield} NOT IN (" . join(",", array_map(array(&$db, 'quote '), $extcourses)) . "))"
386 : '');
I suspect this sql statement is returning too many rows???
Neil S
Hi!
I'm having the same problem with external database sync.
It apears to do nothing at all.
For me it generates NO OUTPUT as well. Only blank screen.
Enrolment works fine with Ext. DB but user needs do login to enrol.
Thats fine! But the same user needs to login again to UNENROL TOO
)))).
Im trying to run enrol_database_sync.php from the browser the same way I do with cron.php. Is that correct?
PS> enrol_database_sync.php gives out blank screeen.... no output... Iwe tryed this on several servers and got the same resoult. When I run cron.php no refrence to sync is displayed too. Oposite of flatfile enrol, it gives me a line of print in cron for every enrol. (flatfile work like a charm).
My mnoodle is Moodle 1.9.1 (Build: 20080515) runing on xampp 1.6.6. WIndows.
Thanks again
Uros
I'm having the same problem with external database sync.
It apears to do nothing at all.
For me it generates NO OUTPUT as well. Only blank screen.
Enrolment works fine with Ext. DB but user needs do login to enrol.
Thats fine! But the same user needs to login again to UNENROL TOO
Im trying to run enrol_database_sync.php from the browser the same way I do with cron.php. Is that correct?
PS> enrol_database_sync.php gives out blank screeen.... no output... Iwe tryed this on several servers and got the same resoult. When I run cron.php no refrence to sync is displayed too. Oposite of flatfile enrol, it gives me a line of print in cron for every enrol. (flatfile work like a charm).
My mnoodle is Moodle 1.9.1 (Build: 20080515) runing on xampp 1.6.6. WIndows.
Thanks again
Uros
Hi again,
Looks like cron.php is not calling db sync.
Here's output of cron:
--- Begin Cron ---
Server Time: Sat, 17 May 2008 13:29:22 -0300 Starting activity modules Processing module function assignment_cron ...done. Processing module function chat_cron ...done. Processing module function forum_cron ...Starting digest processing... Cleaned old digest records done. Processing module function scorm_cron ...done. Finished activity modules Starting blocks Processing cron function for rss_client.... 0 feeds refreshed (took 0.080561 seconds) done. Processing cron function for search....Global searching is not enabled. Nothing performed by search. done. Finished blocks Starting admin reports Finished admin reports Updating languages cache Removing expired enrolments ...none found Starting main gradebook job ... done. Running backups if required... Checking backup status...INACTIVE Backup tasks finished. Running auth crons if required... Running stats cleanup tasks... ...stats cleanup finished Cron script completed correctly Execution took 2.035327 seconds
--- End Cron ---
I examened cron.php and enrol tasks are suposed to run before auth tasks.
As I see no erol tasks in my cron.
Anyone???
thanks
uros
Looks like cron.php is not calling db sync.
Here's output of cron:
--- Begin Cron ---
Server Time: Sat, 17 May 2008 13:29:22 -0300 Starting activity modules Processing module function assignment_cron ...done. Processing module function chat_cron ...done. Processing module function forum_cron ...Starting digest processing... Cleaned old digest records done. Processing module function scorm_cron ...done. Finished activity modules Starting blocks Processing cron function for rss_client.... 0 feeds refreshed (took 0.080561 seconds) done. Processing cron function for search....Global searching is not enabled. Nothing performed by search. done. Finished blocks Starting admin reports Finished admin reports Updating languages cache Removing expired enrolments ...none found Starting main gradebook job ... done. Running backups if required... Checking backup status...INACTIVE Backup tasks finished. Running auth crons if required... Running stats cleanup tasks... ...stats cleanup finished Cron script completed correctly Execution took 2.035327 seconds
--- End Cron ---
I examened cron.php and enrol tasks are suposed to run before auth tasks.
As I see no erol tasks in my cron.
Anyone???
thanks
uros
Hello
I am also kind of looking at a similar solution. I want mdl_grade_transcript table in mysql database to get loaded when I run enrollment cron. I have no idea what an enrollment cron is and how does it function. I searched enrollment cron and came to this forum. I was told that I need to look at the code in enrol.php and look into function enrol_disconnect($enroldb). Any help would be greatly appreciated.
Regards
Amit
I am also kind of looking at a similar solution. I want mdl_grade_transcript table in mysql database to get loaded when I run enrollment cron. I have no idea what an enrollment cron is and how does it function. I searched enrollment cron and came to this forum. I was told that I need to look at the code in enrol.php and look into function enrol_disconnect($enroldb). Any help would be greatly appreciated.
Regards
Amit
Hello,
I downloaded the enrol_db_files_for_19 files and copy them to moodle root (backuped first). But now, when I open the enroll options, just have a blank page. In php.ini, display_erros are on, and error_reporting are 'E_ALL', and turned debug messagens to developer level. Now I'm reciving this error messagens:
Warning: require_once(/var/www/html/moodle/enrol/enrol.class.php) [function.require-once]: failed to open stream: No such file or directory in /var/www/html/moodle/admin/enrol.php on line 20
Fatal error: require_once() [function.require]: Failed opening required '/var/www/html/moodle/enrol/enrol.class.php' (include_path='/var/www/html/moodle/lib/pear:.:/usr/share/pear:/usr/share/php') in /var/www/html/moodle/admin/enrol.php on line 20
And I don't know what to do.
Anyone who can help me?
Thanks,
Alexandre.
I downloaded the enrol_db_files_for_19 files and copy them to moodle root (backuped first). But now, when I open the enroll options, just have a blank page. In php.ini, display_erros are on, and error_reporting are 'E_ALL', and turned debug messagens to developer level. Now I'm reciving this error messagens:
Warning: require_once(/var/www/html/moodle/enrol/enrol.class.php) [function.require-once]: failed to open stream: No such file or directory in /var/www/html/moodle/admin/enrol.php on line 20
Fatal error: require_once() [function.require]: Failed opening required '/var/www/html/moodle/enrol/enrol.class.php' (include_path='/var/www/html/moodle/lib/pear:.:/usr/share/pear:/usr/share/php') in /var/www/html/moodle/admin/enrol.php on line 20
And I don't know what to do.
Anyone who can help me?
Thanks,
Alexandre.
Are you sure the permissions of the new files you have copied are the right ones? If the web server user can't read the files, it won't be able to include/require them, and you'll get that kind of errors.
And sorry for stating the obvious , but are you sure the files are actually there?
Saludos, Iñaki.
回复Alexandre Pezzini
Re: Problems with external database enrollment synchronization
Hello,
I have a view like that:
And the following values for configuration parameters:
enrol_localcoursefield: shortname
enrol_localuserfield: username
enrol_db_localrolefield: shortname
enrol_remotecoursefield: curso
enrol_remoteuserfield: usuario
enrol_db_remoterolefield: funcao
enrol_db_defaultcourseroleid: student
enrol_db_autocreate: yes
The other fields, I think, are not relevant for now.
I create manualy the user usuarioA.
When I run enrol_database_sync.php, I just have a blank page.
I loged in with the user usuarioA, the courses cursoA and cursoB was not create.
Am I doing something wrong?
Thanks,
Alexandre.
I have a view like that:
curso | usuario | funcao |
cursoA | usuarioA | teacher |
cursoA | usuarioB | student |
cursoA | usuarioC | student |
cursoA | usuarioD | student |
cursoB | usuarioA | teacher |
cursoB | usuarioB | student |
cursoB | usuarioC | student |
cursoB | usuarioD | student |
cursoC | usuarioE | teacher |
cursoC | usuarioF | student |
cursoC | usuarioG | student |
cursoC | usuarioH | student |
And the following values for configuration parameters:
enrol_localcoursefield: shortname
enrol_localuserfield: username
enrol_db_localrolefield: shortname
enrol_remotecoursefield: curso
enrol_remoteuserfield: usuario
enrol_db_remoterolefield: funcao
enrol_db_defaultcourseroleid: student
enrol_db_autocreate: yes
The other fields, I think, are not relevant for now.
I create manualy the user usuarioA.
When I run enrol_database_sync.php, I just have a blank page.
I loged in with the user usuarioA, the courses cursoA and cursoB was not create.
Am I doing something wrong?
Thanks,
Alexandre.
Ok so for the white or blank screen its not an issue, moodle prefers not to run it through browser for security reasons. But for the testing purpose what u can do is open enrol_database_sync.php and comment out this code.
if(!empty($_SERVER['GATEWAY_INTERFACE'])){
error_log("should not be called from apache!");
exit;
}
But remember after testing remove the comments.
if(!empty($_SERVER['GATEWAY_INTERFACE'])){
error_log("should not be called from apache!");
exit;
}
But remember after testing remove the comments.
Okay,
But I think nobody replied for Ken's query. So I ask again is there a way so that student's don't have to login to see his/her courses.
Okay I tell you my scenario,
We are using external database enrollment, for that we have saved the student id and course id in external table. Is there a way so that without running cron script and without login student get enrolled in the course.
Can we do it using some moodle function like pass two parameters (userid and courseid) and enroll user in course.
Please suggest,
Thanks
But I think nobody replied for Ken's query. So I ask again is there a way so that student's don't have to login to see his/her courses.
Okay I tell you my scenario,
We are using external database enrollment, for that we have saved the student id and course id in external table. Is there a way so that without running cron script and without login student get enrolled in the course.
Can we do it using some moodle function like pass two parameters (userid and courseid) and enroll user in course.
Please suggest,
Thanks