Commit 62b6016c authored by Gábor Hojtsy's avatar Gábor Hojtsy

Issue #235673 by yched, Damien Tournoud, swentel, pwolanin, redndahead, sun,...

Issue #235673 by yched, Damien Tournoud, swentel, pwolanin, redndahead, sun, carlos8f, c960657: Changes to block caching mode not caught
parent c1b2bb90
......@@ -223,15 +223,22 @@ function block_block($op = 'list', $delta = 0, $edit = array()) {
/**
* 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;
......@@ -239,7 +246,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');
......@@ -249,7 +256,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
......@@ -265,9 +272,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.
......@@ -291,12 +302,25 @@ 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.
$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.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment