Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is 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 meta course 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_meta
  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/meta/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 meta 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/meta/cli/sync.php
  55  ";
  56  
  57      echo $help;
  58      die;
  59  }
  60  
  61  $verbose = !empty($options['verbose']);
  62  
  63  $result = enrol_meta_sync(null, $verbose);
  64  
  65  exit($result);