| 1 | 
           efrain | 
           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 update for self enrolments, use for debugging or immediate update
  | 
        
        
            | 
            | 
           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_self
  | 
        
        
            | 
            | 
           27 | 
            * @copyright  2012 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 | 
              | 
        
        
            | 
            | 
           36 | 
           // Now get cli options.
  | 
        
        
            | 
            | 
           37 | 
           list($options, $unrecognized) = cli_get_params(array('verbose'=>false, 'help'=>false), array('v'=>'verbose', 'h'=>'help'));
  | 
        
        
            | 
            | 
           38 | 
              | 
        
        
            | 
            | 
           39 | 
           if ($unrecognized) {
  | 
        
        
            | 
            | 
           40 | 
               $unrecognized = implode("\n  ", $unrecognized);
  | 
        
        
            | 
            | 
           41 | 
               cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
  | 
        
        
            | 
            | 
           42 | 
           }
  | 
        
        
            | 
            | 
           43 | 
              | 
        
        
            | 
            | 
           44 | 
           if ($options['help']) {
  | 
        
        
            | 
            | 
           45 | 
               $help =
  | 
        
        
            | 
            | 
           46 | 
                   "Execute self course enrol updates.
  | 
        
        
            | 
            | 
           47 | 
              | 
        
        
            | 
            | 
           48 | 
           Options:
  | 
        
        
            | 
            | 
           49 | 
           -v, --verbose         Print verbose progress information
  | 
        
        
            | 
            | 
           50 | 
           -h, --help            Print out this help
  | 
        
        
            | 
            | 
           51 | 
              | 
        
        
            | 
            | 
           52 | 
           Example:
  | 
        
        
            | 
            | 
           53 | 
           \$ sudo -u www-data /usr/bin/php enrol/self/cli/sync.php
  | 
        
        
            | 
            | 
           54 | 
           ";
  | 
        
        
            | 
            | 
           55 | 
              | 
        
        
            | 
            | 
           56 | 
               echo $help;
  | 
        
        
            | 
            | 
           57 | 
               die;
  | 
        
        
            | 
            | 
           58 | 
           }
  | 
        
        
            | 
            | 
           59 | 
              | 
        
        
            | 
            | 
           60 | 
           if (!enrol_is_enabled('self')) {
  | 
        
        
            | 
            | 
           61 | 
               cli_error('enrol_self plugin is disabled, synchronisation stopped', 2);
  | 
        
        
            | 
            | 
           62 | 
           }
  | 
        
        
            | 
            | 
           63 | 
              | 
        
        
            | 
            | 
           64 | 
           if (empty($options['verbose'])) {
  | 
        
        
            | 
            | 
           65 | 
               $trace = new null_progress_trace();
  | 
        
        
            | 
            | 
           66 | 
           } else {
  | 
        
        
            | 
            | 
           67 | 
               $trace = new text_progress_trace();
  | 
        
        
            | 
            | 
           68 | 
           }
  | 
        
        
            | 
            | 
           69 | 
              | 
        
        
            | 
            | 
           70 | 
           /** @var $plugin enrol_self_plugin */
  | 
        
        
            | 
            | 
           71 | 
           $plugin = enrol_get_plugin('self');
  | 
        
        
            | 
            | 
           72 | 
              | 
        
        
            | 
            | 
           73 | 
           $result = $plugin->sync($trace, null);
  | 
        
        
            | 
            | 
           74 | 
           $plugin->send_expiry_notifications($trace);
  | 
        
        
            | 
            | 
           75 | 
              | 
        
        
            | 
            | 
           76 | 
           exit($result);
  |