Moodle Plugins directory: Cohort synchronization | Moodle.org
Cohort synchronization
Plugin description
This plugin allows the synchronization of cohorts and members in cohorts from the command line. There are 2 scripts CLI to do the synchronization.
- cohortsync.php
- cohortmembersync.php
The plugin configuration page
There are two level configuration:
Settings for cohorts synchronization
CSV delimiter: CSV delimiter of the cohorts file, this option will be used as default value if no delimiter option given for the CLI
encoding: The type of encoding file, this option will be used as default value if no encoding option given for the CLI
default category: the default context category of the cohorts, if in the cohorts CSV file the category context is not filled or not found, this category will be used.
Settings for cohorts members synchronization
User identifier: This parameter is used to identify the user who will be added to the cohort, those values are allowed: id, username, idnumber. If the param useridentifier is no given to the CLI script, this value will be used.
Cohort identifier: This parameter is used to identify the cohort in which to insert the member, those values are allowed: id, name, idnumber. If the param cohortidentifier is no given to the CLI script, this value will be used.
CSV delimiter: Delimiter of the cohorts members file, this option will be used as default value if no delimiter option given for the CLI
encoding: The type of encoding file, this option will be used as default value if no encoding option given for the CLI
Formats description
Cohorts synchronization
Since cohort synchronization is based on Upload cohorts (core), the full description is found here
Cohorts members synchronization
The file is a comma separated file (or any other delimiter set in the plugin page settings or as a param in the script CLI) assumed to have three fields per line:
operation, cohortidentifier, useridentifier
where:
- operation - add | del
- cohortidentifier - it could be the cohort id, cohort name or cohort idnumber
- useridentifier - it could be the user id, user username or user idnumber
It could look something like this:
add, cohort1id, username1 add, cohort2id, username2 add, cohort2id, username3 del, cohort3id, username4 del, cohort4id, username5 add, cohort4id, username5
Usage
Cohort synchronization
To synchronize cohorts from script CLI, you have to execute the script like this:
php admin/tool/cohortsync/cli/cohortsync.php --filepath=/pathfile/ --csvdelimeter=comma --csvencoding=UTF-8 --context=system
- filepath: The location of the csv file to be processed.
- context: If the "context" is not found the default context in page settings will be used.
- csvdelimeter: the csv delimiter, if not given the default value in the page settings will be used.
- csvencoding: the file encoding, if not given the default value in the page settings will be used.
Here an example of csv file that can be used:
name,idnumber,description,category,visible cohort name 1,cohortid1,first description,, cohort name 2,cohortid2,,, cohort name 3,cohortid3,,Miscellaneous,no cohort name 4,cohortid4,,CAT1,yes cohort name 5,cohortid5,,CAT2,0 cohort name 6,cohortid6,,CAT3,1
For more details about the script CLI, run this command:
php admin/tool/cohortsync/cli/cohortsync.php --help
Cohort member synchronization
To synchronize cohorts members from script CLI, you have to execute the script like this:
php admin/tool/cohortsync/cli/cohortmembersync.php --filepath=/pathfile/ --cohortidentifier=name --useridentifier=id --flatfiledelimiter=comma --flatfileencoding=UTF-8
- filepath: The location of the flatfile to be processed.
- cohortidentifier: Which field will be used to identify cohort, if not given the default value in the page settings will be used.
- useridentifier: Which field will be used to identify user, if not given the default value in the page settings will be used
- flatfiledelimite: the file delimiter, if not given the default value in the page settings will be used.
- flatfileencoding: the file encoding, if not given the default value in the page settings will be used.
Here an example of flatfile that can be used:
add, my cohort A, 2 add, my cohort A, 3 add, my cohort B, 6 del, my cohort B, 14 del, my cohort C, 75 add, my cohort C, 30
For more details about the script CLI, run this command:
php admin/tool/cohortsync/cli/cohortmembersync.php --help
https://integration.moodle.org/job/Precheck%20remote%20branch/27632/artifact/work/smurf.html
Thanks Issam for sharing your plugin with the community. I am going to check it now as a part of the approval process.
OK, it seems this will need a bit more explanation. To be honest, the primary use case and the scope of the plugin is not clear to me. From the short description, I thought it would nice and simple plugin, doing one job and doing it well. Things seem to be more complicated.
Sorry I may be missing something but I think this needs clarification first.
At first, our need was to do that in one step, but your point let us reflect on the fact that we can do it in two steps: generating two files:
- Csv file for Cohorts
- Csv file for cohort_members
We will come back to you with more details on what will change in the plugin
https://moodle.org/plugins/tool_cohortsync#
Thanks
Thank you!
Recently, we made some changes on the plugin and we want to have your opinion on this.
In the cohortsync plugin we added 2 CLI scripts:
* cohortsync.php script to synchronize cohorts based on the already existing library in Upload_cohorts
* cohortmembersync.php script to synchronize the cohorts members via a flat file
In the plugin configuration page, there will be two levels of config:
Cohort synchronization settings:
* CSV delimiter
* encoding
* default category
the CLI will accept these parameters (If none given it will take params set in the plugin page configuration)
-h, --help: Print out this help
-f, --filepath: Indicate the csv file source to be processed (mandatory)
-d, --csvdelimiter : The csv delimiter used in the file
these delimiters are considered 'comma', 'semicolon', 'colon', 'tab'
Default: the value defined in the plugin setting
-e, --csvencoding The encoding of the file.
Default: the value defined in the plugin setting
-ctx, --context : The category ID matching the context of the cohort
Default: system
-v, --verbose : Print verbose progress information
Example of format:
name,idnumber,description,category_id,visible
cohort name 1,cohortid1,first description cohortid1,2,1
cohort name 2,cohortid2,first description cohortid1,44,1
cohort name 3,cohortid3,first description cohortid1,5,1
cohort name 4,cohortid4,first description cohortid1,14,1
cohort name 5,cohortid5,first description cohortid1,35,1
cohort name 6,cohortid6,first description cohortid1,7,1
Cohort members synchronization settings:
* delimiter
* encoding
* Cohort Identifier : which field used to identify cohort
* User Identifier: which field used to identify user
the CLI will accept these parameters (If none given it will take params set in the plugin page configuration)
-h, --help Print out this help
-f, --filepath Indicate the flat file source to be processed (mandatory)
-d, --flatfiledelimiter : The csv delimiter used in the file
these delimiters are considered 'comma', 'semicolon', 'colon', 'tab'
Default: the value defined in the plugin setting
-e, --flatfileencoding The encoding of the file.
Default: the value defined in the plugin setting
-c, --cohortidentifier The column used to identify cohort in the database
These idetenfiers are considered: name, idnumber, id
Default: the value defined in the plugin setting
-u, --useridentifier The column used to identify user in the database
These idetenfiers are considered: username, id, idnumber
Default: the value defined in the plugin setting
-v, --verbose Print verbose progress information
Example of format:
add, cohortid1, useridentifier1
add, cohortid1, useridentifier2
add, cohortid4, useridentifier4
del, cohortid4, useridentifier6
del, cohortid6, useridentifier12
add, cohortid6, useridentifier78
Thanks
If you can check the new version of the plugin.
Thanks
I just installed this plugin, and I lost access to the site administration with a 500 error (HTTP ERROR 500). please how to fix this error it is very urgent. thank you.
Do you have access to the php error log of your server to see if something in there can help find the error?
Other ideas :
- Clear the cache via command line : php admin/cli/purge_caches.php
- Remove the source code of the plugin (delete the admin/tool/cohortsync folder) On your next login, when you go to site administration it will say that the plugin is missing. In the plugins' administration page, you will then be able to uninstall it.
I have a few questions that would help me understand the problem :
- What version of Moodle are you using?
- Did you install other plugins at the same time?
- What version of the tool_cohortsync plugin did you install?
- How did you install it (from the zip file, from the git repository, ...)
Thanks,
Marie-Eve
And thanks for your work!
The last version is compatible with 3.11 and 4.0. For 4.1, we did not test it yet but some people are using it so it probably works.