Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…MOODLE_20_STABLE
  • Loading branch information...
commit 3e6c1d4d55b34bf437ef836f4c6adc4a91588098 2 parents 2c85a82 + 371e83d
Sam Hemelryk samhemelryk authored

Showing 1 changed file with 14 additions and 5 deletions. Show diff stats Hide diff stats

  1. +14 5 backup/util/helper/backup_cron_helper.class.php
19 backup/util/helper/backup_cron_helper.class.php
@@ -76,7 +76,7 @@ public static function run_automated_backup($rundirective = self::RUN_ON_SCHEDUL
76 76 } else if ($state === backup_cron_automated_helper::STATE_RUNNING) {
77 77 mtrace('RUNNING');
78 78 if ($rundirective == self::RUN_IMMEDIATELY) {
79   - 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.');
  79 + 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.');
80 80 } else {
81 81 mtrace("automated backup are already running. Execution delayed");
82 82 }
@@ -401,10 +401,19 @@ public static function get_automated_backup_state($rundirective = self::RUN_ON_S
401 401 if ($active === self::AUTO_BACKUP_DISABLED || ($rundirective == self::RUN_ON_SCHEDULE && $active === self::AUTO_BACKUP_MANUAL)) {
402 402 return self::STATE_DISABLED;
403 403 } else if (!empty($config->backup_auto_running)) {
404   - // TODO: We should find some way of checking whether the automated
405   - // backup has infact finished. In 1.9 this was being done by checking
406   - // the log entries.
407   - return self::STATE_RUNNING;
  404 + // Detect if the backup_auto_running semaphore is a valid one
  405 + // by looking for recent activity in the backup_controllers table
  406 + // for backups of type backup::MODE_AUTOMATED
  407 + $timetosee = 60 * 90; // Time to consider in order to clean the semaphore
  408 + $params = array( 'purpose' => backup::MODE_AUTOMATED, 'timetolook' => (time() - $timetosee));
  409 + if ($DB->record_exists_select('backup_controllers',
  410 + "operation = 'backup' AND type = 'course' AND purpose = :purpose AND timemodified > :timetolook", $params)) {
  411 + return self::STATE_RUNNING; // Recent activity found, still running
  412 + } else {
  413 + // No recent activity found, let's clean the semaphore
  414 + mtrace('Automated backups activity not found in last ' . (int)$timetosee/60 . ' minutes. Cleaning running status');
  415 + backup_cron_automated_helper::set_state_running(false);
  416 + }
408 417 }
409 418 return self::STATE_OK;
410 419 }

0 comments on commit 3e6c1d4

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