Moodle

autocreate course on enrol fails with mssql_n

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7
  • Fix Version/s: 1.7.1
  • Component/s: Database SQL/XMLDB
  • Labels:
    None
  • Environment:
  • Database:
    Microsoft SQL
  • Affected Branches:
    MOODLE_17_STABLE
  • Fixed Branches:
    MOODLE_17_STABLE

Description

Autocreation of courses that exist in external database but do not yet exist in moodle fails. If the course already exists, the user will be enrolled with the proper role but the course will not be created otherwise. Course creation at both login time and when manually syncing with the external database by calling:

php ./enrol_database_sync.php

No error is returned in error_log on user login but enrol_database_sync.php does show:

PHP Notice: Undefined index: course in /var/www/html/moodle-cvs/lib/adodb/drivers/adodb-mssql.inc.php on line 785

the course shown here, is what I have enrol_remotecoursefield set to (I've tried changing the name to make sure I'm not hitting a reserved word with no change in result).

Adding some debugging statements to the code, it looks like the problem show up in enrol.php at line 197 where $extcourse is set from the $rs object. With mssql_n as the database for external enrollment, $extcourse ends up blank. Too see why this was I added a print_r($rs); statement just before the while (!$rs->EOF) loop. Here are my results for mssql_n:

adorecordset_mssql_n Object
(
[databaseType] => mssql_n
[dataProvider] => native
[fields] => Array
(
[0] => s07-bi101-03
)
... (rest of output is in rs_mssql.txt attachment)

as you can see, fields[course] is not set but fields[0] is. With the same print_r statement but switching my external database to use a mysql table with similar data I get:

adorecordset_mysql Object
(
[dataProvider] => native
[fields] => Array
(
[0] => sp07-bi103-04
[course] => sp07-bi103-04
)
,,, (rest of output is in rs_mysql.txt attachment)

so field[course] is being set for mysql. If (after switching back to mssql) I change line 197 in enrol.php to:

$extcourse = $rs->Fields(0);

then course creation works but a new PHP notice appears:

PHP Notice: Undefined index: peopleid in /var/www/html/moodle-cvs/lib/adodb/drivers/adodb-mssql.inc.php on line 785

peopleid is what I have enrol_remoteuserfield set to. So the problem may exist there also.

Activity

Hide
Eloy Lafuente (stronk7) added a comment -

Aha, I think I've found it!

obviously, because "enrol_database_sync.php" uses another DB connection, somethings need to be defined when that connection is stabilised. And that code is missing in the enrol_connect() function call.

Although a more correct patch will be created in 1-2 days, could you confirm if this quick fix solves your problem?

  • Edit "enrol/database/enrol.php"
  • In the enrol_connect() function after the PConnect line:

if ($enroldb->PConnect($CFG->enrol_dbhost,$CFG->enrol_dbuser,$CFG->enrol_dbpass,$CFG->enrol_dbname)) {

and before the return line:

return $enroldb;

please, insert one line with this code:

$enroldb->SetFetchMode(ADODB_FETCH_ASSOC);

It should, basically, solve your problem (although some more things must be defined to have that 2nd connection 100% well defined).

Does it work? If so, I'll apply the patch in 1-2 days (going to be out this weekend).

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Aha, I think I've found it! obviously, because "enrol_database_sync.php" uses another DB connection, somethings need to be defined when that connection is stabilised. And that code is missing in the enrol_connect() function call. Although a more correct patch will be created in 1-2 days, could you confirm if this quick fix solves your problem?
  • Edit "enrol/database/enrol.php"
  • In the enrol_connect() function after the PConnect line:
if ($enroldb->PConnect($CFG->enrol_dbhost,$CFG->enrol_dbuser,$CFG->enrol_dbpass,$CFG->enrol_dbname)) { and before the return line: return $enroldb; please, insert one line with this code: $enroldb->SetFetchMode(ADODB_FETCH_ASSOC); It should, basically, solve your problem (although some more things must be defined to have that 2nd connection 100% well defined). Does it work? If so, I'll apply the patch in 1-2 days (going to be out this weekend). Ciao
Hide
Jay Lee added a comment -

Thanks for the quick response! Applied the one line patch as you said. It seems to get further but the script now dies completely when attempting to actually create the new course. Here's what's logged when I run "php enrol_database_sync.php" after adding the 1 line:

=== 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 ===
course s07-bi101-03
Creating Course s07-bi101-03...PHP Fatal error: Call to undefined function: page_create_object() in /var/www/html/moodle/enrol/database/enrol.php on line 569
<br />
<b>Fatal error</b>: Call to undefined function: page_create_object() in <b>/var/www/html/moodle/enrol/database/enrol.php</b> on line <b>569</b><br />

Show
Jay Lee added a comment - Thanks for the quick response! Applied the one line patch as you said. It seems to get further but the script now dies completely when attempting to actually create the new course. Here's what's logged when I run "php enrol_database_sync.php" after adding the 1 line: === 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 === course s07-bi101-03 Creating Course s07-bi101-03...PHP Fatal error: Call to undefined function: page_create_object() in /var/www/html/moodle/enrol/database/enrol.php on line 569 <br /> <b>Fatal error</b>: Call to undefined function: page_create_object() in <b>/var/www/html/moodle/enrol/database/enrol.php</b> on line <b>569</b><br />
Hide
Jay Lee added a comment -

It works! In addition to your one line patch I had to add these two line s near the top of enrol.php

require_once($CFG->dirroot.'/lib/moodlelib.php');
require_once($CFG->dirroot.'/lib/blocklib.php');

as is described in this recent forum post:

http://moodle.org/mod/forum/discuss.php?d=58207

Adding the requires got rid of the php fatal error and allowed course creation and role based enrollment to work. Thanks!

Jay

Show
Jay Lee added a comment - It works! In addition to your one line patch I had to add these two line s near the top of enrol.php require_once($CFG->dirroot.'/lib/moodlelib.php'); require_once($CFG->dirroot.'/lib/blocklib.php'); as is described in this recent forum post: http://moodle.org/mod/forum/discuss.php?d=58207 Adding the requires got rid of the php fatal error and allowed course creation and role based enrollment to work. Thanks! Jay
Hide
Eloy Lafuente (stronk7) added a comment -

Hi Jay,

I've applied changes to CVS (1.7 and HEAD). I haven't required_once() "moodlelib.php", because it's always included automatically and also, I've required "blocklib.php" from "enrol_database_sync.php" itself, instead of doing that from the "enrol.php" library file.

If you can confirm that it's working in your environment, it will be great!

TIA and ciao

Show
Eloy Lafuente (stronk7) added a comment - Hi Jay, I've applied changes to CVS (1.7 and HEAD). I haven't required_once() "moodlelib.php", because it's always included automatically and also, I've required "blocklib.php" from "enrol_database_sync.php" itself, instead of doing that from the "enrol.php" library file. If you can confirm that it's working in your environment, it will be great! TIA and ciao
Hide
Jay Lee added a comment -

Confirmed working on my setup. Courses are now autocreated when pulling from MSSQL. Thanks again for the quick work.

Jay

Show
Jay Lee added a comment - Confirmed working on my setup. Courses are now autocreated when pulling from MSSQL. Thanks again for the quick work. Jay
Hide
Eloy Lafuente (stronk7) added a comment -

Thanks for the perfect feedback, Jay. Changing this to "Resolved".

Show
Eloy Lafuente (stronk7) added a comment - Thanks for the perfect feedback, Jay. Changing this to "Resolved".

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: