3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * CLI sync for full category enrol synchronisation.
22 * $sudo -u www-data /usr/bin/php /var/www/moodle/enrol/category/cli/sync.php
25 * - it is required to use the web server account when executing PHP CLI scripts
26 * - you need to change the "www-data" to match the apache user account
27 * - use "su" if "sudo" not available
30 * @subpackage category
31 * @copyright 2010 Petr Skoda {@link http://skodak.org}
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 define('CLI_SCRIPT', true);
37 require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
38 require_once("$CFG->dirroot/enrol/category/locallib.php");
39 require_once("$CFG->libdir/clilib.php");
41 // Now get cli options.
42 list($options, $unrecognized) = cli_get_params(array('verbose'=>false, 'help'=>false), array('v'=>'verbose', 'h'=>'help'));
45 $unrecognized = implode("\n ", $unrecognized);
46 cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
49 if ($options['help']) {
51 "Execute course category enrolment sync.
54 -v, --verbose Print verbose progess information
55 -h, --help Print out this help
58 \$ sudo -u www-data /usr/bin/php enrol/category/cli/sync.php
65 if (!enrol_is_enabled('category')) {
66 cli_error('enrol_category plugin is disabled, synchronisation stopped');
69 $verbose = !empty($options['verbose']);
70 return enrol_category_sync_full($verbose);