Skip to content

Commit

Permalink
Merge branch 'MDL-60758_master' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Nov 10, 2017
2 parents 4ceece6 + 20305a8 commit c392518
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions admin/tool/analytics/cli/guess_course_start_and_end.php
Original file line number Diff line number Diff line change
@@ -117,12 +117,21 @@ function tool_analytics_calculate_course_dates($course, $options) {

$notification = $course->shortname . ' (id = ' . $course->id . '): ';

$originalenddate = null;
$guessedstartdate = null;
$guessedenddate = null;
$samestartdate = null;
$lowerenddate = null;

if ($options['guessstart'] || $options['guessall']) {

$originalstartdate = $course->startdate;

$guessedstartdate = $courseman->guess_start();
if ($guessedstartdate == $originalstartdate) {
$samestartdate = ($guessedstartdate == $originalstartdate);
$lowerenddate = ($course->enddate && ($course->enddate < $guessedstartdate));

if ($samestartdate) {
if (!$guessedstartdate) {
$notification .= PHP_EOL . ' ' . get_string('cantguessstartdate', 'tool_analytics');
} else {
@@ -131,6 +140,9 @@ function tool_analytics_calculate_course_dates($course, $options) {
}
} else if (!$guessedstartdate) {
$notification .= PHP_EOL . ' ' . get_string('cantguessstartdate', 'tool_analytics');
} else if ($lowerenddate) {
$notification .= PHP_EOL . ' ' . get_string('cantguessstartdate', 'tool_analytics') . ': ' .
get_string('enddatebeforestartdate', 'error') . ' - ' . userdate($guessedstartdate);
} else {
// Update it to something we guess.

@@ -151,6 +163,10 @@ function tool_analytics_calculate_course_dates($course, $options) {

if ($options['guessend'] || $options['guessall']) {

if (!empty($lowerenddate) && !empty($guessedstartdate)) {
$course->startdate = $guessedstartdate;
}

$originalenddate = $course->enddate;

$format = course_get_format($course);
@@ -196,10 +212,8 @@ function tool_analytics_calculate_course_dates($course, $options) {
$updateit = true;
}

if ($options['update']) {
if ($course->enddate > $course->startdate) {
update_course($course);
}
if ($options['update'] && $updateit) {
update_course($course);
}
}
}

0 comments on commit c392518

Please sign in to comment.