MDL-69475 backup: Proper handling of backup::RELEASE versions
1) Remove any floatval() casting. They are breaking / killing .10 versions (converting them to .1). Since Moodle 2.0 all the backup::RELEASE have been 100% numerical values. 2) Use version_compare() always to compare backup::RELEASE values. They are always versions and the function is aware of versions > .9, able to clean/ignore alpha chars... and everything else. Note that I've also changed a couple of cases in formats (topics and weeks) that were correct, but just added the same comment and used the same version_compare() comparison parameters style, so all uses in core are consistent (and safe to be copied out there).
This commit is contained in:
@@ -122,7 +122,7 @@ class restore_gradebook_structure_step extends restore_structure_step {
|
||||
}
|
||||
|
||||
// Identify the backup we're dealing with.
|
||||
$backuprelease = floatval($this->get_task()->get_info()->backup_release); // The major version: 2.9, 3.0, ...
|
||||
$backuprelease = $this->get_task()->get_info()->backup_release; // The major version: 2.9, 3.0, 3.10...
|
||||
$backupbuild = 0;
|
||||
preg_match('/(\d{8})/', $this->get_task()->get_info()->moodle_release, $matches);
|
||||
if (!empty($matches[1])) {
|
||||
@@ -132,7 +132,7 @@ class restore_gradebook_structure_step extends restore_structure_step {
|
||||
// On older versions the freeze value has to be converted.
|
||||
// We do this from here as it is happening right before the file is read.
|
||||
// This only targets the backup files that can contain the legacy freeze.
|
||||
if ($backupbuild > 20150618 && ($backuprelease < 3.0 || $backupbuild < 20160527)) {
|
||||
if ($backupbuild > 20150618 && (version_compare($backuprelease, '3.0', '<') || $backupbuild < 20160527)) {
|
||||
$this->rewrite_step_backup_file_for_legacy_freeze($fullpath);
|
||||
}
|
||||
|
||||
@@ -505,8 +505,7 @@ class restore_gradebook_structure_step extends restore_structure_step {
|
||||
$gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->get_courseid());
|
||||
preg_match('/(\d{8})/', $this->get_task()->get_info()->moodle_release, $matches);
|
||||
$backupbuild = (int)$matches[1];
|
||||
// The function floatval will return a float even if there is text mixed with the release number.
|
||||
$backuprelease = floatval($this->get_task()->get_info()->backup_release);
|
||||
$backuprelease = $this->get_task()->get_info()->backup_release; // The major version: 2.9, 3.0, 3.10...
|
||||
|
||||
// Extra credits need adjustments only for backups made between 2.8 release (20141110) and the fix release (20150619).
|
||||
if (!$gradebookcalculationsfreeze && $backupbuild >= 20141110 && $backupbuild < 20150619) {
|
||||
@@ -521,7 +520,7 @@ class restore_gradebook_structure_step extends restore_structure_step {
|
||||
// Courses from before 3.1 (20160518) may have a letter boundary problem and should be checked for this issue.
|
||||
// Backups from before and including 2.9 could have a build number that is greater than 20160518 and should
|
||||
// be checked for this problem.
|
||||
if (!$gradebookcalculationsfreeze && ($backupbuild < 20160518 || $backuprelease <= 2.9)) {
|
||||
if (!$gradebookcalculationsfreeze && ($backupbuild < 20160518 || version_compare($backuprelease, '2.9', '<='))) {
|
||||
require_once($CFG->libdir . '/db/upgradelib.php');
|
||||
upgrade_course_letter_boundary($this->get_courseid());
|
||||
}
|
||||
@@ -4631,11 +4630,11 @@ class restore_create_categories_and_questions extends restore_structure_step {
|
||||
|
||||
// Before 3.5, question categories could be created at top level.
|
||||
// From 3.5 onwards, all question categories should be a child of a special category called the "top" category.
|
||||
$backuprelease = floatval($this->get_task()->get_info()->backup_release);
|
||||
$backuprelease = $this->get_task()->get_info()->backup_release; // The major version: 2.9, 3.0, 3.10...
|
||||
preg_match('/(\d{8})/', $this->get_task()->get_info()->moodle_release, $matches);
|
||||
$backupbuild = (int)$matches[1];
|
||||
$before35 = false;
|
||||
if ($backuprelease < 3.5 || $backupbuild < 20180205) {
|
||||
if (version_compare($backuprelease, '3.5', '<') || $backupbuild < 20180205) {
|
||||
$before35 = true;
|
||||
}
|
||||
if (empty($mapping->info->parent) && $before35) {
|
||||
@@ -4892,11 +4891,11 @@ class restore_move_module_questions_categories extends restore_execution_step {
|
||||
protected function define_execution() {
|
||||
global $DB;
|
||||
|
||||
$backuprelease = floatval($this->task->get_info()->backup_release);
|
||||
$backuprelease = $this->task->get_info()->backup_release; // The major version: 2.9, 3.0, 3.10...
|
||||
preg_match('/(\d{8})/', $this->task->get_info()->moodle_release, $matches);
|
||||
$backupbuild = (int)$matches[1];
|
||||
$after35 = false;
|
||||
if ($backuprelease >= 3.5 && $backupbuild > 20180205) {
|
||||
if (version_compare($backuprelease, '3.5', '>=') && $backupbuild > 20180205) {
|
||||
$after35 = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -581,11 +581,11 @@ abstract class restore_dbops {
|
||||
$rc = restore_controller_dbops::load_controller($restoreid);
|
||||
$restoreinfo = $rc->get_info();
|
||||
$rc->destroy(); // Always need to destroy.
|
||||
$backuprelease = floatval($restoreinfo->backup_release);
|
||||
$backuprelease = $restoreinfo->backup_release; // The major version: 2.9, 3.0, 3.10...
|
||||
preg_match('/(\d{8})/', $restoreinfo->moodle_release, $matches);
|
||||
$backupbuild = (int)$matches[1];
|
||||
$after35 = false;
|
||||
if ($backuprelease >= 3.5 && $backupbuild > 20180205) {
|
||||
if (version_compare($backuprelease, '3.5', '>=') && $backupbuild > 20180205) {
|
||||
$after35 = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,8 @@ class restore_format_topics_plugin extends restore_format_plugin {
|
||||
*/
|
||||
protected function need_restore_numsections() {
|
||||
$backupinfo = $this->step->get_task()->get_info();
|
||||
$backuprelease = $backupinfo->backup_release;
|
||||
return version_compare($backuprelease, '3.3', 'lt');
|
||||
$backuprelease = $backupinfo->backup_release; // The major version: 2.9, 3.0, 3.10...
|
||||
return version_compare($backuprelease, '3.3', '<');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,8 +48,8 @@ class restore_format_weeks_plugin extends restore_format_plugin {
|
||||
*/
|
||||
protected function is_pre_33_backup() {
|
||||
$backupinfo = $this->step->get_task()->get_info();
|
||||
$backuprelease = $backupinfo->backup_release;
|
||||
return version_compare($backuprelease, '3.3', 'lt');
|
||||
$backuprelease = $backupinfo->backup_release; // The major version: 2.9, 3.0, 3.10...
|
||||
return version_compare($backuprelease, '3.3', '<');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user