=== modified file 'modules/block/block.install'
--- modules/block/block.install	2007-10-21 18:59:01 +0000
+++ modules/block/block.install	2007-11-04 14:56:04 +0000
@@ -91,7 +91,7 @@ function block_schema() {
       'cache' => array(
         'type' => 'int',
         'not null' => TRUE,
-        'default' => 0,
+        'default' => 1,
         '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.'),
       ),

=== modified file 'modules/block/block.module'
--- modules/block/block.module	2007-10-21 18:59:01 +0000
+++ modules/block/block.module	2007-11-04 15:03:14 +0000
@@ -224,60 +224,48 @@ function _block_rehash() {
   init_theme();
 
   $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key);
-  while ($old_block = db_fetch_object($result)) {
-    $old_blocks[$old_block->module][$old_block->delta] = $old_block;
+  $old_blocks = array();
+  while ($old_block = db_fetch_array($result)) {
+    $old_blocks[$old_block['module']][$old_block['delta']] = $old_block;
   }
 
   $blocks = array();
 
   foreach (module_list() as $module) {
-    $module_blocks = module_invoke($module, 'block', 'list');
+    $module_blocks = module_invoke($module, 'block', 'list', $theme_key);
     if ($module_blocks) {
       foreach ($module_blocks as $delta => $block) {
-        $block['module'] = $module;
-        $block['delta']  = $delta;
-        // If no cache pattern is specified, we use PER_ROLE as a default.
-        $block['cache'] = isset($block['cache']) ? $block['cache'] : BLOCK_CACHE_PER_ROLE;
-        // If previously written to database, load values.
-        if (!empty($old_blocks[$module][$delta])) {
-          $block['status'] = $old_blocks[$module][$delta]->status;
-          $block['weight'] = $old_blocks[$module][$delta]->weight;
-          $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;
+        if (empty($old_blocks[$module][$delta])) {
+          // If it's a new block, add identifiers.
+          $block['module'] = $module;
+          $block['delta']  = $delta;
+          $block['theme'] = $theme_key;
+          // Add defaults and save it into the database.
+          drupal_write_record('blocks', $block);
+          $blocks[] = $block;
         }
-        // Otherwise, use any set values, or else substitute defaults.
         else {
-          $properties = array('status' => 0, 'weight' => 0, 'region' => 'left', 'pages' => '', 'custom' => 0, 'title' => '');
-          foreach ($properties as $property => $default) {
-            if (!isset($block[$property])) {
-              $block[$property] = $default;
-            }
-          }
+          // 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.
+          // 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 all blocks from table.
-  db_query("DELETE FROM {blocks} WHERE theme = '%s'", $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']);
+  // 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'", $module, $delta);
+    }
   }
-  db_unlock_tables();
-
   return $blocks;
 }
 

=== modified file 'modules/system/system.install'
--- modules/system/system.install	2007-10-25 20:41:16 +0000
+++ modules/system/system.install	2007-11-04 14:58:06 +0000
@@ -4321,7 +4321,7 @@ function system_update_6027() {
   $ret = array();
 
   // 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
   // calls to cache_clear_all() would otherwise cause warnings.

