Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.7
-
Fix Version/s: 1.7.1
-
Component/s: Database SQL/XMLDB
-
Labels:None
-
Environment:HideRHEL4u4 x86_64 Apache 2.0.52/PHP 4.3.9 web server
WinXP SP2 / SQL Server 2005 Express Edition DB Server
ODBTP 1.1.4 PHP module compiled w/ mssql support
bug breifly tested with Apache/PHP running on WinXP box also to make sure x86_64 arch wasn't the culpritShowRHEL4u4 x86_64 Apache 2.0.52/PHP 4.3.9 web server WinXP SP2 / SQL Server 2005 Express Edition DB Server ODBTP 1.1.4 PHP module compiled w/ mssql support bug breifly tested with Apache/PHP running on WinXP box also to make sure x86_64 arch wasn't the culprit
-
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.
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?
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
- 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