User Sync CSV

General plugins (Local) ::: local_usersynccsv
Maintained by Antonello Moro
Moodle users import/export via CSV files
Latest release:
49 sites
13 downloads
23 fans
Current versions available: 1

User Sync CSV is a Moodle local plugin allowing Moodle to import/export Moodle users from/to other systems like SAP, using CSV files.

CSV files are an old but still largely used way of interaction among systems, because they don't require specific skillsets or advanced system configurations.

Hence sometimes it is necessary to set-up a background job that periodically extracts data from Moodle DB and writes the data into a CSV file and vice-versa: reads data from an external CSV file and writes it into the Moodle DB.

This is exactly what this plugin does. It uses a configurable parameter for the user key, typically “idnumber”, but can also be a custom field. According to this key, the plugin inserts or updates users found in the CSV files.

The CSV files must present field names in the first row. After the first one, each row represents a list of User fields.

The CSV files are expected to be found in a configurable directory called “import”. The plugin must have  read/write/exec access in the import dir.

Also, the plugin handles archiving and clean-up of the import files.The file retention days are set by a configurable parameter.

Other parameters, like CSV delimiter, can be configured in the settings page. Each parameter is provided with a detailed description.

The plugin basically registers a new Moodle scheduled task, called User Sync CSV, that, by default, runs every day at 3AM.

At the beginning of each execution the task performs a series of checks on the configuration parameters. If one of these preliminary checks fail, the execution is aborted and a log is written in the Moodle logs.

The most important checks are:

  • CSV Delimiter: it must be set. No empty string allowed.
  • User key: it must be set. No empty string allowed. It must be a column of User table or the shortname of a custom field.
  • Import Directory: it must be set. No empty string allowed. It must exist in the File System, and Moodle must have read/write/exec permissions in it.
  • Default User Password: it must be set. No empty string allowed.

At the start of each execution, the plugin will check for three subdirs of Import Directory. If not found, it will attempt to create them. The directories are:

  • work: Working directory. A file found in import dir is moved to this dir before being imported. It remains here during import and is moved to discard or archive at the end of import.
  • discard: Discard directory. Files would be moved here from work if there were any problems during execution. Discarding policy can also be set. See plugin parameters.
  • archive: Archive directory. Files would be moved here from work if import were OK. The dir is organized in daily subdirectory. Aging policy will remove entire subdirs after expiration time. See plugin parameters.

The export functionality is foreseen in the next releases, but it' still not available in version v1.0.0.

Please note that even though the plugin has been tested in pre-production environments, it's still in BETA version. Hence, you are strongly encouraged to open issues in the git official issue manager, find the link in the plugin page. Please feel free to open bugs, suggest enhancements, report thoughts or whatever should come into your mind.

Screenshots

Screenshot #0
Screenshot #1

Contributors

Antonello Moro (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Antonello Moro
    Wed, 3 Aug 2016, 10:35 PM
    I will submit a new ver when I'm done.
  • Antonello Moro
    Thu, 4 Aug 2016, 3:42 AM
    Ok done. I also made a test with a 10K users file. It took 600 sec to complete on my dev env
  • Mike Churchward
    Thu, 4 Aug 2016, 5:22 AM
    It all looks good. Thanks.
  • David Mudrák
    Tue, 9 Aug 2016, 5:54 PM

    Thanks Antonello for sharing the plugin with the Moodle community, and thanks Mike for the peer-review. I am happy to approve the plugin now. You are cleared to land, welcome to the Plugins directory!

  • محمد مرعب متخصص في موودل
    Tue, 9 Aug 2016, 8:14 PM
    thanks for sharing, this what we need Tested with 3.1 good.
  • Antonello Moro
    Wed, 10 Aug 2016, 5:21 AM
    Hallo Mohammad, the plugin woks fine with Moodle 3.1. Anyway, please feel free to file a bug if you should come across one.
    https://github.com/tunele/moodle-local_usersynccsv/issues
  • Jeff White
    Sat, 3 Sept 2016, 3:18 AM
    Very nice plugin. I was playing with it in updating cohorts but it appears not to recognize the cohort1 field.
  • Antonello Moro
    Sat, 3 Sept 2016, 3:44 AM
    Hi Jeff,
    Thanks for your comment. I think the cohorts are not handled yet, I will handle them in the next version. Meanwhile, could you please file a bug with detailed instructions on expected/actual behaviour and how to repro? That would help me a lot fixing it.
    Thanks,
    *A
  • Sandeep Nehra
    Tue, 11 July 2017, 7:04 PM
    Hello
    Does it work with Moodle 3.3 ?
  • Mariann Abosné Lazányi
    Mon, 9 Oct 2017, 7:17 PM
    Hi,

    This plugin sounds like one I could use (I'm using Moodle 3.3), but I still have a few questions:

    - In the CSV file is there a field where I can set the password to be changed on the first sign-in?
    - On the settings page I can see that you need to have the fields username , firstname, lastname, email, and import key. But what does the import key mean? Is it the password, or something else?
    - If there are data changes and therefore the CSV has to be changed does it have to have all data in the CSV again, or can I just try to upload the new users and the users with changed data?
    - What happens if I want to delete a user (for example the user left the group)? Can I do that with this plugin somehow?
    - Can I set an upload method like I can do with manual user upload?

    Thanks for your help!

    Mariann
  • Oscar Gagliardi
    Fri, 20 Apr 2018, 12:13 PM
    Hi Antonello,

    Are the course, group and role fields available through this plugin. I was thinking about using this plugin to automatically enroll a user in a course and assign a role.

    Thank you!

    Oscar
  • Oscar Gagliardi
    Sat, 21 Apr 2018, 5:39 AM
    There is an error on the plugin on the usersync.php file that prevents it from processing the hash on passwords passed with the CSV file. On line 480 you need to add an else statement. Without the else statement only the default password will be hashed.

    It should look like this:

    if (!property_exists($user, 'password')) {
    $user->password = hash_internal_user_password($this->defpassowrd);
    }else{
    $user->password = hash_internal_user_password($user->password);
    }

    Regards,

    Oscar
  • Tamar Alania
    Wed, 27 June 2018, 7:39 PM
    Hello, is anyone using the plugin? does the plugin work?
  • Olli Savolainen
    Thu, 1 Aug 2019, 6:35 PM
    Hi,
    Thanks for your work.

    There is an undocumented behaviour of this plugin, it resets the authentication method and various other data.

    $user->lang = $CFG->lang;
    $user->mnethostid = $CFG->mnet_localhost_id;
    $user->auth = 'manual';
    $user->confirmed = 1;
    if (empty($user->city)) {
    $user->city = "none";
    }
    if (empty($user->country)) {
    $user->country = "no";
    }

    So in many scenarios these should be commented out to avoid unintended consequences.
    Also, an option to only update data and not create new rows would be welcome; now commenting out code to do this produces errors to Moodle log.
  • Sketch...
    Wed, 5 May 2021, 2:14 PM
    I got confirmation from the author of this plugin, Antonello Moro, that he is no longer supporting this plugin. So I don't think there will be an updated version for current versions of Moodle anytime soon.
1 2
Please login to post comments