Does "External DB plugin" works on Moodle 2.0?

Does "External DB plugin" works on Moodle 2.0?

by Jordi Martínez -
Number of replies: 19

Hi everybody again:

I have spend a lot of time trying to do work this plugin on Moodle 2.0 and I couldn't.

I see its PHP code and I think it have bugs that make it doesn't work.

Anymore has tryied ext. DB enrolment plugin on Moodle 2.0?

Pleaseeeeee

Thanks a lot!

Average of ratings: -
In reply to Jordi Martínez

Re: Does "External DB plugin" works on Moodle 2.0?

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
Hi Jordi,

I have just tried it in my local test environment and it works as expected. I'm using Moodle 2.0RC2 (current as of today) and two local MySQL databases (one for Moodle, the other one acting as the external db).

I've run the enrol/databas/cli/sync.php script to create 3400 courses and enrol a single user in the same 3400 courses. I've also logged in with that user and it was actually enrolled into all of them.

It's taken it's time (nearly 17 minutes to log in* and about half an hour to auto-create the 3400 courses), but otherwise working alright.

Saludos.
Iñaki.

* I've had to raise the max_execution_time quite a bit, because I was getting an error about the script going over the max execution time.
Average of ratings: Useful (1)
In reply to Iñaki Arenaza

Re: Does "External DB plugin" works on Moodle 2.0?

by Jordi Martínez -

Thanks Iñaki, I thought I was alone at ext. DB plugin (2.0).

I was trying with Moodle 2.0RC1 and it has some bugs that make plugin doesn't work.

I updated to 2.0RC2 and it works fine.

Your post helped me to find my outdated code, thanks a lot (lot of hours saved)!

inner thought (Why plugin does not create categories? When an update of your fantastic  improved plugin? wink  )

Saludos,

Jordi

In reply to Jordi Martínez

Re: Does "External DB plugin" works on Moodle 2.0?

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

We plan to upgrade our improved plugin in the near future, as we will need it internally smile

We've been pretty busy with other things, and Moodle 2.0 was changing a lot in the enrolment area up to 3 months ago. So we decided to let Moodle 2.0 stabilise and then upgrade our improved plugin.

Saludos.
Iñaki.
In reply to Jordi Martínez

Re: Does "External DB plugin" works on Moodle 2.0?

by Paul Beckett -

I'm new to Moodle, so my problems are likely due to my inexperience....
I'm trying to set up external database enrolment on Moodle 2.0 rc2, but I'm not seeing any of the courses or enrolments in this DB being added.
I've tried following the doc at:http://docs.moodle.org/en/External_database
but I'm still having trouble.
My Moodle tables look like:

SELECT id, category, fullname, shortname, idnumber FROM mdl_course;

+----+----------+--------------------+--------------------+----------+

| id | category | fullname           | shortname          | idnumber |

+----+----------+--------------------+--------------------+----------+

......

|  2 |        1 | Course-1           | Course-1           | Course-1 |

+----+----------+--------------------+--------------------+----------+

SELECT id, auth, username, password, idnumber, firstname, lastname FROM mdl_user;

+----+--------+----------+----------------------------------+----------+------------+----------+

| id | auth   | username | password                         | idnumber | firstname  | lastname |

+----+--------+----------+----------------------------------+----------+------------+----------+

......

|  4 | ldap   | s167     | not cached                       |          | xxx       | xxxx  |

+----+--------+----------+----------------------------------+----------+------------+----------+
Course-1 and the single enrolment to this was manually created.

I've created two mysql tables:

DESCRIBE enrol;

+-----------+--------------+------+-----+---------+-------+

| Field     | Type         | Null | Key | Default | Extra |

+-----------+--------------+------+-----+---------+-------+

| courseid  | varchar(20)  | NO   | PRI |         |       |

| fullname  | varchar(100) | YES  |     | NULL    |       |

| shortname | varchar(50)  | YES  |     | NULL    |       |

| category  | varchar(20)  | YES  |     | NULL    |       |

+-----------+--------------+------+-----+---------+-------+

SELECT * FROM enrol;

+----------+----------+-----------+---------------+

