Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / enrol / ldap / enrol_ldap_sync.php
blob7830c45daf7c706bf7ba9b96b6ffa599eb80d242
1 <?php
3 if(!empty($_SERVER['GATEWAY_INTERFACE'])){
4 error_log("should not be called from apache!");
5 exit;
7 error_reporting(E_ALL);
9 require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); // global moodle config file.
11 require_once($CFG->dirroot . '/course/lib.php');
12 require_once($CFG->dirroot . '/lib/moodlelib.php');
13 require_once($CFG->dirroot . '/lib/datalib.php');
14 require_once($CFG->dirroot . "/enrol/ldap/enrol.php");
16 // ensure errors are well explained
17 $CFG->debug = DEBUG_NORMAL;
19 // update enrolments -- these handlers should autocreate courses if required
20 $enrol = new enrolment_plugin_ldap();
21 $enrol->enrol_ldap_connect();
23 $enrol->check_legacy_config();
25 $roles = get_records('role');
26 foreach ($roles as $role) {
27 $enrol->sync_enrolments($role->shortname, true);
30 // sync metacourses
31 if (function_exists('sync_metacourses')) {
32 sync_metacourses();