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