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