| courseid | fullname | shortname | category      |

+----------+----------+-----------+---------------+

| Course-2 | Course-2 | Course-2  | Miscellaneous |

| 1        | 1        | 1         | Miscellaneous |

+----------+----------+-----------+---------------+

DESCRIBE course;

+----------+--------------+------+-----+-------------------+-----------------------------+

| Field    | Type         | Null | Key | Default           | Extra                       |

+----------+--------------+------+-----+-------------------+-----------------------------+

| userid   | varchar(100) | NO   | PRI |                   |                             |

| courseid | varchar(20)  | NO   | PRI |                   |                             |

| gname    | varchar(100) | YES  |     | NULL              |                             |

| sname    | varchar(100) | YES  |     | NULL              |                             |

| modified | timestamp    | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |

| active   | int(11)      | YES  |     | NULL              |                             |

| role     | varchar(20)  | YES  |     | NULL              |                             |

+----------+--------------+------+-----+-------------------+-----------------------------+

SELECT * FROM course;

+--------+----------+-------+---------+---------------------+--------+---------+

| userid | courseid | gname | sname   | modified            | active | role    |

+--------+----------+-------+---------+---------------------+--------+---------+

| s167   | Course-1 | Paul  | Beckett | 2010-11-25 13:16:50 |      1 | student |

| s167   | Course-2 | Paul  | Beckett | 2010-11-25 15:15:20 |      1 | student |

| s167   | 1        | Paul  | Beckett | 2010-11-25 15:26:03 |      1 | student |

| s167   | 2        | Paul  | Beckett | 2010-11-25 15:26:13 |      1 | student |

+--------+----------+-------+---------+---------------------+--------+---------+


In the Plugins -> Enrolments -> External Database, I have configured this as:

Database Driver: mysqli

<relevant db details>

Local Course field: idnumber

Loca User field: username

Local role field: shortname

Remote course field: userid

Remote user field: courseid

Remote role field: role

New course full name field: fullname

New course short name field: shortname

New course ID number field: courseid

New course category field: category

I'm really stuck at the moment, and would very much appreaciate it if anyone is able to point me in the right direction, or can see what I am dong wrong.
Thanks,

Paul

In reply to Paul Beckett

Re: Does "External DB plugin" works on Moodle 2.0?

by John Andrewartha -

As fare as I can remember external databases are best used for Single Sign On.  Moodle keeps records in it's own DB for everything else.  Hope that helps.

In reply to Paul Beckett

Re: Does "External DB plugin" works on Moodle 2.0?

by Paul Beckett -

