MDL-34864 add verbose option to CLI enrol_category sync
[moodle.git] / enrol / category / cli / sync.php
CommitLineData
df997f84
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 * CLI sync for full category enrol synchronisation.
20 *
28bd3d9a
PS
21 * Sample execution:
22 * $sudo -u www-data /usr/bin/php /var/www/moodle/enrol/category/cli/sync.php
23 *
24 * Notes:
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
28 *
fe441933
PS
29 * @package enrol
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
df997f84
PS
33 */
34
28bd3d9a 35define('CLI_SCRIPT', true);
df997f84
PS
36
37require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
38require_once("$CFG->dirroot/enrol/category/locallib.php");
a2043a31
PS
39require_once("$CFG->libdir/clilib.php");
40
41// Now get cli options.
42list($options, $unrecognized) = cli_get_params(array('verbose'=>false, 'help'=>false), array('v'=>'verbose', 'h'=>'help'));
43
44if ($unrecognized) {
45 $unrecognized = implode("\n ", $unrecognized);
46 cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
47}
48
49if ($options['help']) {
50 $help =
51 "Execute course category enrolment sync.
52
53Options:
54-v, --verbose Print verbose progess information
55-h, --help Print out this help
56
57Example:
58\$ sudo -u www-data /usr/bin/php enrol/category/cli/sync.php
59";
60 echo $help;
61 die;
62}
63
df997f84
PS
64
65if (!enrol_is_enabled('category')) {
a2043a31 66 cli_error('enrol_category plugin is disabled, synchronisation stopped');
df997f84
PS
67}
68
a2043a31
PS
69$verbose = !empty($options['verbose']);
70return enrol_category_sync_full($verbose);