Index: database/updates.inc
===================================================================
RCS file: /cvs/drupal/drupal/database/updates.inc,v
retrieving revision 1.128
diff -u -r1.128 updates.inc
--- database/updates.inc	16 Aug 2005 20:17:54 -0000	1.128
+++ database/updates.inc	24 Aug 2005 17:18:40 -0000
@@ -684,21 +684,39 @@
 }
 
 function update_145() {
-  $default_theme = variable_get('theme_default', 'bluemarine');
+
   $ret = array();
   $ret[] = update_sql("ALTER TABLE {blocks} CHANGE region region varchar(64) default 'left' NOT NULL");
   $ret[] = update_sql("ALTER TABLE {blocks} ADD theme varchar(255) NOT NULL default ''");
 
+  // Check if default theme is updated with region support.  If not, set default to bluemarine.
+  $regions = system_region_list(variable_get('theme_default', 'bluemarine'));
+  if (count($regions) == 0) {
+    variable_set('theme_default', 'bluemarine');
+  }
+  $default_theme = variable_get('theme_default', 'bluemarine');
+
   // Intialize block data for default theme
   $ret[] = update_sql("UPDATE {blocks} SET region = 'left' WHERE region = '0'");
   $ret[] = update_sql("UPDATE {blocks} SET region = 'right' WHERE region = '1'");
-  db_query("UPDATE {blocks} SET theme = '%s'", $default_theme);
-
+  $result = db_query("UPDATE {blocks} SET theme = '%s'", $default_theme);
+  if ($result) {
+    $ret[] = array('1', check_plain("UPDATE {blocks} SET theme = '$default_theme'") ."\n<span class=\"success\">OK</span>\n");
+  }
+  else {
+    $ret[] = array('0', check_plain("UPDATE {blocks} SET theme = '$default_theme'") ."\n<span class=\"failure\">FAILED</span>\n");
+  }
   // Initialze block data for other enabled themes.
   $themes = list_themes();
   foreach (array_keys($themes) as $theme) {
     if (($theme != $default_theme) && $themes[$theme]->status == 1) {
-      system_initialize_theme_blocks($theme);
+      if (!system_initialize_theme_blocks($theme)) {
+        update_sql("UPDATE {system} SET status = 0, WHERE type = 'theme' AND name = '%s'", $theme);
+        $ret[] = array(0, t('The theme %theme failed to initialize its blocks and so has been disabled.  The theme may need to be upgraded.' . "\n<span class=\"failure\">FAILED</span>\n", array('%theme' => $theme)));
+      }
+      else {
+        $ret[] = array(1, t('Blocks initiated for %theme theme.' . "\n<span class=\"success\">OK</span>\n", array('%theme' => $theme)));
+      }
     }
   }
 
Index: modules/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system.module,v
retrieving revision 1.226
diff -u -r1.226 system.module
--- modules/system.module	22 Aug 2005 05:09:01 -0000	1.226
+++ modules/system.module	24 Aug 2005 17:05:36 -0000
@@ -551,7 +551,7 @@
 function system_listing_save($edit = array()) {
   $op = $_POST['op'];
   $edit = $_POST['edit'];
-
+  $faulty_themes = array();
   if ($op == t('Save configuration')) {
     db_query("UPDATE {system} SET status = 0 WHERE type = '%s'", $edit['type']);
     foreach ($edit['status'] as $name => $status) {
@@ -560,15 +560,27 @@
         $status = 1;
       }
       // If status is being set to 1 from 0, initialize block data for this theme if necessary.
-      if (($status == 1) && db_num_rows(db_query("SELECT status FROM {system} WHERE type = '%s' AND name = '%s' AND status = 0", $edit['type'], $name))) {
-        system_initialize_theme_blocks($name);
+      if (($status == 1) && ($edit['type'] == 'theme') && db_num_rows(db_query("SELECT status FROM {system} WHERE type = '%s' AND name = '%s' AND status = 0", $edit['type'], $name))) {
+        if (!system_initialize_theme_blocks($name)) {
+          $status = 0;
+          drupal_set_message(t('The theme %theme failed to initialize and so has not been enabled.  It may need to be upgraded.', array('%theme' => $name)));
+          $faulty_themes[] = $name;
+        }
       }
 
       db_query("UPDATE {system} SET status = %d, throttle = %d WHERE type = '%s' AND name = '%s'", $status, $edit['throttle'][$name], $edit['type'], $name);
     }
 
     if ($edit['type'] == 'theme') {
-      variable_set('theme_default', $edit['theme_default']);
+      // If the theme set as default hasn't initialized, ensure bluemarine is enabled and then set it as the default theme.
+      if (array_key_exists ($edit['theme_default'], $faulty_themes)) {
+        db_query("UPDATE {system} SET status = 1, WHERE type = 'theme' AND name = 'bluemarine'");
+        variable_set('theme_default', 'bluemarine');
+        drupal_set_message(t('The theme set as default failed to initialize, so bluemarine has been set as the default theme.'));
+      }
+      else {
+        variable_set('theme_default', $edit['theme_default']);
+      }
     }
 
     menu_rebuild();
@@ -587,10 +599,14 @@
  *   The name of a theme.
  */
 function system_initialize_theme_blocks($theme) {
-  $default_theme = variable_get('theme_default', 'bluemarine');
-  $regions = system_region_list($theme);
   // Initialize theme's blocks if none already registered.
   if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) {
+    $default_theme = variable_get('theme_default', 'bluemarine');
+    $regions = system_region_list($theme);
+    // If no regions returned, fail.
+    if (count($regions) == 0) {
+      return FALSE;
+    }
     $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
     while($block = db_fetch_array($result)) {
       // If the region isn't supported by the theme, assign the block to the theme's default region.
@@ -601,6 +617,7 @@
           $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']);
     }
   }
+  return TRUE;
 }
 
 function system_settings_form($form) {
