Skip to content

Commit

Permalink
MDL-73801 backup: set predictably ordered backup next start time.
Browse files Browse the repository at this point in the history
Prior to this change, the testcase would assert ordering based on
identical fields which could lead to random failures. Set distinct
next start time of course backup, and also remove random ordering
by sorting on defined course order (all other fields being equal).
  • Loading branch information
paulholden authored and snake committed May 26, 2022
1 parent a63efe4 commit af8c168
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion backup/util/helper/backup_cron_helper.class.php
Expand Up @@ -77,6 +77,7 @@ abstract class backup_cron_automated_helper {
* First backup courses that do not have an entry in backup_courses first,
* as they are likely new and never been backed up. Do the oldest modified courses first.
* Then backup courses that have previously been backed up starting with the oldest next start time.
* Finally, all else being equal, defer to the sortorder of the courses.
*
* @param null|int $now timestamp to use in course selection.
* @return moodle_recordset The recordset of matching courses.
Expand All @@ -93,7 +94,8 @@ protected static function get_courses($now = null) {
LEFT JOIN {backup_courses} bc ON bc.courseid = c.id
WHERE bc.nextstarttime IS NULL OR bc.nextstarttime < ?
ORDER BY nextstarttime ASC,
c.timemodified DESC';
c.timemodified DESC,
c.sortorder';

$params = array(
$now, // Only get courses where the backup start time is in the past.
Expand Down
2 changes: 1 addition & 1 deletion backup/util/helper/tests/cronhelper_test.php
Expand Up @@ -383,7 +383,7 @@ private function course_setup() {
$backupcourse3 = new stdClass;
$backupcourse3->courseid = $course3->id;
$backupcourse3->laststatus = testable_backup_cron_automated_helper::BACKUP_STATUS_OK;
$backupcourse3->nextstarttime = 1554858160;
$backupcourse3->nextstarttime = 1554822160;
$DB->insert_record('backup_courses', $backupcourse3);

$backupcourse4 = new stdClass;
Expand Down

0 comments on commit af8c168

Please sign in to comment.