[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/enrol/database/cli/ -> sync.php (source)

   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 full external database synchronisation.
  19   *
  20   * Sample cron entry:
  21   * # 5 minutes past 4am
  22   * 5 4 * * * $sudo -u www-data /usr/bin/php /var/www/moodle/enrol/database/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   *
  29   * @package    enrol_database
  30   * @copyright  2010 Petr Skoda {@link http://skodak.org}
  31   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  
  34  define('CLI_SCRIPT', true);
  35  
  36  require(__DIR__.'/../../../config.php');
  37  require_once("$CFG->libdir/clilib.php");
  38  
  39  // Now get cli options.
  40  list($options, $unrecognized) = cli_get_params(array('verbose'=>false, 'help'=>false), array('v'=>'verbose', 'h'=>'help'));
  41  
  42  if ($unrecognized) {
  43      $unrecognized = implode("\n  ", $unrecognized);
  44      cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
  45  }
  46  
  47  if ($options['help']) {
  48      $help =
  49  "Execute enrol sync with external database.
  50  The enrol_database plugin must be enabled and properly configured.
  51  
  52  Options:
  53  -v, --verbose         Print verbose progress information
  54  -h, --help            Print out this help
  55  
  56  Example:
  57  \$ sudo -u www-data /usr/bin/php enrol/database/cli/sync.php
  58  
  59  Sample cron entry:
  60  # 5 minutes past 4am
  61  5 4 * * * sudo -u www-data /usr/bin/php /var/www/moodle/enrol/database/cli/sync.php
  62  ";
  63  
  64      echo $help;
  65      die;
  66  }
  67  
  68  if (!enrol_is_enabled('database')) {
  69      cli_error('enrol_database plugin is disabled, synchronisation stopped', 2);
  70  }
  71  
  72  if (empty($options['verbose'])) {
  73      $trace = new null_progress_trace();
  74  } else {
  75      $trace = new text_progress_trace();
  76  }
  77  
  78  /** @var enrol_database_plugin $enrol  */
  79  $enrol = enrol_get_plugin('database');
  80  $result = 0;
  81  
  82  $result = $result | $enrol->sync_courses($trace);
  83  $result = $result | $enrol->sync_enrolments($trace);
  84  
  85  exit($result);


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1