Wednesday, March 13, 2013

Syncing Active Directory Groups as Moodle Cohorts

We had a situation that required us to synchronize certain active directory groups with enrollment in a moodle course. The way we accomplished this was to use a moodle userscript that synced active directory groups as cohorts. Then we assigned the cohorts to the course using the "cohort-sync" enrollment type.

The following steps assume you already have moodle LDAP auth configured and are running the /auth/ldap/cli/sync_users.php to sync LDAP users to moodle.

1. Obtain the sync_cohorts.php script from https://tracker.moodle.org/browse/MDL-25011?attachmentOrder=desc and place it in /auth/ldap/cli/

2. Add the following lines to moodle's config.php

$CFG->ldap_group_class='group';
$CFG->ldap_process_nested_groups=1;
$CFG->ldap_real_user_attribute='sAMAccountName';
ldap_group_class - needs to be set to 'group' for active directory in order to match user groups
ldap_process_nested_groups - set this to 1 if you have groups as members of your groups in order to locate the actual users
ldap_real_user_attribute - this is probably whatever you have "User attribute" set to in moodle's LDAP settings. Also note that it is CASE SENSITIVE (that one gave me some trouble until I realized what the issue was).

3. Add the sync_cohorts.php scrip to your webserver user's crontab to be run sometime after the ldap sync_users.php finishes.

4. Add the newly created cohort to your course using the cohort-sync enrollment type.

4 comments:

  1. Hi Stephen. Wolfreton School thanks you for this post! ;-)

    ReplyDelete
  2. Hello, just got the following error, searched the web for ours but have no idea, can you help? Did you have any idea?

    traitement du groupe Medien
    creation cohorte 0
    Default exception handler: Fehler in der Kodierung gefunden, den nur ein Programmierer korrigieren kann: textlib_get_instance() can not be used any more, please use core_text::functioname() instead. Debug:
    Error code: codingerror
    * line 1490 of /lib/deprecatedlib.php: coding_exception thrown
    * line 347 of /auth/ldap/cli/sync_cohorts.php: call to textlib_get_instance()
    * line 540 of /auth/ldap/cli/sync_cohorts.php: call to auth_plugin_cohort->ldap_get_group_members_ad()
    * line 653 of /auth/ldap/cli/sync_cohorts.php: call to auth_plugin_cohort->ldap_get_group_members()

    !!! Fehler in der Kodierung gefunden, den nur ein Programmierer korrigieren kann: textlib_get_instance() can not be used any more, please use core_text::functioname() instead. !!!


    best regards

    Jörg

    ReplyDelete
  3. Hello, just got the following error, searched the web for ours but have no idea, can you help? Did you have any idea?

    traitement du groupe Medien
    creation cohorte 0
    Default exception handler: Fehler in der Kodierung gefunden, den nur ein Programmierer korrigieren kann: textlib_get_instance() can not be used any more, please use core_text::functioname() instead. Debug:
    Error code: codingerror
    * line 1490 of /lib/deprecatedlib.php: coding_exception thrown
    * line 347 of /auth/ldap/cli/sync_cohorts.php: call to textlib_get_instance()
    * line 540 of /auth/ldap/cli/sync_cohorts.php: call to auth_plugin_cohort->ldap_get_group_members_ad()
    * line 653 of /auth/ldap/cli/sync_cohorts.php: call to auth_plugin_cohort->ldap_get_group_members()

    !!! Fehler in der Kodierung gefunden, den nur ein Programmierer korrigieren kann: textlib_get_instance() can not be used any more, please use core_text::functioname() instead. !!!


    best regards

    Jörg

    ReplyDelete
  4. I am also getting same error and i have Moodle 3.3

    traitement du groupe Exchange Servers
    Default exception handler: Coding error detected, it must be fixed by a programm
    er: textlib_get_instance() can not be used any more, please use core_text::funct
    ioname() instead. Debug:
    Error code: codingerror
    * line 1208 of \lib\deprecatedlib.php: coding_exception thrown
    * line 347 of \auth\ldap\cli\sync_cohorts.php: call to textlib_get_instance()
    * line 540 of \auth\ldap\cli\sync_cohorts.php: call to auth_plugin_cohort->ldap_
    get_group_members_ad()
    * line 653 of \auth\ldap\cli\sync_cohorts.php: call to auth_plugin_cohort->ldap_
    get_group_members()

    !!! Coding error detected, it must be fixed by a programmer: textlib_get_instanc
    e() can not be used any more, please use core_text::functioname() instead. !!!

    ReplyDelete