Merge branch 'MDL-56602-master-upgrade' of git://github.com/andrewnicols/moodle

This commit is contained in:
Dan Poltawski 2016-11-11 10:22:20 +00:00
commit e9eec33560
4 changed files with 12 additions and 58 deletions

View file

@ -315,6 +315,11 @@ if (!$cache and $version > $CFG->version) { // upgrade
$testsite = 'behat'; $testsite = 'behat';
} }
if (isset($CFG->themerev)) {
// Store the themerev to restore after purging caches.
$themerev = $CFG->themerev;
}
// We purge all of MUC's caches here. // We purge all of MUC's caches here.
// Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true. // Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true.
// This ensures a real config object is loaded and the stores will be purged. // This ensures a real config object is loaded and the stores will be purged.
@ -324,6 +329,11 @@ if (!$cache and $version > $CFG->version) { // upgrade
// We then purge the regular caches. // We then purge the regular caches.
purge_all_caches(); purge_all_caches();
if (isset($themerev)) {
// Restore the themerev
set_config('themerev', $themerev);
}
$output = $PAGE->get_renderer('core', 'admin'); $output = $PAGE->get_renderer('core', 'admin');
if (upgrade_stale_php_files_present()) { if (upgrade_stale_php_files_present()) {

View file

@ -9620,35 +9620,6 @@ function get_course_display_name_for_list($course) {
} }
} }
/**
* Convert a Moodle Version formatted number into a guaranteed incrementing timestamp.
*
* @param float $version The version to convert
* @return int The calculated timestamp
*/
function version_to_timestamp($version) {
// Moodle version numbers are in stored in one of the following formats:
// * YYYYMMDDRR.II
// * YYYYMMDDRR
//
// To convert these into a value akin to a Unix Time Stamp, we take the timestamp of the YYYYMMDD component. and add
// a calculation of the RR.II component.
// The hours/minutes/seconds must be specified otherwise the current time is used.
$date = DateTime::createFromFormat('YmdHis', substr($version, 0, 8) . '000000');
$revision = $date->format('U');
// To ensure a unique incrementing timestamp, we multiple the $rr value by a value larger than the max of $ii,
// and then add $ii.
// As a two-digit number, the max value of $ii is 99, so we multiply by 100.
$revision += (100 * (int) substr($version, 8, 2));
// Note: If there is no .II value, or it is 00, then the substr will return false, but be calculated as 0 when cast to int.
$revision += (int) substr($version, 11, 2);
return $revision;
}
/** /**
* The lang_string class * The lang_string class
* *

View file

@ -86,13 +86,8 @@ function theme_get_revision() {
if (empty($CFG->themedesignermode)) { if (empty($CFG->themedesignermode)) {
if (empty($CFG->themerev)) { if (empty($CFG->themerev)) {
// If theme designer mode is not set, and there is no themerev, this is almost certainly part of the installation. // This only happens during install. It doesn't matter what themerev we use as long as it's positive.
// We attempt to set a themerev based on the Moodle version number to avoid costly rebuilds of the dynamic return 1;
// theme files between each page load.
$version = null;
require("{$CFG->dirroot}/version.php");
return version_to_timestamp($version);
} else { } else {
return $CFG->themerev; return $CFG->themerev;
} }

View file

@ -3282,26 +3282,4 @@ class core_moodlelib_testcase extends advanced_testcase {
'samecourse' => false, 'result' => false], 'samecourse' => false, 'result' => false],
]; ];
} }
/**
* Unit tests for the version_to_timestamp function.
*/
public function test_version_to_timestamp() {
$baseversion = 2016110100.00;
$basestamp = version_to_timestamp($baseversion);
$this->assertEquals(1477929600, $basestamp);
// Adding 00.99 to the version should increase the timestamp.
$stamp = version_to_timestamp($baseversion + .99);
$this->assertGreaterThan($basestamp, $stamp);
// Adding 01.00 to the base version should increase the stamp higher than the 00.99 version.
$newstamp = version_to_timestamp($baseversion + 01.00);
$this->assertGreaterThan($basestamp, $newstamp);
$this->assertGreaterThan($stamp, $newstamp);
// The previous day's timestamp at it's highest increment should be lower than the base version.
$stamp = version_to_timestamp($baseversion - 00.01);
$this->assertLessThan($basestamp, $stamp);
}
} }