Commit | Line | Data |
---|---|---|
28bd3d9a PS |
1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * CAS user sync script. | |
20 | * | |
21 | * This script is meant to be called from a cronjob to sync moodle with the LDAP | |
22 | * backend in those setups where the LDAP backend acts as 'master'. | |
23 | * | |
24 | * Sample cron entry: | |
25 | * # 5 minutes past 4am | |
26 | * 5 4 * * * $sudo -u www-data /usr/bin/php /var/www/moodle/auth/ldap/cli/sync_users.php | |
27 | * | |
28 | * Notes: | |
29 | * - it is required to use the web server account when executing PHP CLI scripts | |
30 | * - you need to change the "www-data" to match the apache user account | |
31 | * - use "su" if "sudo" not available | |
32 | * - If you have a large number of users, you may want to raise the memory limits | |
33 | * by passing -d momory_limit=256M | |
34 | * - For debugging & better logging, you are encouraged to use in the command line: | |
35 | * -d log_errors=1 -d error_reporting=E_ALL -d display_errors=0 -d html_errors=0 | |
36 | * - If you have a large number of users, you may want to raise the memory limits | |
37 | * by passing -d momory_limit=256M | |
38 | * - For debugging & better logging, you are encouraged to use in the command line: | |
39 | * -d log_errors=1 -d error_reporting=E_ALL -d display_errors=0 -d html_errors=0 | |
40 | * | |
41 | * Performance notes: | |
42 | * We have optimized it as best as we could for PostgreSQL and MySQL, with 27K students | |
43 | * we have seen this take 10 minutes. | |
44 | * | |
45 | * @package auth | |
46 | * @subpackage ldap | |
47 | * @copyright 2004 Martin Langhoff | |
48 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
49 | */ | |
50 | ||
51 | define('CLI_SCRIPT', true); | |
52 | ||
53 | require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); // global moodle config file. | |
54 | require_once($CFG->dirroot.'/course/lib.php'); | |
55 | ||
56 | // Ensure errors are well explained | |
57 | $CFG->debug = DEBUG_NORMAL; | |
58 | ||
59 | if (!is_enabled_auth('ldap')) { | |
60 | error_log('[AUTH LDAP] '.get_string('pluginnotenabled', 'auth_ldap')); | |
61 | die; | |
62 | } | |
63 | ||
64 | $ldapauth = get_auth_plugin('ldap'); | |
65 | $ldapauth->sync_users(true); | |
66 |