Automated CSV file processing (users, courses)

Re: Automated CSV file processing (users, courses)

by Brian Pool -
Number of replies: 2

I think I re-developed what you need.  I had done this some time ago for version 1.9 but just redid it for 3.1.

You simply drop the attached file in the admin/tool/uploaduser directory.  There are then 2 variables inside the script that you need to set.

$customfileLocation = "$CFG->dataroot/moodleimport/userimport.csv";
$defaultdomain = "@yourdomain.com";

The first is where your csv file sits.  Mine is a mount inside the moodledata folder that the csv is dropped into automatically from our student management system (DASL) each night.  The file conforms to the same format as the manual userupload in Moodle and the file is simply an edited version of that (from 3.1).

The second variable is for uploads without email fields.  It will automatically make all new user emails username@yourdomain.com so that the upload functions without emails.  This is the same as putting %u@yourdomain.com in the manual upload.

I then make this a nightly CRON job on my system.

I have been using this system for years.  Automatically makes and updates existing users, adds them to correct course, and into the correct groups.  Makes everything hands off once the courses are in Moodle.

Hope that helps!

I would add this as a upload but the upload feature does not allow me to upload something without it being a full mod, which this is obviously not, since it is a single file.


Brian


Average of ratings: Useful (2)
In reply to Brian Pool

Re: Automated CSV file processing (users, courses)

by Luis de Vasconcelos -

Thanks Brian.

What columns do you need to have in the userimport.csv file?

Can you post and example .csv file?


In reply to Luis de Vasconcelos

Re: Automated CSV file processing (users, courses)

by Brian Pool -

The file is EXACTLY the same as is used to manually upload files through the manual upload.  It is a .csv file.   You do not have to have the email in the file and it will then use the username with the email domain that you specify in the file.  The only required are username, firstname, lastname.  eMail is required by Moodle but as stated I coded around that.  Mine is automatically linked to our student software so the CSV file is created each night on an export.  Then the cron job runs this and imports all new users, class additions, and puts them into the appropriate group as well.


The example file is just one student and is typical. 


Hope that helps!


Brian

Average of ratings: Useful (2)