Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * CLI sync for cohort enrolments, use for debugging or immediate sync
  19   * of all courses.
  20   *
  21   * Notes:
  22   *   - it is required to use the web server account when executing PHP CLI scripts
  23   *   - you need to change the "www-data" to match the apache user account
  24   *   - use "su" if "sudo" not available
  25   *
  26   * @package    enrol_cohort
  27   * @copyright  2011 Petr Skoda {@link http://skodak.org}
  28   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  
  31  define('CLI_SCRIPT', true);
  32  
  33  require(__DIR__.'/../../../config.php');
  34  require_once("$CFG->libdir/clilib.php");
  35  require_once("$CFG->dirroot/enrol/cohort/locallib.php");
  36  
  37  // Now get cli options.
  38  list($options, $unrecognized) = cli_get_params(array('verbose'=>false, 'help'=>false), array('v'=>'verbose', 'h'=>'help'));
  39  
  40  if ($unrecognized) {
  41      $unrecognized = implode("\n  ", $unrecognized);
  42      cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
  43  }
  44  
  45  if ($options['help']) {
  46      $help =
  47          "Execute cohort course enrol sync.
  48  
  49  Options:
  50  -v, --verbose         Print verbose progess information
  51  -h, --help            Print out this help
  52  
  53  Example:
  54  \$ sudo -u www-data /usr/bin/php enrol/cohort/cli/sync.php
  55  ";
  56  
  57      echo $help;
  58      die;
  59  }
  60  
  61  if (empty($options['verbose'])) {
  62      $trace = new null_progress_trace();
  63  } else {
  64      $trace = new text_progress_trace();
  65  }
  66  
  67  $result = enrol_cohort_sync($trace, null);
  68  $trace->finished();
  69  
  70  exit($result);