From d69c84b185944310cefdf326078e988ded1f4dc9 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Thu, 28 Jul 2011 14:32:21 +0800 Subject: [PATCH] MDL-25454 before skipping course backup make sure that there are no change entries in it's log during the last month. Store the nextstarttime even for courses that were not backed up --- .../util/helper/backup_cron_helper.class.php | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/backup/util/helper/backup_cron_helper.class.php b/backup/util/helper/backup_cron_helper.class.php index be15523e77b..870511357cd 100644 --- a/backup/util/helper/backup_cron_helper.class.php +++ b/backup/util/helper/backup_cron_helper.class.php @@ -123,14 +123,25 @@ abstract class backup_cron_automated_helper { $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