Commit bfd7c0f1 authored by Gábor Hojtsy's avatar Gábor Hojtsy

#80963 by chx with multiple contributors: remove deletion and database lock...

#80963 by chx with multiple contributors: remove deletion and database lock based block rehash code, replace it with simpler updates
parent e0c7c0e3
...@@ -91,7 +91,7 @@ function block_schema() { ...@@ -91,7 +91,7 @@ function block_schema() {
'cache' => array( 'cache' => array(
'type' => 'int', 'type' => 'int',
'not null' => TRUE, 'not null' => TRUE,
'default' => 0, 'default' => 1,
'size' => 'tiny', 'size' => 'tiny',
'description' => t('Binary flag to indicate block cache mode. (-1: Do not cache, 1: Cache per role, 2: Cache per user, 4: Cache per page, 8: Block cache global) See BLOCK_CACHE_* constants in block.module for more detailed information.'), 'description' => t('Binary flag to indicate block cache mode. (-1: Do not cache, 1: Cache per role, 2: Cache per user, 4: Cache per page, 8: Block cache global) See BLOCK_CACHE_* constants in block.module for more detailed information.'),
), ),
......
...@@ -224,8 +224,9 @@ function _block_rehash() { ...@@ -224,8 +224,9 @@ function _block_rehash() {
init_theme(); init_theme();
$result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key); $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key);
while ($old_block = db_fetch_object($result)) { $old_blocks = array();
$old_blocks[$old_block->module][$old_block->delta] = $old_block; while ($old_block = db_fetch_array($result)) {
$old_blocks[$old_block['module']][$old_block['delta']] = $old_block;
} }
$blocks = array(); $blocks = array();
...@@ -234,50 +235,37 @@ function _block_rehash() { ...@@ -234,50 +235,37 @@ function _block_rehash() {
$module_blocks = module_invoke($module, 'block', 'list'); $module_blocks = module_invoke($module, 'block', 'list');
if ($module_blocks) { if ($module_blocks) {
foreach ($module_blocks as $delta => $block) { foreach ($module_blocks as $delta => $block) {
$block['module'] = $module; if (empty($old_blocks[$module][$delta])) {
$block['delta'] = $delta; // If it's a new block, add identifiers.
// If no cache pattern is specified, we use PER_ROLE as a default. $block['module'] = $module;
$block['cache'] = isset($block['cache']) ? $block['cache'] : BLOCK_CACHE_PER_ROLE; $block['delta'] = $delta;
// If previously written to database, load values. $block['theme'] = $theme_key;
if (!empty($old_blocks[$module][$delta])) { // Add defaults and save it into the database.
$block['status'] = $old_blocks[$module][$delta]->status; drupal_write_record('blocks', $block);
$block['weight'] = $old_blocks[$module][$delta]->weight; $blocks[] = $block;
$block['region'] = $old_blocks[$module][$delta]->region;
$block['visibility'] = $old_blocks[$module][$delta]->visibility;
$block['pages'] = $old_blocks[$module][$delta]->pages;
$block['custom'] = $old_blocks[$module][$delta]->custom;
$block['throttle'] = $old_blocks[$module][$delta]->throttle;
$block['title'] = $old_blocks[$module][$delta]->title;
} }
// Otherwise, use any set values, or else substitute defaults.
else { else {
$properties = array('status' => 0, 'weight' => 0, 'region' => 'left', 'pages' => '', 'custom' => 0, 'title' => ''); // If it's an existing block, database settings should overwrite
foreach ($properties as $property => $default) { // the code. But aside from 'info' everything that's definable in
if (!isset($block[$property])) { // code is stored in the database and we do not store 'info', so we
$block[$property] = $default; // do not need to update the database here.
} // Add 'info' to this block.
} $old_blocks[$module][$delta]['info'] = $block['info'];
// Add this block to the list of blocks we return
$blocks[] = $old_blocks[$module][$delta];
// Remove this block from the list of blocks to be deleted.
unset($old_blocks[$module][$delta]);
} }
$blocks[] = $block;
} }
} }
} }
db_lock_table('blocks'); // Remove blocks that are no longer defined by the code from the database.
// Remove all blocks from table. foreach ($old_blocks as $module => $old_module_blocks) {
db_query("DELETE FROM {blocks} WHERE theme = '%s'", $theme_key); 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);
// Reinsert new set of blocks into table. }
foreach ($blocks as $block) {
$block += array(
'visibility' => NULL,
'throttle' => NULL,
);
db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle, title, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d, '%s', %d)", $block['module'], $block['delta'], $theme_key, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['title'], $block['cache']);
} }
db_unlock_tables();
return $blocks; return $blocks;
} }
......
...@@ -4304,7 +4304,7 @@ function system_update_6027() { ...@@ -4304,7 +4304,7 @@ function system_update_6027() {
$ret = array(); $ret = array();
// Create the blocks.cache column. // Create the blocks.cache column.
db_add_field($ret, 'blocks', 'cache', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny')); db_add_field($ret, 'blocks', 'cache', array('type' => 'int', 'not null' => TRUE, 'default' => 1, 'size' => 'tiny'));
// The cache_block table is created in update_fix_d6_requirements() since // The cache_block table is created in update_fix_d6_requirements() since
// calls to cache_clear_all() would otherwise cause warnings. // calls to cache_clear_all() would otherwise cause warnings.
......
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