Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-36512 Purging a file store actually purges nothing

  • Loading branch information...
commit fb8305dec7ac437a890cfccb0212bbe7009a032c 1 parent 8ccaa29
Matteo Scaramuccia scara authored
Showing with 80 additions and 21 deletions.
  1. +55 −0 cache/classes/config.php
  2. +25 −21 cache/classes/helper.php
55 cache/classes/config.php
View
@@ -345,6 +345,61 @@ public function get_definitions() {
}
/**
+ * Returns the definitions mapped into the given store name.
+ *
+ * @param string $storename
+ * @return array Associative array of definitions, id=>definition
+ */
+ public static function get_definitions_by_store($storename) {
+ $definitions = array();
+
+ $config = cache_config::instance();
+ $stores = $config->get_all_stores();
+ if (!array_key_exists($storename, $stores)) {
+ // The store does not exist.
+ return false;
+ }
+
+ $defmappings = $config->get_definition_mappings();
+ // Create an associative array for the definition mappings.
+ $thedefmappings = array();
+ foreach ($defmappings as $defmapping) {
+ $thedefmappings[$defmapping['definition']] = $defmapping;
+ }
+
+ // Search for matches in default mappings.
+ $defs = $config->get_definitions();
+ foreach($config->get_mode_mappings() as $modemapping) {
+ if ($modemapping['store'] !== $storename) {
+ continue;
+ }
+ foreach($defs as $id => $definition) {
+ if ($definition['mode'] !== $modemapping['mode']) {
+ continue;
+ }
+ // Exclude custom definitions mapping: they will be managed few lines below.
+ if (array_key_exists($id, $thedefmappings)) {
+ continue;
+ }
+ $definitions[$id] = $definition;
+ }
+ }
+
+ // Search for matches in the custom definitions mapping
+ foreach ($defmappings as $defmapping) {
+ if ($defmapping['store'] !== $storename) {
+ continue;
+ }
+ $definition = $config->get_definition_by_id($defmapping['definition']);
+ if ($definition) {
+ $definitions[$defmapping['definition']] = $definition;
+ }
+ }
+
+ return $definitions;
+ }
+
+ /**
* Returns all of the stores that are suitable for the given mode and requirements.
*
* @param int $mode One of cache_store::MODE_*
46 cache/classes/helper.php
View
@@ -389,16 +389,9 @@ public static function get_stats() {
*/
public static function purge_all() {
$config = cache_config::instance();
- $stores = $config->get_all_stores();
- $definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'core', 'cache_purge');
- foreach ($stores as $store) {
- $class = $store['class'];
- $instance = new $class($store['name'], $store['configuration']);
- if (!$instance->is_ready()) {
- continue;
- }
- $instance->initialise($definition);
- $instance->purge();
+
+ foreach ($config->get_all_stores() as $store) {
+ self::purge_store($store['name']);
}
}
@@ -410,21 +403,32 @@ public static function purge_all() {
*/
public static function purge_store($storename) {
$config = cache_config::instance();
- foreach ($config->get_all_stores() as $store) {
- if ($store['name'] !== $storename) {
- continue;
- }
- $class = $store['class'];
+
+ $stores = $config->get_all_stores();
+ if (!array_key_exists($storename, $stores)) {
+ // The store does not exist.
+ return false;
+ }
+
+ $store = $stores[$storename];
+ $class = $store['class'];
+
+ // Found the store: is it ready?
+ $instance = new $class($store['name'], $store['configuration']);
+ if (!$instance->is_ready()) {
+ unset($instance);
+ return false;
+ }
+
+ foreach ($config->get_definitions_by_store($storename) as $id => $definition) {
+ $definition = cache_definition::load($id, $definition);
$instance = new $class($store['name'], $store['configuration']);
- if (!$instance->is_ready()) {
- continue;
- }
- $definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'core', 'cache_purge');
$instance->initialise($definition);
$instance->purge();
- return true;
+ unset($instance);
}
- return false;
+
+ return true;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.