diff --git a/admin/settings/analytics.php b/admin/settings/analytics.php index 30b6a2260c4..1bf0cb38da5 100644 --- a/admin/settings/analytics.php +++ b/admin/settings/analytics.php @@ -144,5 +144,20 @@ if ($hassiteconfig && \core_analytics\manager::is_analytics_enabled()) { $settings->add(new admin_setting_configduration('analytics/modeltimelimit', new lang_string('modeltimelimit', 'analytics'), new lang_string('modeltimelimitinfo', 'analytics'), 20 * MINSECS)); + $options = array( + 0 => new lang_string('neverdelete', 'analytics'), + 1000 => new lang_string('numdays', '', 1000), + 365 => new lang_string('numdays', '', 365), + 180 => new lang_string('numdays', '', 180), + 150 => new lang_string('numdays', '', 150), + 120 => new lang_string('numdays', '', 120), + 90 => new lang_string('numdays', '', 90), + 60 => new lang_string('numdays', '', 60), + 35 => new lang_string('numdays', '', 35)); + $settings->add(new admin_setting_configselect('analytics/calclifetime', + new lang_string('calclifetime', 'analytics'), + new lang_string('configlcalclifetime', 'analytics'), 35, $options)); + + } } diff --git a/analytics/classes/manager.php b/analytics/classes/manager.php index 054a07a4d83..c137cf50e6b 100644 --- a/analytics/classes/manager.php +++ b/analytics/classes/manager.php @@ -694,6 +694,13 @@ class manager { $param + $idsparams); } } + + // Clean up calculations table. + $calclifetime = get_config('analytics', 'calclifetime'); + if (!empty($calclifetime)) { + $lifetime = time() - ($calclifetime * DAYSECS); // Value in days. + $DB->delete_records_select('analytics_indicator_calc', 'timecreated < ?', [$lifetime]); + } } /** diff --git a/lang/en/analytics.php b/lang/en/analytics.php index 719cc6549af..f3d19e8c60e 100644 --- a/lang/en/analytics.php +++ b/lang/en/analytics.php @@ -31,6 +31,8 @@ $string['analyticslogstore'] = 'Log store used for analytics'; $string['analyticslogstore_help'] = 'The log store that will be used by the analytics API to read users\' activity.'; $string['analyticssettings'] = 'Analytics settings'; $string['analyticssiteinfo'] = 'Site information'; +$string['calclifetime'] = 'Keep analytics calculations for'; +$string['configlcalclifetime'] = 'This specifies the length of time you want to keep calculation data - this will not delete predictions, but deletes the data used to generate the predictions. Using the default option here is best as it keeps your disk usage under control, however if you are using calculation tables for other purposes you may want to increase this value.'; $string['defaulttimesplittingmethods'] = 'Default analysis intervals for model\'s evaluation'; $string['defaulttimesplittingmethods_help'] = 'The analysis interval defines when the system will calculate predictions and the portion of activity logs that will be considered for those predictions. The model evaluation process will iterate through these analysis intervals unless a specific analysis interval is specified.'; $string['defaultpredictionsprocessor'] = 'Default predictions processor'; @@ -97,6 +99,7 @@ $string['modeloutputdirwithdefaultinfo'] = 'Directory where prediction processor $string['modeltimelimit'] = 'Analysis time limit per model'; $string['modeltimelimitinfo'] = 'This setting limits the time each model spends analysing the site contents.'; $string['neutral'] = 'Neutral'; +$string['neverdelete'] = 'Never delete calculations'; $string['noevaluationbasedassumptions'] = 'Models based on assumptions cannot be evaluated.'; $string['nodata'] = 'No data to analyse'; $string['noinsightsmodel'] = 'This model does not generate insights';