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'") ."\nOK\n");
+ }
+ else {
+ $ret[] = array('0', check_plain("UPDATE {blocks} SET theme = '$default_theme'") ."\nFAILED\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.' . "\nFAILED\n", array('%theme' => $theme)));
+ }
+ else {
+ $ret[] = array(1, t('Blocks initiated for %theme theme.' . "\nOK\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 25 Aug 2005 17:48:18 -0000
@@ -373,39 +373,41 @@
/**
* Get a list of available regions from a specified theme.
*
- * @param $theme
+ * @param $theme_key
* The name of a theme.
* @return
* An array of regions in the form $region['name'] = 'description'.
*/
-function system_region_list($theme) {
+function system_region_list($theme_key) {
static $list = array();
- if(!array_key_exists($theme, $list)) {
+ if(!array_key_exists($theme_key, $list)) {
- $themes = list_themes();
+ $result = db_query("SELECT * FROM {system} WHERE type = 'theme' AND name = '%s'", $theme_key);
+ $theme = db_fetch_object($result);
- if (strpos($themes[$theme]->filename, '.css')) {
+ if (strpos($theme->filename, '.css')) {
// File is a style, which can't have its own regions; use its theme instead.
- $theme = basename(dirname($themes[$theme]->description));
+ $list[$theme_key] = system_region_list(basename(dirname($theme->description)));
+ return $list[$theme_key];
}
- if (file_exists($file = dirname($themes[$theme]->filename) .'/' . $themes[$theme]->name . '.theme')) {
+ if (file_exists($file = dirname($theme->filename) .'/' . $theme_key . '.theme')) {
include_once($file);
}
- $regions = function_exists($theme . '_regions') ? call_user_func($theme . '_regions') : array();
- if (strpos($themes[$theme]->description, '.engine')) {
+ $regions = function_exists($theme_key . '_regions') ? call_user_func($theme_key . '_regions') : array();
+ if (strpos($theme->description, '.engine')) {
// File is a template; include its engine's regions.
- include_once($themes[$theme]->description);
- $theme_engine = basename($themes[$theme]->description, '.engine');
+ include_once($theme->description);
+ $theme_engine = basename($theme->description, '.engine');
$engine_regions = function_exists($theme_engine . '_regions') ? call_user_func($theme_engine . '_regions') : array();
$regions = array_merge($engine_regions, $regions);
}
- $list[$theme] = $regions;
+ $list[$theme_key] = $regions;
}
- return $list[$theme];
+ return $list[$theme_key];
}
/**
@@ -551,7 +553,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) {
@@ -559,16 +561,27 @@
if (($edit['type'] == 'theme') && ($edit['theme_default'] == $name)) {
$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 theme status is being set to 1 from 0, initialize block data for this theme if necessary.
+ if (($edit['type'] == 'theme') && ($status == 1) && 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 (in_array($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 +600,15 @@
* 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 +619,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) {