Merge branch 'MDL-72496-master_assert_tag' of https://github.com/call-learning/moodle
[moodle.git] / admin / tool / analytics / cli / enable_model.php
blob5da4e1f8a98b277f028eca4a16b7b0bdd341713c
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.
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/>.
17 /**
18 * Enables the provided model.
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
25 define('CLI_SCRIPT', true);
27 require_once(__DIR__ . '/../../../../config.php');
28 require_once($CFG->libdir.'/clilib.php');
30 $help = "Enables the provided model.
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
38 Example:
39 \$ php admin/tool/analytics/cli/enable_model.php --modelid=1 --analysisinterval=\"\\core\\analytics\\time_splitting\\quarters\"
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
50 array(
51 'h' => 'help',
55 if ($options['help']) {
56 echo $help;
57 exit(0);
60 if (!\core_analytics\manager::is_analytics_enabled()) {
61 echo get_string('analyticsdisabled', 'analytics') . PHP_EOL;
62 exit(0);
65 if ($options['list'] || $options['modelid'] === false) {
66 \tool_analytics\clihelper::list_models();
67 exit(0);
70 if ($options['analysisinterval'] === false) {
71 echo $help;
72 exit(0);
75 // We need admin permissions.
76 \core\session\manager::set_user(get_admin());
78 $model = new \core_analytics\model($options['modelid']);
80 // Evaluate its suitability to predict accurately.
81 $model->enable($options['analysisinterval']);
83 cli_heading(get_string('success'));
84 exit(0);