Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1128
diff -u -p -r1.1128 common.inc
--- includes/common.inc	12 Mar 2010 14:20:32 -0000	1.1128
+++ includes/common.inc	17 Mar 2010 20:59:38 -0000
@@ -6069,16 +6069,7 @@ function drupal_flush_all_caches() {
   registry_rebuild();
   drupal_clear_css_cache();
   drupal_clear_js_cache();
-
-  // If invoked from update.php, we must not update the theme information in the
-  // database, or this will result in all themes being disabled.
-  if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') {
-    _system_rebuild_theme_data();
-  }
-  else {
-    system_rebuild_theme_data();
-  }
-
+  system_rebuild_theme_data();
   drupal_theme_rebuild();
   menu_rebuild();
   node_types_rebuild();
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.582
diff -u -p -r1.582 theme.inc
--- includes/theme.inc	4 Mar 2010 09:03:08 -0000	1.582
+++ includes/theme.inc	17 Mar 2010 20:59:38 -0000
@@ -2443,7 +2443,7 @@ function template_preprocess_maintenance
 
   global $theme;
   // Retrieve the theme data to list all available regions.
-  $theme_data = _system_rebuild_theme_data();
+  $theme_data = list_themes();
   $regions = $theme_data[$theme]->info['regions'];
 
   // Get all region content set with drupal_add_region_content().
Index: includes/update.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/update.inc,v
retrieving revision 1.39
diff -u -p -r1.39 update.inc
--- includes/update.inc	7 Mar 2010 06:53:26 -0000	1.39
+++ includes/update.inc	17 Mar 2010 20:59:38 -0000
@@ -36,7 +36,10 @@ function update_check_incompatibility($n
 
   // Store values of expensive functions for future use.
   if (empty($themes) || empty($modules)) {
-    $themes = _system_rebuild_theme_data();
+    // We need to do a full rebuild here to make sure the database reflects any
+    // code changes that were made in the filesystem before the update script
+    // was initiated.
+    $themes = system_rebuild_theme_data();
     $modules = system_rebuild_module_data();
   }
 
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.901
diff -u -p -r1.901 system.module
--- modules/system/system.module	13 Mar 2010 06:55:50 -0000	1.901
+++ modules/system/system.module	17 Mar 2010 20:59:39 -0000
@@ -2342,7 +2342,13 @@ function _system_rebuild_theme_data() {
     $themes_info = $themes;
   }
 
-  return $themes_info;
+  // We don't return the original objects, because we don't want them to be
+  // manipulated by other functions.
+  $themes_info_cloned = array();
+  foreach ($themes_info as $key => $object) {
+    $themes_info_cloned[$key] = clone $object;
+  }
+  return $themes_info_cloned;
 }
 
 /**
Index: modules/system/system.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.test,v
retrieving revision 1.117
diff -u -p -r1.117 system.test
--- modules/system/system.test	12 Mar 2010 14:33:02 -0000	1.117
+++ modules/system/system.test	17 Mar 2010 20:59:40 -0000
@@ -1604,6 +1604,20 @@ class UpdateScriptFunctionalTest extends
     $this->drupalGet($this->update_url, array('external' => TRUE));
     $this->assertResponse(200);
   }
+
+  /**
+   * Tests the effect of using the update script on the theme system.
+   */
+  function testThemeSystem() {
+    // Since visiting update.php triggers a rebuild of the theme system from an
+    // unusual maintenance mode environment, we check that this rebuild did not
+    // put any incorrect information about the themes into the database.
+    $original_theme_data = db_query("SELECT * FROM {system} WHERE type = 'theme' ORDER BY name")->fetchAll();
+    $this->drupalLogin($this->update_user);
+    $this->drupalGet($this->update_url, array('external' => TRUE));
+    $final_theme_data = db_query("SELECT * FROM {system} WHERE type = 'theme' ORDER BY name")->fetchAll();
+    $this->assertEqual($original_theme_data, $final_theme_data, t('Visiting update.php does not alter the information about themes stored in the database.'));
+  }
 }
 
 /**
Index: modules/system/system.updater.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.updater.inc,v
retrieving revision 1.5
diff -u -p -r1.5 system.updater.inc
--- modules/system/system.updater.inc	30 Jan 2010 07:59:25 -0000	1.5
+++ modules/system/system.updater.inc	17 Mar 2010 20:59:40 -0000
@@ -136,7 +136,7 @@ class ThemeUpdater extends Updater imple
     // Update the system table.
     clearstatcache();
     drupal_static_reset('_system_rebuild_theme_data');
-    _system_rebuild_theme_data();
+    system_rebuild_theme_data();
 
     // Active the theme
     db_update('system')
