|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00046 define('CLI_SCRIPT', true); 00047 00048 require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); 00049 require_once($CFG->dirroot.'/course/lib.php'); 00050 require_once($CFG->libdir.'/clilib.php'); 00051 00052 // now get cli options 00053 list($options, $unrecognized) = cli_get_params(array('noupdate'=>false, 'verbose'=>false, 'help'=>false), array('n'=>'noupdate', 'v'=>'verbose', 'h'=>'help')); 00054 00055 if ($unrecognized) { 00056 $unrecognized = implode("\n ", $unrecognized); 00057 cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); 00058 } 00059 00060 if ($options['help']) { 00061 $help = 00062 "Execute user account sync with external database. 00063 The auth_db plugin must be enabled and properly configured. 00064 00065 Options: 00066 -n, --noupdate Skip update of existing users 00067 -v, --verbose Print verbose progess information 00068 -h, --help Print out this help 00069 00070 Example: 00071 \$sudo -u www-data /usr/bin/php auth/db/cli/sync_users.php 00072 00073 Sample cron entry: 00074 # 5 minutes past 4am 00075 5 4 * * * \$sudo -u www-data /usr/bin/php /var/www/moodle/auth/db/cli/sync_users.php 00076 "; 00077 00078 echo $help; 00079 die; 00080 } 00081 00082 if (!is_enabled_auth('db')) { 00083 echo "Plugin not enabled!"; 00084 exit(1); 00085 } 00086 00087 $verbose = !empty($options['verbose']); 00088 $update = empty($options['noupdate']); 00089 00090 $dbauth = get_auth_plugin('db'); 00091 return $dbauth->sync_users($update, $verbose); 00092