From e1abf003eedd5cb04dfe8de723c7797a21764ed2 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Thu, 28 Jun 2012 09:32:13 +0800 Subject: [PATCH] MDL-29470 Backup: fixed unexpected next automated backup date --- .../util/helper/backup_cron_helper.class.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/backup/util/helper/backup_cron_helper.class.php b/backup/util/helper/backup_cron_helper.class.php index 42a5bf53399..b711f6e1aa3 100644 --- a/backup/util/helper/backup_cron_helper.class.php +++ b/backup/util/helper/backup_cron_helper.class.php @@ -281,23 +281,25 @@ abstract class backup_cron_automated_helper { $midnight = usergetmidnight($now, $timezone); $date = usergetdate($now, $timezone); - //Get number of days (from today) to execute backups - $automateddays = substr($config->backup_auto_weekdays,$date['wday']) . $config->backup_auto_weekdays; - $daysfromtoday = strpos($automateddays, "1"); + // Get number of days (from today) to execute backups + $automateddays = substr($config->backup_auto_weekdays, $date['wday']) . $config->backup_auto_weekdays; + $daysfromtoday = strpos($automateddays, "1", 1); + + // If we can't find the next day, we set it to tomorrow if (empty($daysfromtoday)) { $daysfromtoday = 1; } - //If some day has been found + // If some day has been found if ($daysfromtoday !== false) { - //Calculate distance - $dist = ($daysfromtoday * 86400) + //Days distance - ($config->backup_auto_hour * 3600) + //Hours distance - ($config->backup_auto_minute * 60); //Minutes distance + // Calculate distance + $dist = ($daysfromtoday * 86400) + // Days distance + ($config->backup_auto_hour * 3600) + // Hours distance + ($config->backup_auto_minute * 60); // Minutes distance $result = $midnight + $dist; } - //If that time is past, call the function recursively to obtain the next valid day + // If that time is past, call the function recursively to obtain the next valid day if ($result > 0 && $result < time()) { $result = self::calculate_next_automated_backup($timezone, $result); }