Fixes bug MDL-8454, "students can't post to forums"
[moodle-pu.git] / enrol / database / enrol_database_sync.php
blobedeb500b48688a4b30fd8ae083511c90e03219a6
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/blocklib.php');
13 require_once($CFG->dirroot . "/enrol/database/enrol.php");
15 // ensure errors are well explained
16 $CFG->debug=E_ALL;
17 // update enrolments -- these handlers should autocreate courses if required
18 $enrol = new enrolment_plugin_database();
20 // If we have settings to handle roles individually, through each type of
21 // role and update it. Otherwise, just got through once (with no role
22 // specified).
23 $roles = !empty($CFG->enrol_db_remoterolefield) && !empty($CFG->enrol_db_localrolefield)
24 ? get_records('role')
25 : array(null);
27 foreach ($roles as $role) {
28 $enrol->sync_enrolments($role);
31 // sync metacourses
32 if (function_exists('sync_metacourses')) {
33 sync_metacourses();