2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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.
35 --analysisinterval Time splitting method full class name
36 -h, --help Print out this help
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(
48 'analysisinterval' => false
55 if ($options['help']) {
60 if (!\core_analytics\manager
::is_analytics_enabled()) {
61 echo get_string('analyticsdisabled', 'analytics') . PHP_EOL
;
65 if ($options['list'] ||
$options['modelid'] === false) {
66 \tool_analytics\clihelper
::list_models();
70 if ($options['analysisinterval'] === false) {
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'));