diff --git a/backup/util/helper/backup_cron_helper.class.php b/backup/util/helper/backup_cron_helper.class.php index 5dfdc70c766..d1f649cd751 100644 --- a/backup/util/helper/backup_cron_helper.class.php +++ b/backup/util/helper/backup_cron_helper.class.php @@ -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. @@ -93,7 +94,8 @@ abstract class backup_cron_automated_helper { 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. diff --git a/backup/util/helper/tests/cronhelper_test.php b/backup/util/helper/tests/cronhelper_test.php index 22833e74533..23ed6687dd4 100644 --- a/backup/util/helper/tests/cronhelper_test.php +++ b/backup/util/helper/tests/cronhelper_test.php @@ -393,7 +393,7 @@ class cronhelper_test extends \advanced_testcase { $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;