MDL-74032 core_cache: Coding error before upgrade with versioned cache

In certain cases where it doesn't already redirect to run the upgrade,
users could see an exception 'Unexpectedly found non-versioned cache
entry'. This change ensures the upgrade happens instead.
This commit is contained in:
sam marshall 2022-03-08 12:08:26 +00:00
parent 1d99ba19a2
commit 3776b5542f
2 changed files with 9 additions and 4 deletions

View File

@ -510,11 +510,16 @@ class cache implements cache_loader {
try {
$validversion = self::check_version($result, $requiredversion);
} catch (\coding_exception $e) {
// If we get an exception because there is incorrect data in the cache (not
// In certain circumstances this could happen before users are taken to the upgrade
// screen when upgrading from an earlier Moodle version that didn't use a versioned
// cache for this item, so redirect instead of showing error if that's the case.
redirect_if_major_upgrade_required();
// If we still get an exception because there is incorrect data in the cache (not
// versioned when it ought to be), delete it so this exception goes away next time.
// The exception should only happen if there is a code bug (which is why we still
// throw it) but there are unusual scenarios where it might happen and that would
// be annoying if it doesn't fix itself.
// throw it) but there are unusual scenarios in development where it might happen
// and that would be annoying if it doesn't fix itself.
$this->store->delete($parsedkey);
throw $e;
}

View File

@ -1423,7 +1423,7 @@ function disable_output_buffering() {
*/
function is_major_upgrade_required() {
global $CFG;
$lastmajordbchanges = 2021101900.01;
$lastmajordbchanges = 2022022200.00;
$required = empty($CFG->version);
$required = $required || (float)$CFG->version < $lastmajordbchanges;