|
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 00035 define('CLI_SCRIPT', true); 00036 00037 require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); 00038 require_once($CFG->libdir.'/clilib.php'); 00039 00040 // now get cli options 00041 list($options, $unrecognized) = cli_get_params(array('verbose'=>false, 'help'=>false), array('v'=>'verbose', 'h'=>'help')); 00042 00043 if ($unrecognized) { 00044 $unrecognized = implode("\n ", $unrecognized); 00045 cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); 00046 } 00047 00048 if ($options['help']) { 00049 $help = 00050 "Execute enrol sync with external database. 00051 The enrol_database plugin must be enabled and properly configured. 00052 00053 Options: 00054 -v, --verbose Print verbose progess information 00055 -h, --help Print out this help 00056 00057 Example: 00058 \$sudo -u www-data /usr/bin/php enrol/database/cli/sync.php 00059 00060 Sample cron entry: 00061 # 5 minutes past 4am 00062 5 4 * * * \$sudo -u www-data /usr/bin/php /var/www/moodle/enrol/database/cli/sync.php 00063 "; 00064 00065 echo $help; 00066 die; 00067 } 00068 00069 if (!enrol_is_enabled('database')) { 00070 echo('enrol_database plugin is disabled, sync is disabled'."\n"); 00071 exit(1); 00072 } 00073 00074 $verbose = !empty($options['verbose']); 00075 $enrol = enrol_get_plugin('database'); 00076 $result = 0; 00077 00078 $result = $result | $enrol->sync_courses($verbose); 00079 $result = $result | $enrol->sync_enrolments($verbose); 00080 00081 exit($result);