Thank you
Upload User with a predefined CSV rather than chosing the file vial filepicker
Re: Upload User with a predefined CSV rather than chosing the file vial filepicker
Seems like you would need something like /admin/tool/uploadcourse/cli/uploadcourse.php
but for the tool_uploaduser
. That would be a nice contribution to Moodle!
Re: Upload User with a predefined CSV rather than chosing the file vial filepicker
Re: Upload User with a predefined CSV rather than chosing the file vial filepicker
The uploadcourse.php CLI script accepts a --file parameter, which is the CSV file it will process. You could set up a cron job which calls it on a regular basis to process a file in a particular location, then removes it afterwards.
My metacourse link and tutor link blocks (which should really be admin tools, but were created before admin tools were a thing) have a slightly different way of doing things - You can upload a CSV file through a form, or set a path in the block's settings to to a CSV file which will be processed by the block's own cron function.
Either approach would work here, the CLI script approach used by tool_uploadcourse is more flexible, but requires more server config outside of Moodle itself compared using the plugin's own cron functions.
Re: Upload User with a predefined CSV rather than chosing the file vial filepicker
Hello,
just adding my two cents,
if you are using Linux, you may use incrontab (http://linux.die.net/man/5/incrontab),
to only run the script when a file is created of modified on a specified monitored directory,
using inotify events, instead of running a cron every minute, so you don't wast resources.
Re: Upload User with a predefined CSV rather than chosing the file vial filepicker
Thank you for your help, and please excuse me, I didn't get it at first, plus I am a newbie; so what I need to do is create a cli folder in upload user, save the uploadcorse.php in it with a different name "autouploaduser.php" add the following
require_once($CFG->dirroot.'/user/profile/lib.php');
require_once($CFG->dirroot.'/user/lib.php');
require_once($CFG->dirroot.'/group/lib.php');
require_once($CFG->dirroot.'/cohort/lib.php');
require_once('locallib.php');
and change the following on line 156
$defaults = array();
$defaults['category'] = $options['category'];
$defaults['startdate'] = time() + 3600 * 24;
$defaults['newsitems'] = $courseconfig->newsitems;.....
to
$defaults = array();
$defaults['username'] = $courseconfig->username;
$defaults['password'] = $courseconfig->password;
$defaults['firstname'] = $courseconfig->firstname;
$defaults['lastname'] = $courseconfig->lastname;
$defaults['email'] = $CFG->email;
$defaults['idnumber'] = $courseconfig->idnumber;
An amateur yet I need to ask this question how does this script would know what table-row it should write in? shall I change anything else to specify the table-row to indicate to mdl_user rather than mdl_course?
Thanks a million
Re: Upload User with a predefined CSV rather than chosing the file vial filepicker
So this is what I've done so far
removed 'category' => coursecat::get_default()->id, since I didn't know with what to replace it,
line35: $courseconfig with $userconfig and moodlecourse with moodleuser
script attached below, when I run it it gives me that its still looking for course rather than user since the error is "missing value for mandatory fields: fullname, category"
any suggestions?
Re: Upload User with a predefined CSV rather than chosing the file vial filepicker
I think I 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
Re: Upload User with a predefined CSV rather than chosing the file vial filepicker
Thanks Brian.
What columns do you need to have in the userimport.csv file?
Can you post and example .csv file?