diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index fe85eb447976..8354520e6609 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -864,4 +864,20 @@ function _drupal_bootstrap($phase) { } } -?> +/** + * Enables use of the theme system without requiring database access. Since + * there is not database access no theme will be enabled and the default + * themable fuctions will be called. Some themable functions can not be used + * without the full Drupal API loaded. For example, theme_page() is + * unavailable and theme_maintenance_page() must be used in its place. + */ +function drupal_maintenance_theme() { + global $theme; + require_once './includes/theme.inc'; + require_once './includes/common.inc'; + require_once './includes/unicode.inc'; + unicode_check(); + $theme = ''; +} + +?> \ No newline at end of file diff --git a/includes/common.inc b/includes/common.inc index 93724afd6f10..2672bf895e2e 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1831,7 +1831,7 @@ function drupal_implode_autocomplete($array) { function _drupal_bootstrap_full() { static $called; - global $locale, $multibyte; + global $locale; if ($called) { return; @@ -1850,7 +1850,7 @@ function _drupal_bootstrap_full() { // Emit the correct charset HTTP header. drupal_set_header('Content-Type: text/html; charset=utf-8'); // Detect string handling method - $multibyte = unicode_check(); + unicode_check(); // Initialize $_GET['q'] prior to loading modules and invoking hook_init(). if (!empty($_GET['q'])) { $_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/')); diff --git a/includes/database.inc b/includes/database.inc index c76b0083d454..fa111b460455 100644 --- a/includes/database.inc +++ b/includes/database.inc @@ -116,7 +116,11 @@ function db_set_active($name = 'default') { include_once($handler); } else { - die('Unsupported database type'); + drupal_maintenance_theme(); + drupal_set_title('Unsupported database type'); + print theme('maintenance_page', '
The database type '. theme('placeholder', $db_type) .' is unsupported. Please use either mysql for MySQL databases or pgsql for PostgreSQL databases. The database information is in your settings.php file.
For more help, see the Installation and upgrading handbook. If you are unsure what these terms mean you should probably contact your hosting provider.
'); + exit; } $db_conns[$name] = db_connect($connect_url); diff --git a/includes/database.mysql.inc b/includes/database.mysql.inc index 78bd24656ac0..22012d4320fe 100644 --- a/includes/database.mysql.inc +++ b/includes/database.mysql.inc @@ -34,9 +34,36 @@ function db_connect($url) { // server. // - 2 means CLIENT_FOUND_ROWS: return the number of found // (matched) rows, not the number of affected rows. - $connection = mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2) or die(mysql_error()); + $connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2); + if (!$connection) { + drupal_maintenance_theme(); + drupal_set_title('Unable to connect to database server'); + print theme('maintenance_page', 'This either means that the username and password information in your settings.php file is incorrect or we can\'t contact the MySQL database server. This could mean your hosting provider\'s database server is down.
The MySQL error was: '. theme('placeholder', mysql_error()) .'.
+Currently, the username is '. theme('placeholder', $url['user']) .' and the database server is '. theme('placeholder', $url['host']) .'.
+For more help, see the Installation and upgrading handbook. If you are unsure what these terms mean you should probably contact your hosting provider.
'); + exit; + } - mysql_select_db(substr($url['path'], 1)) or die('unable to select database'); + if (!mysql_select_db(substr($url['path'], 1))) { + drupal_maintenance_theme(); + drupal_set_title('Unable to select database'); + print theme('maintenance_page', 'We were able to connect to the MySQL database server (which means your username and password is okay) but not able to select the database.
+The MySQL error was: '. theme('placeholder', mysql_error()) .'.
+Currently, the database is '. theme('placeholder', substr($url['path'], 1)) .'. The username is '. theme('placeholder', $url['user']) .' and the database server is '. theme('placeholder', $url['host']) .'.
+For more help, see the Installation and upgrading handbook. If you are unsure what these terms mean you should probably contact your hosting provider.
'); + exit; + } return $connection; } diff --git a/includes/database.pgsql.inc b/includes/database.pgsql.inc index 9e4ecf21bb87..46acbe14ad01 100644 --- a/includes/database.pgsql.inc +++ b/includes/database.pgsql.inc @@ -25,7 +25,32 @@ function db_connect($url) { $conn_string = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'] . ' host=' . $url['host']; $conn_string .= isset($url['port']) ? ' port=' . $url['port'] : ''; - $connection = pg_connect($conn_string) or die(pg_last_error()); + + // pg_last_error() does not return a useful error message for database + // connection errors. We must turn on error tracking to get at a good error + // message, which will be stored in $php_errormsg. + $track_errors_previous = ini_get('track_errors'); + ini_set('track_errors', 1); + + $connection = @pg_connect($conn_string); + if (!$connection) { + drupal_maintenance_theme(); + drupal_set_title('Unable to connect to database'); + print theme('maintenance_page', 'This either means that the database information in your settings.php file is incorrect or we can\'t contact the PostgreSQL database server. This could mean your hosting provider\'s database server is down.
The PostgreSQL error was: '. theme('placeholder', decode_entities($php_errormsg)) .'
+Currently, the database is '. theme('placeholder', substr($url['path'], 1)) .', the username is '. theme('placeholder', $url['user']) .', and the database server is '. theme('placeholder', $url['host']) .'.
+For more help, see the Installation and upgrading handbook. If you are unsure what these terms mean you should probably contact your hosting provider.
'); + exit; + } + + // Restore error tracking setting + ini_set('track_errors', $track_errors_previous); return $connection; } diff --git a/includes/theme.inc b/includes/theme.inc index 02f74fd36964..04100a8e9b3f 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -160,7 +160,7 @@ function list_theme_engines($refresh = FALSE) { function theme() { global $theme, $theme_engine; - if (!$theme) { + if ($theme === NULL) { // Initialize the enabled theme. $theme = init_theme(); } @@ -440,6 +440,31 @@ function theme_page($content) { return $output; } +function theme_maintenance_page($content) { + drupal_set_header('Content-Type: text/html; charset=utf-8'); + theme('add_style', 'misc/drupal.css'); + theme('add_style', 'misc/maintenance.css'); + $output = "\n"; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= '