Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.299.2.4 diff -u -p -r1.299.2.4 block.module --- modules/block/block.module 6 Oct 2009 12:13:01 -0000 1.299.2.4 +++ modules/block/block.module 17 Jun 2010 17:37:55 -0000 @@ -224,15 +224,22 @@ function block_block($op = 'list', $delt /** * Update the 'blocks' DB table with the blocks currently exported by modules. * + * @param $theme + * The theme to rehash blocks for. If not provided, defaults to the currently + * used theme. + * * @return * Blocks currently exported by modules. */ -function _block_rehash() { +function _block_rehash($theme = NULL) { global $theme_key; init_theme(); + if (!isset($theme)) { + $theme = $theme_key; + } - $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key); + $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme); $old_blocks = array(); while ($old_block = db_fetch_array($result)) { $old_blocks[$old_block['module']][$old_block['delta']] = $old_block; @@ -240,7 +247,7 @@ function _block_rehash() { $blocks = array(); // Valid region names for the theme. - $regions = system_region_list($theme_key); + $regions = system_region_list($theme); foreach (module_list() as $module) { $module_blocks = module_invoke($module, 'block', 'list'); @@ -250,7 +257,7 @@ function _block_rehash() { // If it's a new block, add identifiers. $block['module'] = $module; $block['delta'] = $delta; - $block['theme'] = $theme_key; + $block['theme'] = $theme; if (!isset($block['pages'])) { // {block}.pages is type 'text', so it cannot have a // default value, and not null, so we need to provide @@ -266,9 +273,13 @@ function _block_rehash() { } else { // If it's an existing block, database settings should overwrite - // the code. But aside from 'info' everything that's definable in - // code is stored in the database and we do not store 'info', so we - // do not need to update the database here. + // the code. The only exceptions are 'cache' which is only definable + // and updatable in the code, and 'info' which is not stored in + // the database. + // Update the cache mode only; the other values don't need to change. + if (isset($block['cache']) && $block['cache'] != $old_blocks[$module][$delta]['cache']) { + db_query("UPDATE {blocks} SET cache = %d WHERE bid = %d", $block['cache'], $old_blocks[$module][$delta]['bid']); + } // Add 'info' to this block. $old_blocks[$module][$delta]['info'] = $block['info']; // If the region name does not exist, disable the block and assign it to none. @@ -292,13 +303,27 @@ function _block_rehash() { // Remove blocks that are no longer defined by the code from the database. foreach ($old_blocks as $module => $old_module_blocks) { foreach ($old_module_blocks as $delta => $block) { - db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme_key); + db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme); } } return $blocks; } /** + * Implementation of hook_flush_caches(). + */ +function block_flush_caches() { + // Rehash blocks for active themes. We don't use list_themes() here, + // because if MAINTENANCE_MODE is defined it skips reading the database, + // and we can't tell which themes are active. + // Inner join on {blocks}? + $result = db_query("SELECT name FROM {system} WHERE type = 'theme' AND status = 1"); + while ($theme = db_result($result)) { + _block_rehash($theme); + } +} + +/** * Returns information from database about a user-created (custom) block. * * @param $bid