mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00

Credit: Alastair Pharo <alastair@catalyst.net.nz> Database -------- 1) This plugin previously only worked for students. I have made it so that you can _optionally_ specify a third column in your external database that contains some kind of role information (similar to the other two fields, you can choose any column in the mdl_role table to map to). If you do this, then the code loops over for each different kind of role and queries the external database. 2) There is a *slight* problem to be aware of, if a moodle configuration was upgraded to use the new role columns, then downgraded again, some roles might get left behind in the database when the large-scale sync thing goes through (that is, record pruning doesn't scale back quite properly). These would be cleaned away by setup_enrolments at login time, however, and the scenario was unlikely enough for me to decide to leave it for now. 3) If you don't have role columns there is a 'default role' setting that you can set (made by Martin D). This will only be obeyed when no role columns are specified. If this is set to 'default', then the course default role is used, on a per-course basis (which usually means student apparently). 4) From (3), my understanding is that if no config settings are changed, and the default role for all upgraded courses is student, that a smooth upgrade to 1.7 will occur for users of the database enrolment plugin.
35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
|
|
if(!empty($_SERVER['GATEWAY_INTERFACE'])){
|
|
error_log("should not be called from apache!");
|
|
exit;
|
|
}
|
|
error_reporting(E_ALL);
|
|
|
|
require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); // global moodle config file.
|
|
|
|
require_once($CFG->dirroot . '/course/lib.php');
|
|
require_once($CFG->dirroot . "/enrol/database/enrol.php");
|
|
|
|
// ensure errors are well explained
|
|
$CFG->debug=E_ALL;
|
|
// update enrolments -- these handlers should autocreate courses if required
|
|
$enrol = new enrolment_plugin_database();
|
|
|
|
// If we have settings to handle roles individually, through each type of
|
|
// role and update it. Otherwise, just got through once (with no role
|
|
// specified).
|
|
$roles = !empty($CFG->enrol_db_remoterolefield) && !empty($CFG->enrol_db_localrolefield)
|
|
? get_records('role')
|
|
: array(null);
|
|
|
|
foreach ($roles as $role) {
|
|
$enrol->sync_enrolments($role);
|
|
}
|
|
|
|
// sync metacourses
|
|
if (function_exists('sync_metacourses')) {
|
|
sync_metacourses();
|
|
}
|
|
|
|
?>
|