Permalink
Browse files

MDL-25454 before skipping course backup make sure that there are no c…

…hange entries in it's log during the last month. Store the nextstarttime even for courses that were not backed up
  • Loading branch information...
1 parent 690ef50 commit d69c84b185944310cefdf326078e988ded1f4dc9 @marinaglancy marinaglancy committed Jul 28, 2011
Showing with 18 additions and 7 deletions.
  1. +18 −7 backup/util/helper/backup_cron_helper.class.php
@@ -123,14 +123,25 @@ public static function run_automated_backup($rundirective = self::RUN_ON_SCHEDUL
$backupcourse = $DB->get_record('backup_courses', array('courseid'=>$course->id));
}
+ // Skip courses that do not yet need backup
+ $skipped = !(($backupcourse->nextstarttime >= 0 && $backupcourse->nextstarttime < $now) || $rundirective == self::RUN_IMMEDIATELY);
// Skip backup of unavailable courses that have remained unmodified in a month
- $skipped = false;
- if (empty($course->visible) && ($now - $course->timemodified) > 31*24*60*60) { //Hidden + unmodified last month
- $backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
- $DB->update_record('backup_courses', $backupcourse);
- mtrace('Skipping unchanged course '.$course->fullname);
- $skipped = true;
- } else if (($backupcourse->nextstarttime >= 0 && $backupcourse->nextstarttime < $now) || $rundirective == self::RUN_IMMEDIATELY) {
+ if (!$skipped && empty($course->visible) && ($now - $course->timemodified) > 31*24*60*60) { //Hidden + settings were unmodified last month
+ //Check log if there were any modifications to the course content
+ $sql = "SELECT l.id FROM {log} l WHERE ".
+ "l.course=:courseid AND l.time>:time AND ". $DB->sql_like('l.action', ':action', false, true, true);
+ $params = array('courseid' => $course->id, 'time' => $now-31*24*60*60, 'action' => '%view%');
+ $logs = $DB->get_records_sql($sql, $params, 0, 1);
+ if (empty($logs)) {
+ $backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
+ $backupcourse->nextstarttime = $nextstarttime;
+ $DB->update_record('backup_courses', $backupcourse);
+ mtrace('Skipping unchanged course '.$course->fullname);
+ $skipped = true;
+ }
+ }
+ //Now we backup every non-skipped course
+ if (!$skipped) {
mtrace('Backing up '.$course->fullname, '...');
//We have to send a email because we have included at least one backup

0 comments on commit d69c84b

Please sign in to comment.