diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-06-15 16:19:28 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-06-15 16:19:28 +0000 |
commit | a3b28597bbae14920b7eef9090279e9cf20a040e (patch) | |
tree | c8cf9ac319730d0c34547a9bf5bb5ae5854826cc /modules/block | |
parent | 5f5c024b6d4730f1b052de2714a02839c251bd1a (diff) | |
download | brdo-a3b28597bbae14920b7eef9090279e9cf20a040e.tar.gz brdo-a3b28597bbae14920b7eef9090279e9cf20a040e.tar.bz2 |
- Patch #235673 by carlos8f, yched, swentel, redndahead, Damien Tournoud, pwolanin, dww: changes to block caching mode not caught.
Diffstat (limited to 'modules/block')
-rw-r--r-- | modules/block/block.module | 17 | ||||
-rw-r--r-- | modules/block/block.test | 23 | ||||
-rw-r--r-- | modules/block/tests/block_test.module | 1 |
3 files changed, 39 insertions, 2 deletions
diff --git a/modules/block/block.module b/modules/block/block.module index 402f43a9e..05c9d4efc 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -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'); } diff --git a/modules/block/block.test b/modules/block/block.test index 0f9eaafe4..9810db9f2 100644 --- a/modules/block/block.test +++ b/modules/block/block.test @@ -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 { diff --git a/modules/block/tests/block_test.module b/modules/block/tests/block_test.module index 46c1aa755..57b5ad37b 100644 --- a/modules/block/tests/block_test.module +++ b/modules/block/tests/block_test.module @@ -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( |