Commit a3b28597 authored by Dries's avatar Dries

- Patch #235673 by carlos8f, yched, swentel, redndahead, Damien Tournoud,...

- Patch #235673 by carlos8f, yched, swentel, redndahead, Damien Tournoud, pwolanin, dww: changes to block caching mode not caught.
parent 5f5c024b
......@@ -365,6 +365,11 @@ function _block_rehash($theme = NULL) {
foreach ($database_blocks as $block) {
// Preserve info which is not in the database.
$block->info = $current_blocks[$block->module][$block->delta]['info'];
// The cache mode can only by set from hook_block_info(), so that has
// precedence over the database's value.
if (isset($current_blocks[$block->module][$block->delta]['cache'])) {
$block->cache = $current_blocks[$block->module][$block->delta]['cache'];
}
// Blocks stored in the database override the blocks defined in code.
$current_blocks[$block->module][$block->delta] = get_object_vars($block);
// Preserve this block.
......@@ -395,7 +400,7 @@ function _block_rehash($theme = NULL) {
$block['region'] = BLOCK_REGION_NONE;
}
// There is no point saving disabled blocks. Still, we need to save them
// beecause the 'title' attribute is saved to the {blocks} table.
// because the 'title' attribute is saved to the {blocks} table.
if (isset($block['bid'])) {
// If the block has a bid property, it comes from the database and
// the record needs to be updated, so set the primary key to 'bid'
......@@ -562,7 +567,7 @@ function block_theme_initialize($theme) {
$result = db_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $default_theme), array('fetch' => PDO::FETCH_ASSOC));
foreach ($result as $block) {
// If the region isn't supported by the theme, assign the block to the theme's default region.
if (!array_key_exists($block['region'], $regions)) {
if ($block['status'] && !array_key_exists($block['region'], $regions)) {
$block['region'] = system_default_region($theme);
}
$block['theme'] = $theme;
......@@ -842,6 +847,14 @@ function _block_get_cache_id($block) {
* Implements 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.
$themes = db_query("SELECT name FROM {system} WHERE type = 'theme' AND status = 1");
foreach ($themes as $theme) {
_block_rehash($theme->name);
}
return array('cache_block');
}
......
......@@ -261,6 +261,29 @@ class BlockTestCase extends DrupalWebTestCase {
));
$this->assertFieldByXPath($xpath, FALSE, t('Custom block found in %region_name region.', array('%region_name' => $region['name'])));
}
/**
* Test _block_rehash().
*/
function testBlockRehash() {
module_enable(array('block_test'));
$this->assertTrue(module_exists('block_test'), t('Test block module enabled.'));
// Our new block should be inserted in the database when we visit the
// block management page.
$this->drupalGet('admin/structure/block');
// Our test block's caching should default to DRUPAL_CACHE_PER_ROLE.
$current_caching = db_query("SELECT cache FROM {block} WHERE module = 'block_test' AND delta = 'test_cache'")->fetchField();
$this->assertEqual($current_caching, DRUPAL_CACHE_PER_ROLE, t('Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.'));
// Disable caching for this block.
variable_set('block_test_caching', DRUPAL_NO_CACHE);
// Flushing all caches should call _block_rehash().
drupal_flush_all_caches();
// Verify that the database is updated with the new caching mode.
$current_caching = db_query("SELECT cache FROM {block} WHERE module = 'block_test' AND delta = 'test_cache'")->fetchField();
$this->assertEqual($current_caching, DRUPAL_NO_CACHE, t("Test block's database entry updated to DRUPAL_NO_CACHE."));
}
}
class NonDefaultBlockAdmin extends DrupalWebTestCase {
......
......@@ -12,6 +12,7 @@
function block_test_block_info() {
$blocks['test_cache'] = array(
'info' => t('Test block caching'),
'cache' => variable_get('block_test_caching', DRUPAL_CACHE_PER_ROLE),
);
$blocks['test_html_id'] = array(
......
......@@ -2850,6 +2850,8 @@ function system_cron() {
function system_flush_caches() {
// Rebuild list of date formats.
system_date_formats_rebuild();
// Reset the menu static caches.
menu_reset_static_cache();
}
/**
......
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