Commit 40511178 authored by Paul Holden's avatar Paul Holden

MDL-66392 analytics: make model output directory default to empty.

Falling back to path within $CFG->dataroot/models.
parent 9aaab50c
......@@ -131,15 +131,10 @@ if ($hassiteconfig && \core_analytics\manager::is_analytics_enabled()) {
$timesplittingdefaults, $timesplittingoptions)
);
// Predictions processor output dir.
$defaultmodeloutputdir = rtrim($CFG->dataroot, '/') . DIRECTORY_SEPARATOR . 'models';
if (empty(get_config('analytics', 'modeloutputdir')) && !file_exists($defaultmodeloutputdir) &&
is_writable($defaultmodeloutputdir)) {
// Automatically create the dir for them so users don't see the invalid value red cross.
mkdir($defaultmodeloutputdir, $CFG->directorypermissions, true);
}
// Predictions processor output dir - specify default in setting description (used if left blank).
$defaultmodeloutputdir = \core_analytics\model::default_output_dir();
$settings->add(new admin_setting_configdirectory('analytics/modeloutputdir', new lang_string('modeloutputdir', 'analytics'),
new lang_string('modeloutputdirinfo', 'analytics'), $defaultmodeloutputdir));
new lang_string('modeloutputdirwithdefaultinfo', 'analytics', $defaultmodeloutputdir), ''));
// Disable web interface evaluation and get predictions.
$settings->add(new admin_setting_configcheckbox('analytics/onlycli', new lang_string('onlycli', 'analytics'),
......
......@@ -1492,6 +1492,17 @@ class model {
$prediction->get_prediction_data()->contextid, $prediction->get_sample_data());
}
/**
* Returns the default output directory for prediction processors
*
* @return string
*/
public static function default_output_dir(): string {
global $CFG;
return $CFG->dataroot . DIRECTORY_SEPARATOR . 'models';
}
/**
* Returns the output directory for prediction processors.
*
......@@ -1506,8 +1517,6 @@ class model {
* @return string
*/
public function get_output_dir($subdirs = array(), $onlymodelid = false) {
global $CFG;
$subdirstr = '';
foreach ($subdirs as $subdir) {
$subdirstr .= DIRECTORY_SEPARATOR . $subdir;
......@@ -1516,7 +1525,7 @@ class model {
$outputdir = get_config('analytics', 'modeloutputdir');
if (empty($outputdir)) {
// Apply default value.
$outputdir = rtrim($CFG->dataroot, '/') . DIRECTORY_SEPARATOR . 'models';
$outputdir = self::default_output_dir();
}
// Append model id.
......
......@@ -94,6 +94,7 @@ $string['modeinstructionblendedhybrid'] = 'Blended or hybrid';
$string['modeinstructionfullyonline'] = 'Fully online';
$string['modeloutputdir'] = 'Models output directory';
$string['modeloutputdirinfo'] = 'Directory where prediction processors store all evaluation info. Useful for debugging and research.';
$string['modeloutputdirwithdefaultinfo'] = 'Directory where prediction processors store all evaluation info. Useful for debugging and research. If empty, then \'<strong>{$a}</strong>\' will be used as default.';
$string['modeltimelimit'] = 'Analysis time limit per model';
$string['modeltimelimitinfo'] = 'This setting limits the time each model spends analysing the site contents.';
$string['neutral'] = 'Neutral';
......
......@@ -3981,5 +3981,16 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2019111805.10);
}
if ($oldversion < 2019111805.12) {
// Reset analytics model output dir if it's the default value.
$modeloutputdir = get_config('analytics', 'modeloutputdir');
if (strcasecmp($modeloutputdir, $CFG->dataroot . DIRECTORY_SEPARATOR . 'models') == 0) {
set_config('modeloutputdir', '', 'analytics');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2019111805.12);
}
return true;
}
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2019111805.11; // 20191118 = branching date YYYYMMDD - do not modify!
$version = 2019111805.12; // 20191118 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '3.8.5+ (Build: 20201021)'; // Human-friendly version name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment