Uploadusers timing out: run offline?

Uploadusers timing out: run offline?

by Tony Delahunty -
Number of replies: 8

Hi to users of the uploadusers.php script for flatfile upload. We use it to pre-enrol all College users to Moodle, but this being many thousands, running it through the browser as ..../moodle/admin/uploaduser.php soon times out, and changing the timeout settings doesn't even get close. 

Perhaps there's a MySQL/ODBC timeout that could be extended, but it would probably be easier not to run this batch job offline, and so not tie up an online session?  I tried running on the command line - ie as  ../php/php.exe ../uploaduser.php but then it tripped up at the require_login() etc  calls.  Is there an obvious way round this, of running .php code directly on the server without being logged in to a Moodle session?  ie so this could be run as an overnight scheduled task to keep users uploaded.

Average of ratings: -
In reply to Tony Delahunty

Re: Uploadusers timing out: run offline?

by Damon Blanchette -
Hello!  I know this was posted about 10 months ago, but this is the exact question I have.  I want to upload new users from a flatfile outside of Moodle.  Tony, did you have a solution for this?
Thanks,
Damon
In reply to Damon Blanchette

Re: Uploadusers timing out: run offline?

by denis cahalane -
I'm sorry I missed this the first time; comment out the 4 lines at the start of the file:

    require_login();

    if (!isadmin()) {
        error("You must be an administrator to edit users this way.");
    }

(put // at the start of each line) and it should work from the command line for you.

But why not use the flatfile enrolment plugin instead?
In reply to denis cahalane

Re: Uploadusers timing out: run offline?

by Damon Blanchette -
Thanks for the quick reply Denis!  Will the flatfile enrolment plugin add new users to moodle, or only enrol them in a course?  If it will add new users, where can I get information about it?
Thanks again,
Damon
In reply to Damon Blanchette

Re: Uploadusers timing out: run offline?

by denis cahalane -
Sorry Damon, you're quite right; you need the uploadusers to create their accounts, followed by the plugin to register them in courses.
In reply to denis cahalane

Re: Uploadusers timing out: run offline?

by Damon Blanchette -
Hi Denis, unfortunately it's not as easy as commenting out those particular lines of code from the uploaduser.php file.  From the html that gets spit out when I try to run the file from the command line, it gives me a sesskey error and also a "You are not logged in" error.

I had a suggestion from a co-worker: what about changing it to always upload the same file and just having the cron script send an http request to that page?  Seems to me that would work.  Any ideas anyone?
Damon
In reply to denis cahalane

Re: Uploadusers timing out: run offline?

by Damon Blanchette -
I seem to have a solution: I edited the uploaduser.php file to not require anything about logging in - no admin, no sesskey, nothing.  Then, instead of needing a file to upload, I commented out those lines and hard-coded a filename and location.  Now I can just run the file with php from the command line and everything seems to work.  The users are uploaded fine and show up in Moodle.
smile
Does anyone see any huge problems with this that I'm not thinking of?
Damon
In reply to Damon Blanchette

Re: Uploadusers timing out: run offline?

by denis cahalane -
They'll be manual accounts, so if you use ldap you'll want to change that field.
In reply to denis cahalane

Re: Uploadusers timing out: run offline?

by Damon Blanchette -
You can specify login type such as ldap in the flatfile - it's how we originally got most of our users into Moodle.  You need to have "auth" as one of the fields, and set it to "ldap".
Damon