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   * Enables the provided model.
  19   *
  20   * @package    tool_analytics
  21   * @copyright  2017 David Monllao {@link http://www.davidmonllao.com}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  define('CLI_SCRIPT', true);
  26  
  27  require_once(__DIR__ . '/../../../../config.php');
  28  require_once($CFG->libdir.'/clilib.php');
  29  
  30  $help = "Enables the provided model.
  31  
  32  Options:
  33  --modelid           Model id
  34  --list              List models
  35  --analysisinterval  Time splitting method full class name
  36  -h, --help          Print out this help
  37  
  38  Example:
  39  \$ php admin/tool/analytics/cli/enable_model.php --modelid=1 --analysisinterval=\"\\core\\analytics\\time_splitting\\quarters\"
  40  ";
  41  
  42  // Now get cli options.
  43  list($options, $unrecognized) = cli_get_params(
  44      array(
  45          'help'             => false,
  46          'list'             => false,
  47          'modelid'          => false,
  48          'analysisinterval' => false
  49      ),
  50      array(
  51          'h' => 'help',
  52      )
  53  );
  54  
  55  if ($options['help']) {
  56      echo $help;
  57      exit(0);
  58  }
  59  
  60  if (!\core_analytics\manager::is_analytics_enabled()) {
  61      echo get_string('analyticsdisabled', 'analytics') . PHP_EOL;
  62      exit(0);
  63  }
  64  
  65  if ($options['list'] || $options['modelid'] === false) {
  66      \tool_analytics\clihelper::list_models();
  67      exit(0);
  68  }
  69  
  70  if ($options['analysisinterval'] === false) {
  71      echo $help;
  72      exit(0);
  73  }
  74  
  75  // We need admin permissions.
  76  \core\session\manager::set_user(get_admin());
  77  
  78  $model = new \core_analytics\model($options['modelid']);
  79  
  80  // Evaluate its suitability to predict accurately.
  81  $model->enable($options['analysisinterval']);
  82  
  83  cli_heading(get_string('success'));
  84  exit(0);