From 3d49421a2151dff9df65f375de83200b89b352cb Mon Sep 17 00:00:00 2001 From: Peter Burnett Date: Tue, 21 Apr 2020 10:00:35 +1000 Subject: [PATCH] MDL-68440 cache: Added counting of default mappings --- cache/classes/administration_helper.php | 20 +++++++++++++++++++- cache/tests/administration_helper_test.php | 7 ++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cache/classes/administration_helper.php b/cache/classes/administration_helper.php index 551e62c1695..620505cd6ed 100644 --- a/cache/classes/administration_helper.php +++ b/cache/classes/administration_helper.php @@ -101,13 +101,31 @@ abstract class administration_helper extends cache_helper { ksort($default); $return = $return + $default; - foreach ($instance->get_definition_mappings() as $mapping) { + $mappings = $instance->get_definition_mappings(); + foreach ($mappings as $mapping) { if (!array_key_exists($mapping['store'], $return)) { continue; } $return[$mapping['store']]['mappings']++; } + // Now get all definitions, and if not mapped, increment the defaults for the mode. + $modemappings = $instance->get_mode_mappings(); + foreach ($instance->get_definitions() as $definition) { + // Construct the definition name to search for. + $defname = $definition['component'] . '/' . $definition['area']; + // Skip if definition is already mapped. + if (array_search($defname, array_column($mappings, 'definition')) !== false) { + continue; + } + + $mode = $definition['mode']; + // Get the store name of the default mapping from the mode. + $index = array_search($mode, array_column($modemappings, 'mode')); + $store = $modemappings[$index]['store']; + $return[$store]['mappings']++; + } + return $return; } diff --git a/cache/tests/administration_helper_test.php b/cache/tests/administration_helper_test.php index 865539f51d3..146efe34abc 100644 --- a/cache/tests/administration_helper_test.php +++ b/cache/tests/administration_helper_test.php @@ -92,7 +92,12 @@ class core_cache_administration_helper_testcase extends advanced_testcase { $this->assertEquals(0, $summary['default']); $this->assertEquals(1, $summary['isready']); $this->assertEquals(1, $summary['requirementsmet']); - $this->assertEquals(1, $summary['mappings']); + + // Find the number of mappings to sessionstore. + $mappingcount = count(array_filter($config->get_definitions(), function($element) { + return $element['mode'] === cache_store::MODE_APPLICATION; + })); + $this->assertEquals($mappingcount, $summary['mappings']); $definitionsummaries = core_cache\administration_helper::get_definition_summaries(); $this->assertInternalType('array', $definitionsummaries);