MDL-44141 Completion: System updates data during restore
The completion system has code which is supposed to prevent it updating completion status while grades are being restored. This code was a nasty hack and had not worked for some time. As a result completion dates were restored incorrectly. This commit implements a 'proper' way to find out if a restore is currently running, replacing the previous hack.
This commit is contained in:
@@ -59,6 +59,9 @@ class restore_controller extends backup implements loggable {
|
||||
|
||||
protected $checksum; // Cache @checksumable results for lighter @is_checksum_correct() uses
|
||||
|
||||
/** @var int Number of restore_controllers that are currently executing */
|
||||
protected static $executing = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $tempdir Directory under tempdir/backup awaiting restore
|
||||
@@ -312,7 +315,26 @@ class restore_controller extends backup implements loggable {
|
||||
$this->log('notifying plan about excluded activities by type', backup::LOG_DEBUG);
|
||||
$this->plan->set_excluding_activities();
|
||||
}
|
||||
return $this->plan->execute();
|
||||
self::$executing++;
|
||||
try {
|
||||
$this->plan->execute();
|
||||
} catch (Exception $e) {
|
||||
self::$executing--;
|
||||
throw $e;
|
||||
}
|
||||
self::$executing--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether restore is currently executing. Certain parts of code that
|
||||
* is called during restore, but not directly part of the restore system, may
|
||||
* need to behave differently during restore (e.g. do not bother resetting a
|
||||
* cache because we know it will be reset at end of operation).
|
||||
*
|
||||
* @return bool True if any restore is currently executing
|
||||
*/
|
||||
public static function is_executing() {
|
||||
return self::$executing > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -779,22 +779,21 @@ class grade_grade extends grade_object {
|
||||
unset($SESSION->gradescorecache[$this->itemid]);
|
||||
}
|
||||
|
||||
// Ignore during restore
|
||||
// TODO There should be a proper way to determine when we are in restore
|
||||
// so that this hack looking for a $restore global is not needed.
|
||||
global $restore;
|
||||
if (!empty($restore->backup_unique_code)) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once($CFG->libdir.'/completionlib.php');
|
||||
|
||||
// Bail out immediately if completion is not enabled for site (saves loading
|
||||
// grade item below)
|
||||
// grade item & requiring the restore stuff).
|
||||
if (!completion_info::is_enabled_for_site()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore during restore, as completion data will be updated anyway and
|
||||
// doing it now will result in incorrect dates (it will say they got the
|
||||
// grade completion now, instead of the correct time).
|
||||
if (class_exists('restore_controller', false) && restore_controller::is_executing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load information about grade item
|
||||
$this->load_grade_item();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user