From d2cdaf68ae1bcf7a72b92d22f8e8fa405580e571 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 1 Jun 2017 09:56:48 +0200 Subject: [PATCH] MDL-58859 analytics: No enddate update if wrong guess Part of MDL-57791 epic. --- .../tool/models/cli/guess_course_start_and_end.php | 13 ++++++++++--- lang/en/analytics.php | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/admin/tool/models/cli/guess_course_start_and_end.php b/admin/tool/models/cli/guess_course_start_and_end.php index e4d8b37cb23..50fa3743245 100644 --- a/admin/tool/models/cli/guess_course_start_and_end.php +++ b/admin/tool/models/cli/guess_course_start_and_end.php @@ -77,7 +77,7 @@ if ($options['filter'] !== false) { // We need admin permissions. \core\session\manager::set_user(get_admin()); -$conditions = array(); +$conditions = array('id != 1'); if (!$options['guessall']) { if ($options['guessstart']) { $conditions[] = '(startdate is null or startdate = 0)'; @@ -174,10 +174,17 @@ function tool_models_calculate_course_dates($course, $options) { // Update it to something we guess. $course->enddate = $guessedenddate; - $notification .= PHP_EOL . ' ' . get_string('enddate') . ': ' . userdate($guessedenddate); + + if ($course->enddate > $course->startdate) { + $notification .= PHP_EOL . ' ' . get_string('enddate') . ': ' . userdate($course->enddate); + } else { + $notification .= PHP_EOL . ' ' . get_string('errorendbeforestart', 'analytics', userdate($course->enddate)); + } if ($options['update']) { - update_course($course); + if ($course->enddate > $course->startdate) { + update_course($course); + } } } } diff --git a/lang/en/analytics.php b/lang/en/analytics.php index 5bcd12cc0ec..35eda79a7cd 100644 --- a/lang/en/analytics.php +++ b/lang/en/analytics.php @@ -28,6 +28,7 @@ $string['analyticssettings'] = 'Analytics settings'; $string['enabledtimesplittings'] = 'Time splitting methods'; $string['enabledtimesplittings_help'] = 'The time splitting method divides the course duration in parts, the predictions engine will run at the end of these parts. It is recommended that you only enable the time splitting methods you could be interested on using; the evaluation process will iterate through all of them so the more time splitting methods to go through the slower the evaluation process will be.'; $string['erroralreadypredict'] = '{$a} file has already been used to predict'; +$string['errorendbeforestart'] = 'The guessed end date ({$a}) is before the course start date.'; $string['errorinvalidindicator'] = 'Invalid {$a} indicator'; $string['errorinvalidtimesplitting'] = 'Invalid time splitting, please ensure you added the class fully qualified class name'; $string['errornoindicators'] = 'This model does not have any indicator';