From cecd90ffecb6ac228a71a7cfe6c930b674dd2643 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 29 Sep 2020 08:57:56 +0100 Subject: [PATCH] MDL-66392 analytics: make model output directory default to empty. Falling back to path within $CFG->dataroot/models. --- admin/settings/analytics.php | 11 +++-------- analytics/classes/model.php | 15 ++++++++++++--- lang/en/analytics.php | 5 ++++- lang/en/deprecated.txt | 1 + lib/db/upgrade.php | 11 +++++++++++ version.php | 2 +- 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/admin/settings/analytics.php b/admin/settings/analytics.php index a7222444e5b..30b6a2260c4 100644 --- a/admin/settings/analytics.php +++ b/admin/settings/analytics.php @@ -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'), diff --git a/analytics/classes/model.php b/analytics/classes/model.php index 5385c29fc3b..5fc63d4b166 100644 --- a/analytics/classes/model.php +++ b/analytics/classes/model.php @@ -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. diff --git a/lang/en/analytics.php b/lang/en/analytics.php index 17f165464df..f6e97b81d71 100644 --- a/lang/en/analytics.php +++ b/lang/en/analytics.php @@ -93,7 +93,7 @@ $string['modeinstructionfacetoface'] = 'Face to face'; $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 \'{$a}\' 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'; @@ -156,3 +156,6 @@ $string['viewinsight'] = 'View insight'; $string['viewinsightdetails'] = 'View insight details'; $string['viewprediction'] = 'View prediction details'; $string['washelpful'] = 'Was this helpful?'; + +// Deprecated since Moodle 3.10. +$string['modeloutputdirinfo'] = 'Directory where prediction processors store all evaluation info. Useful for debugging and research.'; diff --git a/lang/en/deprecated.txt b/lang/en/deprecated.txt index 2bd4d58cbc7..4ba2ea50b9e 100644 --- a/lang/en/deprecated.txt +++ b/lang/en/deprecated.txt @@ -123,3 +123,4 @@ managelicenses,core_admin userfilterplaceholder,core sitebackpackverify,core_badges filetypesnotwhitelisted,core_form +modeloutputdirinfo,core_analytics diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 69527d99803..fe27f11e43f 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2815,5 +2815,16 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2021052500.27); } + if ($oldversion < 2021052500.29) { + // 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, 2021052500.29); + } + return true; } diff --git a/version.php b/version.php index b311bce33d9..13d25773a3b 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2021052500.28; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2021052500.29; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '4.0dev (Build: 20201021)'; // Human-friendly version name