=== modified file 'modules/book/book.install'
--- modules/book/book.install	2007-10-25 15:32:55 +0000
+++ modules/book/book.install	2007-11-23 12:38:17 +0000
@@ -44,207 +44,6 @@ function _book_install_type_create() {
 }
 
 /**
- * Drupal 5.x to 6.x update.
- *
- * This function moves any existing book hierarchy into the new structure used
- * in the 6.x module.  Rather than storing the hierarchy in the {book} table,
- * the menu API is used to store the hierarchy in the {menu_links} table and the
- * {book} table serves to uniquely connect a node to a menu link.
- *
- * In order to accomplish this, the current hierarchy is processed using a stack.
- * The stack insures that each parent is processed before any of its children
- * in the book hierarchy, and is compatible with batched update processing.
- *
- */
-function book_update_6000() {
-  $ret = array();
-
-  // Set up for a multi-part update.
-  if (!isset($_SESSION['book_update_6000'])) {
-
-    $schema['book'] = array(
-      'fields' => array(
-        'mlid'    => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-        'nid'     => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-        'bid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-      ),
-      'indexes' => array(
-        'nid'     => array('nid'),
-        'bid' => array('bid')
-      ),
-      'primary key' => array('mlid'),
-    );
-    // Add the node type.
-    _book_install_type_create();
-
-    // Fix role permissions to account for the changed names
-    // Setup the array holding strings to match and the corresponding
-    // strings to replace them with.
-    $replace = array(
-      'outline posts in books' => 'administer book outlines',
-      'create book pages' => 'create book content',
-      'edit book pages' => 'edit book content',
-      'edit own book pages' => 'edit own book content',
-      'see printer-friendly version' => 'access printer-friendly version',
-    );
-
-    // Loop over all the roles, and do the necessary transformations.
-    $query = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
-    while ($role = db_fetch_object($query)) {
-      // Replace all the old permissions with the corresponding new permissions.
-      $fixed_perm = strtr($role->perm, $replace);
-      // If the user could previously create book pages, they should get the new
-      // 'add content to books' permission.
-      if (strpos($role->perm, 'create book pages') !== FALSE) {
-        $fixed_perm .= ', add content to books';
-      }
-      // Only save if the permissions have changed.
-      if ($fixed_perm != $role->perm) {
-        $ret[] = update_sql("UPDATE {permission} SET perm = '$fixed_perm' WHERE rid = $role->rid");
-      }
-    }
-
-    // Determine whether there are any existing nodes in the book hierarchy.
-    if (db_result(db_query("SELECT COUNT(*) FROM {book}"))) {
-      // Temporary table for the old book hierarchy; we'll discard revision info.
-      $schema['book_temp'] = array(
-        'fields' => array(
-          'nid'    => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-          'parent' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-          'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny')
-        ),
-        'indexes' => array(
-          'parent' => array('parent')
-        ),
-        'primary key' => array('nid'),
-      );
-
-      db_create_table($ret, 'book_temp', $schema['book_temp']);
-
-      // Insert each node in the old table into the temporary table.
-      $ret[] = update_sql("INSERT INTO {book_temp} (nid, parent, weight) SELECT b.nid, b.parent, b.weight FROM {book} b INNER JOIN {node} n on b.vid = n.vid");
-      $ret[] = update_sql("DROP TABLE {book}");
-
-      db_create_table($ret, 'book', $schema['book']);
-
-      $_SESSION['book_update_6000_orphans']['from'] = 0;
-      $_SESSION['book_update_6000'] = array();
-      $result = db_query("SELECT * from {book_temp} WHERE parent = 0");
-
-      // Collect all books - top-level nodes.
-      while ($a = db_fetch_array($result)) {
-        $_SESSION['book_update_6000'][] = $a;
-      }
-      $ret['#finished'] = FALSE;
-      return $ret;
-    }
-    else {
-      // No exising nodes in the hierarchy, so drop the table and re-create it.
-      $ret[] = update_sql("DROP TABLE {book}");
-      db_create_table($ret, 'book', $schema['book']);
-      return $ret;
-    }
-  }
-  elseif ($_SESSION['book_update_6000_orphans']) {
-    // Do the first batched part of the update - collect orphans.
-    $update_count = 400; // Update this many at a time
-
-    $result = db_query_range("SELECT * FROM {book_temp}", $_SESSION['book_update_6000_orphans']['from'], $update_count);
-    $has_rows = FALSE;
-    // Go through the next $update_count book pages and locate the orphans.
-    while ($book = db_fetch_array($result)) {
-      $has_rows = TRUE;
-      // Orphans are defined as nodes whose parent does not exist in the table.
-      if ($book['parent'] && !db_result(db_query("SELECT COUNT(*) FROM {book_temp} WHERE nid = %d", $book['parent']))) {
-        if (empty($_SESSION['book_update_6000_orphans']['book'])) {
-          // The first orphan becomes the parent for all other orphans.
-          $book['parent'] = 0;
-          $_SESSION['book_update_6000_orphans']['book'] = $book;
-          $ret[] = array('success' => TRUE, 'query' => t('Relocated orphan book pages.'));
-        }
-        else {
-          // Re-assign the parent value of the book, and add it to the stack.
-          $book['parent'] = $_SESSION['book_update_6000_orphans']['book']['nid'];
-          $_SESSION['book_update_6000'][] = $book;
-        }
-      }
-    }
-    if ($has_rows) {
-      $_SESSION['book_update_6000_orphans']['from'] += $update_count;
-    }
-    else {
-      // Done with this part
-      if (!empty($_SESSION['book_update_6000_orphans']['book'])) {
-        // The orphans' parent is added last, so it will be processed first.
-        $_SESSION['book_update_6000'][] = $_SESSION['book_update_6000_orphans']['book'];
-      }
-      $_SESSION['book_update_6000_orphans'] = FALSE;
-    }
-    $ret['#finished'] = FALSE;
-    return $ret;
-  }
-  else {
-    // Do the next batched part of the update
-    $update_count = 100; // Update this many at a time
-
-    while ($update_count && $_SESSION['book_update_6000']) {
-      // Get the last node off the stack.
-      $book = array_pop($_SESSION['book_update_6000']);
-
-      // Add all of this node's children to the stack
-      $result = db_query("SELECT * FROM {book_temp} WHERE parent = %d", $book['nid']);
-      while ($a = db_fetch_array($result)) {
-        $_SESSION['book_update_6000'][] = $a;
-      }
-
-      if ($book['parent']) {
-        // If its not a top level page, get its parent's mlid.
-        $parent = db_fetch_array(db_query("SELECT b.mlid AS plid, b.bid FROM {book} b WHERE b.nid = %d", $book['parent']));
-        $book = array_merge($book, $parent);
-      }
-      else {
-        // There is not a parent - this is a new book.
-        $book['plid'] = 0;
-        $book['bid'] = $book['nid'];
-      }
-
-      $book += array(
-        'module' => 'book',
-        'link_path' => 'node/'. $book['nid'],
-        'router_path' => 'node/%',
-        'menu_name' => book_menu_name($book['bid']),
-      );
-      $book = array_merge($book, db_fetch_array(db_query("SELECT title AS link_title FROM {node} WHERE nid = %d", $book['nid'])));
-
-      // Items with depth > MENU_MAX_DEPTH cannot be saved.
-      if (menu_link_save($book)) {
-        db_query("INSERT INTO {book} (mlid, nid, bid) VALUES (%d, %d, %d)", $book['mlid'], $book['nid'], $book['bid']);
-      }
-      else {
-        // The depth was greater then MENU_MAX_DEPTH, so attach it to the
-        // closest valid parent.
-        $book['plid'] = db_result(db_query("SELECT plid FROM {menu_links} WHERE mlid = %d", $book['plid']));
-        if (menu_link_save($book)) {
-          db_query("INSERT INTO {book} (mlid, nid, bid) VALUES (%d, %d, %d)", $book['mlid'], $book['nid'], $book['bid']);
-        }
-      }
-      $update_count--;
-    }
-    $ret['#finished'] = FALSE;
-  }
-
-  if (empty($_SESSION['book_update_6000'])) {
-    $ret['#finished'] = TRUE;
-    $ret[] = array('success' => TRUE, 'query' => t('Relocated existing book pages.'));
-    $ret[] = update_sql("DROP TABLE {book_temp}");
-    unset($_SESSION['book_update_6000']);
-    unset($_SESSION['book_update_6000_orphans']);
-  }
-
-  return $ret;
-}
-
-/**
  * Implementation of hook_schema().
  */
 function book_schema() {

=== modified file 'modules/comment/comment.install'
--- modules/comment/comment.install	2007-11-07 15:54:49 +0000
+++ modules/comment/comment.install	2007-11-23 12:35:42 +0000
@@ -10,53 +10,6 @@ function comment_enable() {
 }
 
 /**
- * Changed node_comment_statistics to use node->changed to avoid future
- * timestamps.
- */
-function comment_update_1() {
-  // Change any future last comment timestamps to now.
-  db_query('UPDATE {node_comment_statistics} SET last_comment_timestamp = %d WHERE last_comment_timestamp > %d', time(), time());
-
-  // Unstuck node indexing timestamp if needed.
-  if (($last = variable_get('node_cron_last', FALSE)) !== FALSE) {
-    variable_set('node_cron_last', min(time(), $last));
-  }
-  return array();
-}
-
-function comment_update_6001() {
-  $ret[] = update_sql("ALTER TABLE {comments} DROP score");
-  $ret[] = update_sql("ALTER TABLE {comments} DROP users");
-  return $ret;
-}
-
-/**
- * Changed comment settings from global to per-node -- copy global
- * settings to all node types.
- */
-function comment_update_6002() {
-  $settings = array(
-    'comment_default_mode' => COMMENT_MODE_THREADED_EXPANDED,
-    'comment_default_order' => COMMENT_ORDER_NEWEST_FIRST,
-    'comment_default_per_page' => 50,
-    'comment_controls' => COMMENT_CONTROLS_HIDDEN,
-    'comment_anonymous' => COMMENT_ANONYMOUS_MAYNOT_CONTACT,
-    'comment_subject_field' => 1,
-    'comment_preview' => COMMENT_PREVIEW_REQUIRED,
-    'comment_form_location' => COMMENT_FORM_SEPARATE_PAGE,
-  );
-  $types = node_get_types();
-  foreach ($settings as $setting => $default) {
-    $value = variable_get($setting, $default);
-    foreach ($types as $type => $object) {
-      variable_set($setting .'_'. $type, $value);
-    }
-    variable_del($setting);
-  }
-  return array();
-}
-
-/**
  * Implementation of hook_schema().
  */
 function comment_schema() {

=== modified file 'modules/locale/locale.install'
--- modules/locale/locale.install	2007-11-15 13:27:45 +0000
+++ modules/locale/locale.install	2007-11-23 12:44:55 +0000
@@ -21,117 +21,6 @@ function locale_install() {
  */
 
 /**
- * {locales_meta} table became {languages}.
- */
-function locale_update_6001() {
-  $ret = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("CREATE TABLE {languages} (
-        language varchar(12) NOT NULL default '',
-        name varchar(64) NOT NULL default '',
-        native varchar(64) NOT NULL default '',
-        direction int NOT NULL default '0',
-        enabled int NOT NULL default '0',
-        plurals int NOT NULL default '0',
-        formula varchar(128) NOT NULL default '',
-        domain varchar(128) NOT NULL default '',
-        prefix varchar(128) NOT NULL default '',
-        weight int NOT NULL default '0',
-        PRIMARY KEY (language)
-      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
-      break;
-    case 'pgsql':
-      $ret[] = update_sql("CREATE TABLE {languages} (
-        language varchar(12) NOT NULL default '',
-        name varchar(64) NOT NULL default '',
-        native varchar(64) NOT NULL default '',
-        direction int NOT NULL default '0',
-        enabled int NOT NULL default '0',
-        plurals int NOT NULL default '0',
-        formula varchar(128) NOT NULL default '',
-        domain varchar(128) NOT NULL default '',
-        prefix varchar(128) NOT NULL default '',
-        weight int NOT NULL default '0',
-        PRIMARY KEY (language)
-      )");
-      break;
-  }
-
-  // Save the languages
-  $ret[] = update_sql("INSERT INTO {languages} (language, name, native, direction, enabled, plurals, formula, domain, prefix, weight) SELECT locale, name, '', 0, enabled, plurals, formula, '', locale, 0 FROM {locales_meta}");
-
-  // Save the language count in the variable table
-  $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1'));
-  variable_set('language_count', $count);
-
-  // Save the default language in the variable table
-  $default = db_fetch_object(db_query('SELECT * FROM {locales_meta} WHERE isdefault = 1'));
-  variable_set('language_default', (object) array('language' => $default->locale, 'name' => $default->name, 'native' => '', 'direction' => 0, 'enabled' => 1, 'plurals' => $default->plurals, 'formula' => $default->formula, 'domain' => '', 'prefix' => $default->locale, 'weight' => 0));
-
-  $ret[] = update_sql("DROP TABLE {locales_meta}");
-  return $ret;
-}
-
-/**
- * Change locale column to language. The language column is added by
- * update_fix_d6_requirements() in update.php to avoid a large number
- * of error messages from update.php.  All we need to do here is copy
- * locale to language and then drop locale.
- */
-function locale_update_6002() {
-  $ret = array();
-  $ret[] = update_sql('UPDATE {locales_target} SET language = locale');
-  db_drop_field($ret, 'locales_target', 'locale');
-  return $ret;
-}
-
-/**
- * Adds a column to store the filename of the JavaScript translation file.
- */
-function locale_update_6003() {
-  $ret = array();
-  db_add_field($ret, 'languages', 'javascript', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''));
-  return $ret;
-}
-
-/**
- * Remove empty translations, we don't need these anymore.
- */
-function locale_update_6004() {
-  $ret = array();
-  $ret[] = update_sql("DELETE FROM {locales_target} WHERE translation = ''");
-  return $ret;
-}
-
-/**
- * Prune strings with no translations (will be automatically re-registered if still in use)
- */
-function locale_update_6005() {
-  $ret = array();
-  $ret[] = update_sql("DELETE FROM {locales_source} WHERE lid NOT IN (SELECT lid FROM {locales_target})");
-  return $ret;
-}
-
-/**
- * Fix remaining inconsistent indexes.
- */
-function locale_update_6006() {
-  $ret = array();
-  db_add_index($ret, 'locales_target', 'language', array('language'));
-
-  switch ($GLOBALS['db_type']) {
-    case 'pgsql':
-      db_drop_index($ret, 'locales_source', 'source');
-      db_add_index($ret, 'locales_source', 'source', array(array('source', 30)));
-      break;
-  }
-
-  return $ret;
-}
-
-/**
  * @} End of "defgroup updates-5.x-to-6.x"
  */
 

=== modified file 'modules/system/system.install'
--- modules/system/system.install	2007-11-20 14:48:07 +0000
+++ modules/system/system.install	2007-11-23 12:48:20 +0000
@@ -305,9 +305,11 @@ function system_install() {
   // anyways. So we insert the superuser here, the uid is 2 here for now, but
   // very soon it will be changed to 1.
   db_query("INSERT INTO {users} (name, mail, created, data) VALUES('%s', '%s', %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', time(), serialize(array()));
-  // This sets the above two users to 1 -1 = 0 (anonymous) and
-  // 2- 1 = 1 (superuser). We skip uid 2 but that's not a big problem.
-  db_query('UPDATE {users} SET uid = uid - 1');
+  // This sets the above nameless user to uid 0 (anonymous). We avoid an
+  // explicit 0, otherwise MySQL might insert the next auto_increment value.
+  db_query("UPDATE {users} SET uid = uid - uid WHERE name = '%s'", '');
+  // This sets uid 1 (superuser). We skip uid 2 but that's not a big problem.
+  db_query("UPDATE {users} SET uid = 1 WHERE name = '%s'", 'placeholder-for-uid-1');
 
   db_query("INSERT INTO {role} (name) VALUES ('%s')", 'anonymous user');
   db_query("INSERT INTO {role} (name) VALUES ('%s')", 'authenticated user');
@@ -2701,6 +2703,389 @@ function system_update_6037() {
 }
 
 /**
+ * Changed node_comment_statistics to use node->changed to avoid future
+ * timestamps.
+ */
+function system_update_6038() {
+  if (db_table_exists('node_comment_statistics')) {
+    // Change any future last comment timestamps to now.
+    db_query('UPDATE {node_comment_statistics} SET last_comment_timestamp = %d WHERE last_comment_timestamp > %d', time(), time());
+  }
+
+  // Unstuck node indexing timestamp if needed.
+  if (($last = variable_get('node_cron_last', FALSE)) !== FALSE) {
+    variable_set('node_cron_last', min(time(), $last));
+  }
+  return array();
+}
+
+function system_update_6039() {
+  $ret = array();
+  if (db_table_exists('comments')) {
+    $ret[] = update_sql("ALTER TABLE {comments} DROP score");
+    $ret[] = update_sql("ALTER TABLE {comments} DROP users");
+  }
+  return $ret;
+}
+
+/**
+ * Changed comment settings from global to per-node -- copy global
+ * settings to all node types.
+ */
+function system_update_6040() {
+  $settings = array(
+    'comment_default_mode' => COMMENT_MODE_THREADED_EXPANDED,
+    'comment_default_order' => COMMENT_ORDER_NEWEST_FIRST,
+    'comment_default_per_page' => 50,
+    'comment_controls' => COMMENT_CONTROLS_HIDDEN,
+    'comment_anonymous' => COMMENT_ANONYMOUS_MAYNOT_CONTACT,
+    'comment_subject_field' => 1,
+    'comment_preview' => COMMENT_PREVIEW_REQUIRED,
+    'comment_form_location' => COMMENT_FORM_SEPARATE_PAGE,
+  );
+  $types = node_get_types();
+  foreach ($settings as $setting => $default) {
+    $value = variable_get($setting, $default);
+    foreach ($types as $type => $object) {
+      variable_set($setting .'_'. $type, $value);
+    }
+    variable_del($setting);
+  }
+  return array();
+}
+
+/**
+ * Drupal 5.x to 6.x book update.
+ *
+ * This function moves any existing book hierarchy into the new structure used
+ * in the 6.x module.  Rather than storing the hierarchy in the {book} table,
+ * the menu API is used to store the hierarchy in the {menu_links} table and the
+ * {book} table serves to uniquely connect a node to a menu link.
+ *
+ * In order to accomplish this, the current hierarchy is processed using a stack.
+ * The stack insures that each parent is processed before any of its children
+ * in the book hierarchy, and is compatible with batched update processing.
+ *
+ */
+function system_update_6041() {
+  $ret = array();
+
+  // Even if the book table does not exist we fix up permissions just to be
+  // sure.
+  if (!db_table_exists('book')) {
+    // Fix role permissions to account for the changed names
+    // Setup the array holding strings to match and the corresponding
+    // strings to replace them with.
+    $replace = array(
+      'outline posts in books' => 'administer book outlines',
+      'create book pages' => 'create book content',
+      'edit book pages' => 'edit book content',
+      'edit own book pages' => 'edit own book content',
+      'see printer-friendly version' => 'access printer-friendly version',
+    );
+
+    // Loop over all the roles, and do the necessary transformations.
+    $query = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
+    while ($role = db_fetch_object($query)) {
+      // Replace all the old permissions with the corresponding new permissions.
+      $fixed_perm = strtr($role->perm, $replace);
+      // If the user could previously create book pages, they should get the new
+      // 'add content to books' permission.
+      if (strpos($role->perm, 'create book pages') !== FALSE) {
+        $fixed_perm .= ', add content to books';
+      }
+      // Only save if the permissions have changed.
+      if ($fixed_perm != $role->perm) {
+        $ret[] = update_sql("UPDATE {permission} SET perm = '$fixed_perm' WHERE rid = $role->rid");
+      }
+    }
+    return $ret;
+  }
+  // Set up for a multi-part update.
+  if (!isset($_SESSION['system_update_6041'])) {
+
+    $schema['book'] = array(
+      'fields' => array(
+        'mlid'    => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+        'nid'     => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+        'bid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+      ),
+      'indexes' => array(
+        'nid'     => array('nid'),
+        'bid' => array('bid')
+      ),
+      'primary key' => array('mlid'),
+    );
+    // Add the node type.
+    _book_install_type_create();
+
+    // Determine whether there are any existing nodes in the book hierarchy.
+    if (db_result(db_query("SELECT COUNT(*) FROM {book}"))) {
+      // Temporary table for the old book hierarchy; we'll discard revision info.
+      $schema['book_temp'] = array(
+        'fields' => array(
+          'nid'    => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+          'parent' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+          'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny')
+        ),
+        'indexes' => array(
+          'parent' => array('parent')
+        ),
+        'primary key' => array('nid'),
+      );
+
+      db_create_table($ret, 'book_temp', $schema['book_temp']);
+
+      // Insert each node in the old table into the temporary table.
+      $ret[] = update_sql("INSERT INTO {book_temp} (nid, parent, weight) SELECT b.nid, b.parent, b.weight FROM {book} b INNER JOIN {node} n on b.vid = n.vid");
+      $ret[] = update_sql("DROP TABLE {book}");
+
+      db_create_table($ret, 'book', $schema['book']);
+
+      $_SESSION['system_update_6041_orphans']['from'] = 0;
+      $_SESSION['system_update_6041'] = array();
+      $result = db_query("SELECT * from {book_temp} WHERE parent = 0");
+
+      // Collect all books - top-level nodes.
+      while ($a = db_fetch_array($result)) {
+        $_SESSION['system_update_6041'][] = $a;
+      }
+      $ret['#finished'] = FALSE;
+      return $ret;
+    }
+    else {
+      // No exising nodes in the hierarchy, so drop the table and re-create it.
+      $ret[] = update_sql("DROP TABLE {book}");
+      db_create_table($ret, 'book', $schema['book']);
+      return $ret;
+    }
+  }
+  elseif (!empty($_SESSION['system_update_6041_orphans'])) {
+    // Do the first batched part of the update - collect orphans.
+    $update_count = 400; // Update this many at a time
+
+    $result = db_query_range("SELECT * FROM {book_temp}", $_SESSION['system_update_6041_orphans']['from'], $update_count);
+    $has_rows = FALSE;
+    // Go through the next $update_count book pages and locate the orphans.
+    while ($book = db_fetch_array($result)) {
+      $has_rows = TRUE;
+      // Orphans are defined as nodes whose parent does not exist in the table.
+      if ($book['parent'] && !db_result(db_query("SELECT COUNT(*) FROM {book_temp} WHERE nid = %d", $book['parent']))) {
+        if (empty($_SESSION['system_update_6041_orphans']['book'])) {
+          // The first orphan becomes the parent for all other orphans.
+          $book['parent'] = 0;
+          $_SESSION['system_update_6041_orphans']['book'] = $book;
+          $ret[] = array('success' => TRUE, 'query' => t('Relocated orphan book pages.'));
+        }
+        else {
+          // Re-assign the parent value of the book, and add it to the stack.
+          $book['parent'] = $_SESSION['system_update_6041_orphans']['book']['nid'];
+          $_SESSION['system_update_6041'][] = $book;
+        }
+      }
+    }
+    if ($has_rows) {
+      $_SESSION['system_update_6041_orphans']['from'] += $update_count;
+    }
+    else {
+      // Done with this part
+      if (!empty($_SESSION['system_update_6041_orphans']['book'])) {
+        // The orphans' parent is added last, so it will be processed first.
+        $_SESSION['system_update_6041'][] = $_SESSION['system_update_6041_orphans']['book'];
+      }
+      $_SESSION['system_update_6041_orphans'] = FALSE;
+    }
+    $ret['#finished'] = FALSE;
+    return $ret;
+  }
+  elseif (!empty($_SESSION['system_update_6041'])) {
+    // Do the next batched part of the update
+    $update_count = 100; // Update this many at a time
+
+    while ($update_count && $_SESSION['system_update_6041']) {
+      // Get the last node off the stack.
+      $book = array_pop($_SESSION['system_update_6041']);
+
+      // Add all of this node's children to the stack
+      $result = db_query("SELECT * FROM {book_temp} WHERE parent = %d", $book['nid']);
+      while ($a = db_fetch_array($result)) {
+        $_SESSION['system_update_6041'][] = $a;
+      }
+
+      if ($book['parent']) {
+        // If its not a top level page, get its parent's mlid.
+        $parent = db_fetch_array(db_query("SELECT b.mlid AS plid, b.bid FROM {book} b WHERE b.nid = %d", $book['parent']));
+        $book = array_merge($book, $parent);
+      }
+      else {
+        // There is not a parent - this is a new book.
+        $book['plid'] = 0;
+        $book['bid'] = $book['nid'];
+      }
+
+      $book += array(
+        'module' => 'book',
+        'link_path' => 'node/'. $book['nid'],
+        'router_path' => 'node/%',
+        'menu_name' => book_menu_name($book['bid']),
+      );
+      $book = array_merge($book, db_fetch_array(db_query("SELECT title AS link_title FROM {node} WHERE nid = %d", $book['nid'])));
+
+      // Items with depth > MENU_MAX_DEPTH cannot be saved.
+      if (menu_link_save($book)) {
+        db_query("INSERT INTO {book} (mlid, nid, bid) VALUES (%d, %d, %d)", $book['mlid'], $book['nid'], $book['bid']);
+      }
+      else {
+        // The depth was greater then MENU_MAX_DEPTH, so attach it to the
+        // closest valid parent.
+        $book['plid'] = db_result(db_query("SELECT plid FROM {menu_links} WHERE mlid = %d", $book['plid']));
+        if (menu_link_save($book)) {
+          db_query("INSERT INTO {book} (mlid, nid, bid) VALUES (%d, %d, %d)", $book['mlid'], $book['nid'], $book['bid']);
+        }
+      }
+      $update_count--;
+    }
+    $ret['#finished'] = FALSE;
+  }
+
+  if (empty($_SESSION['system_update_6041'])) {
+    $ret['#finished'] = TRUE;
+    $ret[] = array('success' => TRUE, 'query' => t('Relocated existing book pages.'));
+    $ret[] = update_sql("DROP TABLE {book_temp}");
+    unset($_SESSION['system_update_6041']);
+    unset($_SESSION['system_update_6041_orphans']);
+  }
+
+  return $ret;
+}
+
+/**
+ * {locales_meta} table became {languages}.
+ */
+function system_update_6042() {
+  $ret = array();
+  if (!db_table_exists('locales_meta')) {
+    return $ret;
+  }
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("CREATE TABLE {languages} (
+        language varchar(12) NOT NULL default '',
+        name varchar(64) NOT NULL default '',
+        native varchar(64) NOT NULL default '',
+        direction int NOT NULL default '0',
+        enabled int NOT NULL default '0',
+        plurals int NOT NULL default '0',
+        formula varchar(128) NOT NULL default '',
+        domain varchar(128) NOT NULL default '',
+        prefix varchar(128) NOT NULL default '',
+        weight int NOT NULL default '0',
+        PRIMARY KEY (language)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("CREATE TABLE {languages} (
+        language varchar(12) NOT NULL default '',
+        name varchar(64) NOT NULL default '',
+        native varchar(64) NOT NULL default '',
+        direction int NOT NULL default '0',
+        enabled int NOT NULL default '0',
+        plurals int NOT NULL default '0',
+        formula varchar(128) NOT NULL default '',
+        domain varchar(128) NOT NULL default '',
+        prefix varchar(128) NOT NULL default '',
+        weight int NOT NULL default '0',
+        PRIMARY KEY (language)
+      )");
+      break;
+  }
+
+  // Save the languages
+  $ret[] = update_sql("INSERT INTO {languages} (language, name, native, direction, enabled, plurals, formula, domain, prefix, weight) SELECT locale, name, '', 0, enabled, plurals, formula, '', locale, 0 FROM {locales_meta}");
+
+  // Save the language count in the variable table
+  $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1'));
+  variable_set('language_count', $count);
+
+  // Save the default language in the variable table
+  $default = db_fetch_object(db_query('SELECT * FROM {locales_meta} WHERE isdefault = 1'));
+  variable_set('language_default', (object) array('language' => $default->locale, 'name' => $default->name, 'native' => '', 'direction' => 0, 'enabled' => 1, 'plurals' => $default->plurals, 'formula' => $default->formula, 'domain' => '', 'prefix' => $default->locale, 'weight' => 0));
+
+  $ret[] = update_sql("DROP TABLE {locales_meta}");
+  return $ret;
+}
+
+/**
+ * Change locale column to language. The language column is added by
+ * update_fix_d6_requirements() in update.php to avoid a large number
+ * of error messages from update.php.  All we need to do here is copy
+ * locale to language and then drop locale.
+ */
+function system_update_6043() {
+  $ret = array();
+  if (db_table_exists('locales_target')) {
+    $ret[] = update_sql('UPDATE {locales_target} SET language = locale');
+    db_drop_field($ret, 'locales_target', 'locale');
+  }
+  return $ret;
+}
+
+/**
+ * Adds a column to store the filename of the JavaScript translation file.
+ */
+function system_update_6044() {
+  $ret = array();
+  if (db_table_exists('languages')) {
+    db_add_field($ret, 'languages', 'javascript', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''));
+  }
+  return $ret;
+}
+
+/**
+ * Remove empty translations, we don't need these anymore.
+ */
+function system_update_6045() {
+  $ret = array();
+  if (db_table_exists('locales_target')) {
+    $ret[] = update_sql("DELETE FROM {locales_target} WHERE translation = ''");
+  }
+  return $ret;
+}
+
+/**
+ * Prune strings with no translations (will be automatically re-registered if still in use)
+ */
+function system_update_6046() {
+  $ret = array();
+  if (db_table_exists('locales_source')) {
+    $ret[] = update_sql("DELETE FROM {locales_source} WHERE lid NOT IN (SELECT lid FROM {locales_target})");
+  }
+  return $ret;
+}
+
+/**
+ * Fix remaining inconsistent indexes.
+ */
+function system_update_6047() {
+  $ret = array();
+  if (db_table_exists('locales_target')) {
+    db_add_index($ret, 'locales_target', 'language', array('language'));
+  }
+
+  switch ($GLOBALS['db_type']) {
+    case 'pgsql':
+      if (db_table_exists('locales_source')) {
+        db_drop_index($ret, 'locales_source', 'source');
+        db_add_index($ret, 'locales_source', 'source', array(array('source', 30)));
+      }
+      break;
+  }
+
+  return $ret;
+}
+
+/**
  * @} End of "defgroup updates-5.x-to-6.x"
  * The next series of updates should start at 7000.
  */

