Command Line User Creation

Command Line User Creation

Steven Dawe -
Erantzun kopurua: 6

Hi 

Appologies if this is A) stupid or B) answered somewhere else (i have searched)

I am v.new to Moodle and using latest (2.6.whatever on lamp) and i want to create a Moodle where little structural interaction is require by general staff - user creation, course creation (barebones) and user enrolement is done for them, by me, automatically.

I have my users authenticate against AD (working) and this creates my users.

I can export to csv from my MIS and wish to use the command line (and CRON) to create courses and enroll the appropriate students onto the courses.

My first problem is that although the users are created when they log in against AD, they wont be enrolled until that process happens - i was hoping to create the users in advance but authenitcate against AD when logging in. i know that you can bulk upload from within Moodle, but i want to do this process daily, automatically.

I hope this makes sense. Advice and guidance appreciated.

Puntuazioen batez bestekoa: -
Steven Dawe(e)ri erantzunda

Re: Command Line User Creation

Howard Miller -
Core developers-ren irudia Documentation writers-ren irudia Particularly helpful Moodlers-ren irudia Peer reviewers-ren irudia Plugin developers-ren irudia
Howard Miller(e)ri erantzunda

Re: Command Line User Creation

Steven Dawe -

Howard this looks great!

Thanks - i will have a go with this.

Are there any gotchas when installing plugins - will i have to reinstall this when i upgrade Moodle?

Steven Dawe(e)ri erantzunda

Re: Command Line User Creation

Howard Miller -
Core developers-ren irudia Documentation writers-ren irudia Particularly helpful Moodlers-ren irudia Peer reviewers-ren irudia Plugin developers-ren irudia

It's not really a Moodle plugin in the normal sense. Just follow the instructions. It needs quite a lot of permissions on your server to work.

Steven Dawe(e)ri erantzunda

Re: Command Line User Creation

Joe Amatrucola -

I have accomplished this same task by using the following 2 plugins (both are called plugins, but they're actually part of Moodle core):

  • LDAP Authentication
    • This is the plugin you are already using to connect your users to your LDAP server.  As you point out, if the LDAP user doesn't already exist in Moodle at the time the user logs in, the user is created.  However, if you add a command to your crontab (see reference here) you can schedule that synchronization to happen as often as you like.  I'm running this command every morning at 4am.
  • External Database Enrolment
    • This plugin allows you to point Moodle at an SQL data source (a table or view/query) which contains a few key pieces of information.  The minimum fields in the external data source are a unique identifier for the Moodle course, and a unique identifier for the Moodle user.  I am using the idnumber for each of these (see reference here).  This external data source is referenced each time a user logs in, and the user's enrolments are updated accordingly - including enrolments and unenrolments.
    • This plugin also permits course creation via a similar process.
    • There is a command line script for this too, which I have running every morning after the LDAP synchronization runs. (see reference here)
    • All of this, of course, presumes that you have access to the tables that drive your SIS, based upon which you can create a view to pull the current student enrolments.
    • It took me a little while to think through exactly how to best set this up for our system, but having done so, I think it was totally worth it in the long run.  As we add and drop students in our SIS, the Moodle enrolments adjust accordingly.
    • A few other thoughts:
      • be sure to read and consider the Potential Gotchas section. For example, in large part for the reason identified here, we don't let users edit their Moodle profiles.
      • Give some serious consideration to how you will handle when a user falls out of the external data source.  In an ideal world, the record has fallen out because the student is no longer enroled in the course, and he really should be unenroled from the Moodle course.  However, what if something went wrong with the external data source query?  You have the potential to rip every external-database-enrolment from your Moodle, mass-unenroling people throughout the site.  Remember that unenroling a student from a course drops the vast majority of his information from the course (submitted assignments, activity attempts, grades etc. ... grades can be recovered, but it's a manual process to do so when re-enrolling the student).  If it works for you, I'd recommend the "Disable course enrolment" option until you're sure you have it working as you'd like.
      • If you've already got everyone enroled via another method (Self Enrolment, Manual Enrolment or File upload Enrolment, for exapmle), this process will essentially duplicate all those enrolments.  Just something to consider as you make the transition.  Once you have all the External Database enrolments in place, you can go in and remove all the duplicated enrolment entries.  That way, you'll be fully automated (which is where we are right now).
Joe Amatrucola(e)ri erantzunda

Re: Command Line User Creation

Steven Dawe -

Hey Joe, thanks for your reply.

There a lot to think about there, but the first thing the that comes to mind is that - yes i can see the advantage the external database. My database is not running on SQL but some other 3rd party database engine (afaik). That said, they do provide a function where all the tables and relationships can be exported to an access database for further manipulation (this data can be refreshed as required with a scheduled task, etc).

Would Moodle be able to connect to an Access DB in the same way as an SQL DB?

If so, i could potentially do what you are suggesting with ID fields etc.

Steve

P.S. excuse my ignorance - what is SIS?

Steven Dawe(e)ri erantzunda

Re: Command Line User Creation

Joe Amatrucola -

You're welcome.  To answer your 2 questions:

  1. According to the documentation for External Database Enrolment (see link above), it does support access as a data source.  There's a complete list in the documentation.  Having said that, I can't imagine how that could work in a Linux environment, so I wonder if that data source is intended for a Windows installation of Moodle.  Personally, if I were to go the route you seem to be considering, I'd go with a regular csv export, which is also on the list of approved data source formats.
  2. Sorry.  SIS = School Information System.  It's a term used for the category of software for managing students, teachers, courses, etc.

Happy to help.

Joe