From 1ace2eca07e3009d8be0738894bc104116714af3 Mon Sep 17 00:00:00 2001 From: Graham Eames Date: Fri, 27 Jan 2006 20:23:33 +0000 Subject: [PATCH] Changing the way we handle the case where a user's style does not exist in the database We now try to fallback to the board default if possible and update the database if this succeeds git-svn-id: file:///svn/phpbb/branches/phpBB-2_0_0@5500 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index bea9c23afe..0d9cbcae0f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -372,7 +372,40 @@ function setup_style($style) if ( !($row = $db->sql_fetchrow($result)) ) { - message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]"); + // We are trying to setup a style which does not exist in the database + // Try to fallback to the board default (if the user had a custom style) + // and then any users using this style to the default if it succeeds + if ( $style != $board_config['default_style']) + { + $sql = 'SELECT * + FROM ' . THEMES_TABLE . ' + WHERE themes_id = ' . $board_config['default_style']; + if ( !($result = $db->sql_query($sql)) ) + { + message_die(CRITICAL_ERROR, 'Could not query database for theme info'); + } + + if ( $row = $db->sql_fetchrow($result) ) + { + $db->sql_freeresult($result); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = ' . $board_config['default_style'] . " + WHERE user_style = $style"; + if ( !($result = $db->sql_query($sql)) ) + { + message_die(CRITICAL_ERROR, 'Could not query database for theme info'); + } + } + else + { + message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]"); + } + } + else + { + message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]"); + } } $template_path = 'templates/' ;