diff --git a/includes/common.inc b/includes/common.inc index d0649d7..525ebb5 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -7117,10 +7117,30 @@ function drupal_implode_tags($tags) { * invokes a hook so that other modules' cache data can be cleared as well. */ function drupal_flush_all_caches() { + // Rebuild class registry and module information. + registry_rebuild(); + + // Clear core cache tables. This is required to come first, so all following + // operations are not able to invoke API functions that reload stale + // information from the database cache (which in turn might be cached in a + // static variable). + // Don't clear cache_form - in-progress form submissions may break. + // Page cache is cleared separately below, after most rebuilds (especially + // menu rebuild) have been done. + foreach (array('cache_bootstrap', 'cache') as $table) { + cache_clear_all('*', $table, TRUE); + } + + // Ensure that all following rebuilds can rely on fresh entity information + // and other potentially cached data by resetting all static caches. + // Rebuilding of class registry and modules, as well as flushing of core + // caches potentially acts on previously known information, but this + // interdependency cannot be resolved differently. + drupal_static_reset(); + // Change query-strings on css/js files to enforce reload for all users. _drupal_flush_css_js(); - - registry_rebuild(); + // CSS and JS caches may rely on custom module-provided stream wrappers. drupal_clear_css_cache(); drupal_clear_js_cache(); @@ -7129,19 +7149,26 @@ function drupal_flush_all_caches() { system_rebuild_theme_data(); drupal_theme_rebuild(); + // Rebuilding node types requires fresh entity information. The rebuild will + // also rebuild entity information, if not triggered through other means above + // already. Additionally, node_menu() defines router items based on node types + // so they need to be rebuilt before hook_menu() is invoked. + // @todo Replace with a hook_rebuild(); contributed modules potentially also + // need to rebuild data before hook_menu() is invoked. node_types_rebuild(); - // node_menu() defines menu items based on node types so it needs to come - // after node types are rebuilt. + + // Rebuild the menu router. Many hook_menu() implementations register router + // items based on entity information. menu_rebuild(); // Synchronize to catch any actions that were added or removed. actions_synchronize(); - // Don't clear cache_form - in-progress form submissions may break. - // Ordered so clearing the page cache will always be the last action. - $core = array('cache', 'cache_filter', 'cache_bootstrap', 'cache_page'); - $cache_tables = array_merge(module_invoke_all('flush_caches'), $core); - foreach ($cache_tables as $table) { + // Clear module caches. Some implementations of hook_flush_caches() are not + // only returning cache tables to flush, but additionally attempt to rebuild + // module data, which may rely on various core registries and caches. + // Therefore, invoke these last, after flushing and rebuilding core data. + foreach (module_invoke_all('flush_caches') as $table) { cache_clear_all('*', $table, TRUE); } @@ -7149,6 +7176,9 @@ function drupal_flush_all_caches() { // can get new hook_boot() implementations registered without having to // write a hook_update_N() function. _system_update_bootstrap_status(); + + // Clear the page cache after all cache flushes and rebuilds. + cache_clear_all('*', 'cache_page', TRUE); } /** diff --git a/modules/filter/filter.module b/modules/filter/filter.module index 66fadcb..f4e7503 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -768,6 +768,13 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE) } /** + * Implements hook_flush_caches(). + */ +function filter_flush_caches() { + return array('cache_filter'); +} + +/** * Expands an element into a base element with text format selector attached. * * The form element will be expanded into two separate form elements, one