Index: includes/update.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/update.inc,v
retrieving revision 1.13
diff -u -F^f -u -F^f -r1.13 update.inc
--- includes/update.inc	13 Oct 2009 05:26:57 -0000	1.13
+++ includes/update.inc	17 Oct 2009 12:11:22 -0000
@@ -104,6 +104,94 @@ function update_prepare_d7_bootstrap() {
 }
 
 /**
+ * A helper function that modules can use to assist with the transformation
+ * from numeric block deltas to string block deltas during the 6.x -> 7.x
+ * upgrade.  This function should be removed in 8.x.
+ *
+ * @param $sandbox
+ *   An array holding data for the batch process.
+ * @param $renamed_deltas
+ *   An associative array.  Keys are module names, values an associative array
+ *   mapping the old block deltas to the new block deltas for the module.
+ *   Example:
+ *     $renamed_deltas = array(
+ *       'mymodule' =>
+ *         array(
+ *           0 => 'mymodule-block-1',
+ *           1 => 'mymodule-block-2',
+ *         );
+ *     );
+ */
+function update_fix_block_deltas(&$sandbox, $renamed_deltas) {
+  // Loop through each block and make changes to the block tables.
+  // Only run this the first time through the batch update.
+  if (!isset($sandbox['progress'])) {
+    $block_tables = array('blocks', 'blocks_roles');
+    foreach ($block_tables as $table) {
+      foreach ($renamed_deltas as $module => $deltas) {
+        foreach ($deltas as $old_delta => $new_delta) {
+          // Only do the update if the old block actually exists.
+          $block_exists = db_query("SELECT COUNT(*) FROM {" . $table . "} WHERE module = :module AND delta = :delta", array(
+            ':module' => $module,
+            ':delta' => $old_delta,
+          ))
+          ->fetchField();
+          if ($block_exists) {
+          	db_update($table)
+          	  ->fields(array('delta' => $new_delta))
+          	  ->condition('module', $module)
+          	  ->condition('delta', $old_delta)
+          	  ->execute();
+          }
+        }
+      }
+    }
+
+    // Initialize batch update information.
+    $sandbox['progress'] = 0;
+    $sandbox['last_user_processed'] = -1;
+    $sandbox['max'] = db_query("SELECT COUNT(*) FROM {users} WHERE data IS NOT NULL")->fetchField();
+  }
+  // Now do the batch update of the user-specific block visibility settings.
+  $limit = 100;
+  $result = db_select('users', 'u')
+    ->fields('u', array('uid', 'data'))
+    ->condition('uid', $sandbox['last_user_processed'], '>')
+    ->where('data IS NOT NULL')
+    ->range(0, $limit)
+    ->execute();
+  foreach ($result as $row) {
+    $data = unserialize($row->data);
+    $user_needs_update = FALSE;
+    foreach ($renamed_deltas as $module => $deltas) {
+      foreach ($deltas as $old_delta => $new_delta) {
+        if (isset($data['block'][$module][$old_delta])) {
+          // Transfer the old block visibility settings to the newly-renamed
+          // block, and mark this user for a database update.
+          $data['block'][$module][$new_delta] = $data['block'][$module][$old_delta];
+          unset($data['block'][$module][$old_delta]);
+          $user_needs_update = TRUE;
+        }
+      }
+    }
+    // Update the current user.
+    if ($user_needs_update) {
+      db_update('users')
+        ->fields(array('data' => serialize($data)))
+        ->condition('uid', $row->uid)
+        ->execute();
+    }
+    // Update our progress information for the batch update.
+    $sandbox['progress']++;
+    $sandbox['last_user_processed'] = $row->uid;
+  }
+  // Indicate our current progress to the batch update system.
+  if ($sandbox['progress'] < $sandbox['max']) {
+    $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
+  }
+}
+
+/**
  * Perform Drupal 6.x to 7.x updates that are required for update.php
  * to function properly.
  *
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.403
diff -u -F^f -u -F^f -r1.403 system.install
--- modules/system/system.install	16 Oct 2009 23:48:38 -0000	1.403
+++ modules/system/system.install	17 Oct 2009 12:11:25 -0000
@@ -1765,29 +1765,9 @@ function system_update_7004(&$sandbox) {
       '3' => 'online',
     ),
   );
-  // Loop through each block and make changes to the core block tables.
+
   // Only run this the first time through the batch update.
   if (!isset($sandbox['progress'])) {
-    $block_tables = array('blocks', 'blocks_roles');
-    foreach ($block_tables as $table) {
-      foreach ($renamed_deltas as $module => $deltas) {
-        foreach ($deltas as $old_delta => $new_delta) {
-          // Only do the update if the old block actually exists.
-          $block_exists = db_query("SELECT COUNT(*) FROM {" . $table . "} WHERE module = :module AND delta = :delta", array(
-            ':module' => $module,
-            ':delta' => $old_delta,
-          ))
-          ->fetchField();
-          if ($block_exists) {
-          	db_update($table)
-          	  ->fields(array('delta' => $new_delta))
-          	  ->condition('module', $module)
-          	  ->condition('delta', $old_delta)
-          	  ->execute();
-          }
-        }
-      }
-    }
     // Rename forum module's block variables.
     $forum_block_num_0 = variable_get('forum_block_num_0');
     if (isset($forum_block_num_0)) {
@@ -1799,48 +1779,10 @@ function system_update_7004(&$sandbox) {
       variable_set('forum_block_num_new', $forum_block_num_1);
       variable_del('forum_block_num_1');
     }
-    // Initialize batch update information.
-    $sandbox['progress'] = 0;
-    $sandbox['last_user_processed'] = -1;
-    $sandbox['max'] = db_query("SELECT COUNT(*) FROM {users} WHERE data IS NOT NULL")->fetchField();
-  }
-  // Now do the batch update of the user-specific block visibility settings.
-  $limit = 100;
-  $result = db_select('users', 'u')
-    ->fields('u', array('uid', 'data'))
-    ->condition('uid', $sandbox['last_user_processed'], '>')
-    ->where('data IS NOT NULL')
-    ->range(0, $limit)
-    ->execute();
-  foreach ($result as $row) {
-    $data = unserialize($row->data);
-    $user_needs_update = FALSE;
-    foreach ($renamed_deltas as $module => $deltas) {
-      foreach ($deltas as $old_delta => $new_delta) {
-        if (isset($data['block'][$module][$old_delta])) {
-          // Transfer the old block visibility settings to the newly-renamed
-          // block, and mark this user for a database update.
-          $data['block'][$module][$new_delta] = $data['block'][$module][$old_delta];
-          unset($data['block'][$module][$old_delta]);
-          $user_needs_update = TRUE;
-        }
-      }
-    }
-    // Update the current user.
-    if ($user_needs_update) {
-      db_update('users')
-        ->fields(array('data' => serialize($data)))
-        ->condition('uid', $row->uid)
-        ->execute();
-    }
-    // Update our progress information for the batch update.
-    $sandbox['progress']++;
-    $sandbox['last_user_processed'] = $row->uid;
-  }
-  // Indicate our current progress to the batch update system.
-  if ($sandbox['progress'] < $sandbox['max']) {
-    $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
   }
+
+  update_fix_block_deltas($sandbox, $renamed_deltas);
+
 }
 
 /**
