Skip to content
Browse files

Merge branch 'MDL-25811_m20' of git://github.com/stronk7/moodle into …

…MOODLE_20_STABLE
  • Loading branch information...
2 parents 2c85a82 + 371e83d commit 3e6c1d4d55b34bf437ef836f4c6adc4a91588098 Sam Hemelryk committed Jun 22, 2011
Showing with 14 additions and 5 deletions.
  1. +14 −5 backup/util/helper/backup_cron_helper.class.php
View
19 backup/util/helper/backup_cron_helper.class.php
@@ -76,7 +76,7 @@ public static function run_automated_backup($rundirective = self::RUN_ON_SCHEDUL
} else if ($state === backup_cron_automated_helper::STATE_RUNNING) {
mtrace('RUNNING');
if ($rundirective == self::RUN_IMMEDIATELY) {
- mtrace('automated backups are already. If this script is being run by cron this constitues an error. You will need to increase the time between executions within cron.');
+ mtrace('Automated backups are already running. If this script is being run by cron this constitues an error. You will need to increase the time between executions within cron.');
} else {
mtrace("automated backup are already running. Execution delayed");
}
@@ -401,10 +401,19 @@ public static function get_automated_backup_state($rundirective = self::RUN_ON_S
if ($active === self::AUTO_BACKUP_DISABLED || ($rundirective == self::RUN_ON_SCHEDULE && $active === self::AUTO_BACKUP_MANUAL)) {
return self::STATE_DISABLED;
} else if (!empty($config->backup_auto_running)) {
- // TODO: We should find some way of checking whether the automated
- // backup has infact finished. In 1.9 this was being done by checking
- // the log entries.
- return self::STATE_RUNNING;
+ // Detect if the backup_auto_running semaphore is a valid one
+ // by looking for recent activity in the backup_controllers table
+ // for backups of type backup::MODE_AUTOMATED
+ $timetosee = 60 * 90; // Time to consider in order to clean the semaphore
+ $params = array( 'purpose' => backup::MODE_AUTOMATED, 'timetolook' => (time() - $timetosee));
+ if ($DB->record_exists_select('backup_controllers',
+ "operation = 'backup' AND type = 'course' AND purpose = :purpose AND timemodified > :timetolook", $params)) {
+ return self::STATE_RUNNING; // Recent activity found, still running
+ } else {
+ // No recent activity found, let's clean the semaphore
+ mtrace('Automated backups activity not found in last ' . (int)$timetosee/60 . ' minutes. Cleaning running status');
+ backup_cron_automated_helper::set_state_running(false);
+ }
}
return self::STATE_OK;
}

0 comments on commit 3e6c1d4

Please sign in to comment.
Something went wrong with that request. Please try again.