Flatfile course enrolment not working

Flatfile course enrolment not working

by Rob Woof -
Number of replies: 3

I am at my wits' end with this. I have tried everything I can think of (which, given my lack of imagination, isn't much!) and I'm getting nowhere.

Moodle 2.4.7, CentOS 6.4, MySQL 5.1.69, PHP 5.3.27 for test server

Moodle 2.4.6+, Windows Server 2012, MySQL 5.1.68, PHP 5.3.24 for production server

First, a bit of background: The College where I work creates a new Moodle each year, and keeps 3 past years' Moodles available to current students. This allows them to look through past years' lecture notes, assignments, quizzes and results etc. For our 'current year' Moodle, we have LDAP controlling subject (Moodle: course) enrollments. So at this time last year I loaded a CSV flatfile of the 2012 subject enrollments into the 2012 Moodle, which means that students see their 2012 subjects if they log on to the 2012 Moodle.

Now I am trying to load this year's subject enrollments, and NOTHING IS WORKING!

I have tried every possible combination of users::username, users::id and users::idnumber and course::shortname, course::id and course::idnumber. In our case, course::shortname and course::idnumber are identical, so if it uses either of those, it should match.

The Site administration->Plugins->Enrollments->Flat file (CSV) page says it should be users::idnumber and course::idnumber, but I tried the others because it wasn't happy. I initially had a problem with using the wrong line breaks, but that's now sorted. I tried enclosing all fields in quotes, not just the user::idnumber, but that made no difference.

When I use either user::username or user::id, the Cron output gives "Unknown user idnumber or deleted user…".

When I use user::idnumber, both options for course give "Line incorrectly formatted - ignoring". The user::idnumber field contains the LDAP string (e.g. CN=10076746,OU=MooreUsers,O=Moore,C=AU), and since it contains commas it is enclosed in quotes. The fact that it doesn't say "Unknown user idnumber…" leads me to believe that it is correctly receiving the user::id, but not matter what else I supply it gives me "Line incorrectly formatted…".

Here are a few sample lines (user::idnumber, course::idnumber):

add,student,"CN=10076746,OU=MooreUsers,O=Moore,C=AU",BS141
add,student,"CN=10071420,OU=MooreUsers,O=Moore,C=AU",BS121
add,student,"CN=10070683,OU=MooreUsers,O=Moore,C=AU",CM102
add,student,"CN=10082482,OU=MooreUsers,O=Moore,C=AU",BS141

I would value comments and suggestions from those any who use flatfile enrollment successfully.

Cheers,

Rob

Average of ratings: -
In reply to Rob Woof

Re: Flatfile course enrolment not working

by Rob Woof -

Update: I also tried with single quotes around the LDAP student::idnumber string. Still no dice. Also, the "example.txt" file in <moodle root>/enrol/flatfile has a space after each comma, so I tried that as well. No dice.

The "Line incorrectly formatted" error is supposed to be for where the number of fields in the line is neither 4 nor 6. Perhaps the commas in the LDAP string are confusing it.

Still scratching my head.

In reply to Rob Woof

Re: Flatfile course enrolment not working

by Rob Woof -

OK, fixed it (I seem to remember doing the same thing last year, now that I think about it).

The issue is the commas in the LDAP string in the user::idnumber value. Even though it has quotes around it, once Moodle tries to parse it, it goes "there's commas here - there must be too many fields in the line", and throws the "Line incorrectly formatted" error.

In <moodleroot>/enrol/flatfile/lib.php, the line that matches the user contains

if (! $user = $DB->get_record("user", array("idnumber"=>$fields[2],...

If you change "idnumber" to "id" and use the database id of the user instead of the idnumber field, you're in. Likewise you could use "username" instead of "idnumber".

Of course, every Moodle update will overwrite this hack, so you remember to keep it current every time you update Moodle.

In reply to Rob Woof

Ynt: Flatfile course enrolment not working

by oğuzhan menemencioğlu -

We use Moodle 1.9.9 and we encounter another thpe of cron error. We could not find any solution for a while. Checking the limits of your system may be a solution for you too.

I have mention the details, check the link.