As I suspected my previous problem was my fault.... i'd used the category name rather than the category id - causing the sync script to silently fail. My courses are now being populated.
However I can't get my enrolments to populate. Looking through the code in <moodle-home>/enrol/database/lib.php I think it's because the mdl_enrol.enrol needs to equal 'database', but is being created as 'manual'..... however if I update this (using SQL to equal 'database' as I don't know how else I can change it), then the sync script results in the following error:

(mysqli): SELECT  userid,role
FROM uea_enrol WHERE courseid = '1'

-----<hr>
!!! Coding error detected, it must be fixed by a programmer: PHP catchable fatal error !!!
!! Argument 3 passed to enrol_database_plugin::db_get_sql() must be an array, boolean given, called in /usr/local/moodle/2-0/app/enrol/database/lib.php on line 359 and defined !!
!! Stack trace: * line 351 of /lib/setuplib.php: coding_exception thrown
* line 578 of /enrol/database/lib.php: call to default_error_handler()
* line 359 of /enrol/database/lib.php: call to enrol_database_plugin-&gt;db_get_sql()
* line 47 of /enrol/database/cli/sync.php: call to enrol_database_plugin-&gt;sync_enrolments()
!!

PS. I have re-instatlled with 2.0 (rather than 2.0rc2 as in my previous post).  Any help would be greatly appreciated. Thanks, Paul

In reply to Paul Beckett

Re: Does "External DB plugin" works on Moodle 2.0?

by Jordi Martínez -

Hi Paul,

I don't understand what "mdl_enrol.enrol needs to equal 'database', but is being created as manual", can you explain it with other words :-S What are you doing exacly by sql statements.

In my case, I've detected script (enrol/database/cli/sync.php) just can create courses, but enrolments are just created by plugin when a user logins on Moodle.

ps. I'm using 2.0 release too.

Jordi

In reply to Jordi Martínez

Re: Does "External DB plugin" works on Moodle 2.0?

by Paul Beckett -

Jordi,

Thanks for replying. Sorry my post was somewhat opaque.

To try and clarify things a little

mdl_enrol is a database table (in my case MySQL).

mdl_enrol.enrol is a field within that table

 

This is something that is created by Moodle. I then added two seperate tables to contain my enrolment and course data, and configured the enrolments plugin to point at this. After doing this, and running the <moodle-app>/enrol/database/cli/sync.php script, the courses get created, but nobody gets enrolled on them (neither when I run the sync script or when they login).

Looking at the sync script it calls two methods: sync_courses and sync_enrolments. So I was expecting enrolments to get synced by running the script, rather than having to wait until login (which incidentally doesn't work for me either).

If as an administrator in a web browser I go into: Site Administration -> Plugins -> Enrolments -> Manage Enrolments , then in the Instances / Enrolments column I see that none of my courses are being managed by 'External Database', and are instead 'Manual Enrolments'.

Looking at <moodle-app>/enrol/database/lib.php I wondered if the mdl_enrol.enrol field needed to contain the value 'database' rather than 'manual'.

Using a command like:

update mdl_enrol set enrol='database' where id=2;

After doing this, the enrolments get added at the point the user logs in.

Site Administration -> Plugins -> Enrolments -> Manage Enrolments , then I see the enrolments for the course now appear to be being managed by the External Database.

However, I don't think the enrolments are being added at the point I run the sync script as I'd hoped, and the sync script now errors with:

(mysqli): SELECT  userid,role

FROM uea_enrol WHERE courseid = '1'

-----<hr>
!!! Coding error detected, it must be fixed by a programmer: PHP catchable fatal error !!!
!! Argument 3 passed to enrol_database_plugin::db_get_sql() must be an array, boolean given, called in /usr/local/moodle/2-0/app/enrol/database/lib.php on line 359 and defined !!
!! Stack trace: * line 351 of /lib/setuplib.php: coding_exception thrown
* line 578 of /enrol/database/lib.php: call to default_error_handler()
* line 359 of /enrol/database/lib.php: call to enrol_database_plugin-&gt;db_get_sql()
* line 47 of /enrol/database/cli/sync.php: call to enrol_database_plugin-&gt;sync_enrolments()
!!

 

This suggests to me that although I've half got it working how I want, but I've probably broken something else - with who knows what consequences.

I'm new to Moodle, so this is all quite likely to be a lack in my understanding rather than a bug, but any help would be very much appreciated.

Thanks,

Paul

In reply to Paul Beckett

Re: Does "External DB plugin" works on Moodle 2.0?

by Paul Beckett -

Strangely I've now tried setting the mdl_enrol.enrol values back to 'manual' and things are still working.

I'm certain this wasn't the case before - but maybe I'm just going mad.

Probably have to chalk this one up to user error. Sorry everyone.

Thanks,

Paul

In reply to Paul Beckett

Re: Does "External DB plugin" works on Moodle 2.0?

by Jordi Martínez -

Hi Paul,

May be you have log in with one enroled user (and plugin has enroled).

You can try deleting created courses and retrying script (without modifying enrols).

I dound some bug (I think) and searching more. May be tomorrow I explain it (I'm bussy).

Good luck!

 

Jordi

In reply to Paul Beckett

Re: Does "External DB plugin" works on Moodle 2.0?

by Jordi Martínez -

Hi again,

I almost be sure there is a bug on row 294 (/database/lib.php), if you delete this row (not making the join) plugin creates database instances (I think it's 90% a bug because plugin are searching non existing necessary instances (not possible to find it on moodle (because are nonexisting))).

But there is another problem later (Paul, you told about this before), I'm debuggin.

Anyone expert can confirm it (that it is a bug and where to track)?

Thanks, Jordi wink

In reply to Jordi Martínez

Re: Does "External DB plugin" works on Moodle 2.0?

by Jordi Martínez -

Hi again,

I found it big grin

I think there is another bug on row 374 (/database/lib.php). Here code assigns a resultset row to an already used variable name that it's used on the parent bucle. This makes lose a value (names of external user and rol references) of this variable (used on every bucle execution) so the call to db_get_sql on second execution throws an exception and script ends.

I tryed to change the name of this variable on the nested bucle (it begins at 374 row) and plugin works fine on a simple exemple (172 new courses and 7 enrolments with nonexisting database instances).

Anyone can confirm?

Thanks!

Jordi

In reply to Jordi Martínez

Re: Does "External DB plugin" works on Moodle 2.0?

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
At first I was not sure about this, but the more I look at it, the more it looks like you are right. The only thing that confuses me is that it's actually working alright as is in my test setup :-?

Saludos.
Iñaki.
In reply to Iñaki Arenaza

Re: Does "External DB plugin" works on Moodle 2.0?

by Jordi Martínez -

Thanks Iñaki.

Yes, referenced forum post is the same problem.

May be you are log in a enroled user after executing script? I saw the failed script execution by trowing a query to moodle db (mdl_user_enrol) after executing script and before log in any user on moodle. Then I saw there isn't any enrolment. Then, when I log in a user that had to have an enrolment, plugin enrols it.

Thanks to Iñaki and Paul that helps me to find this problem with my integration.

Jordi

In reply to Jordi Martínez

Re: Does "External DB plugin" works on Moodle 2.0?

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
Hi Jordi,

maybe you are right. I'll check it tonight.

Thanks for spotting the bug (it looks like it!).

Saludos.
Iñaki.
In reply to Jordi Martínez

Re: Does "External DB plugin" works on Moodle 2.0?

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
You were 100% right. There are two bugs in sync_enrolments(). The SQL query and the overwritten variable.

I don't think there's a reported bug for this in the tracker (or at least I can't find one righ tnow), so feel free to open a new one and point it to this discussion smile

Saludos.
Iñaki.
In reply to Iñaki Arenaza

Re: Does "External DB plugin" works on Moodle 2.0?

by Gisele Brugger -

Hello Inaki,

I found the same problem .

before applying your patch, I had these errors:

-bash-3.2$ php sync.php
Default exception handler: Coding error detected, it must be fixed by a programmer: PHP catchable fatal error Debug: Argument 3 passed to enrol_database_plugin::db_get_sql() must be an array, boolean given, called in /home/storage/b/3b/91/uniabeu/public_html/moodle2/enrol/database/lib.php on line 359 and defined
* line 351 of /lib/setuplib.php: coding_exception thrown
* line 578 of /enrol/database/lib.php: call to default_error_handler()
* line 359 of /enrol/database/lib.php: call to enrol_database_plugin->db_get_sql()
* line 47 of /enrol/database/cli/sync.php: call to enrol_database_plugin->sync_enrolments()

!!! Coding error detected, it must be fixed by a programmer: PHP catchable fatal error !!!
!! Argument 3 passed to enrol_database_plugin::db_get_sql() must be an array, boolean given, called in /home/storage/b/3b/91/uniabeu/public_html/moodle2/enrol/database/lib.php on line 359 and defined !!
!! Stack trace: * line 351 of /lib/setuplib.php: coding_exception thrown
* line 578 of /enrol/database/lib.php: call to default_error_handler()
* line 359 of /enrol/database/lib.php: call to enrol_database_plugin-&gt;db_get_sql()
* line 47 of /enrol/database/cli/sync.php: call to enrol_database_plugin-&gt;sync_enrolments()
!!

After your patch .. its OK now.

I am using :

Moodle 2.0 (Build: 20101130)

Mysql 5.1.41

PHP :5.2.14

Gracias Gracias Gracias

I have 1224 courses and 36.500 enrols  smile

obs:  in mdl_enrol the field enrol should be set to 'database"  if you had create course with php scripts (my case).

I created the courses, and has already allocate in their categories automatically via php scripts.