- #27231: Friendly DB error screens.
							parent
							
								
									88ccaf02c4
								
							
						
					
					
						commit
						d9d4b9bdab
					
				| 
						 | 
					@ -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 = '';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
| 
						 | 
					@ -1831,7 +1831,7 @@ function drupal_implode_autocomplete($array) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function _drupal_bootstrap_full() {
 | 
					function _drupal_bootstrap_full() {
 | 
				
			||||||
  static $called;
 | 
					  static $called;
 | 
				
			||||||
  global $locale, $multibyte;
 | 
					  global $locale;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if ($called) {
 | 
					  if ($called) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
| 
						 | 
					@ -1850,7 +1850,7 @@ function _drupal_bootstrap_full() {
 | 
				
			||||||
  // Emit the correct charset HTTP header.
 | 
					  // Emit the correct charset HTTP header.
 | 
				
			||||||
  drupal_set_header('Content-Type: text/html; charset=utf-8');
 | 
					  drupal_set_header('Content-Type: text/html; charset=utf-8');
 | 
				
			||||||
  // Detect string handling method
 | 
					  // Detect string handling method
 | 
				
			||||||
  $multibyte = unicode_check();
 | 
					  unicode_check();
 | 
				
			||||||
  // Initialize $_GET['q'] prior to loading modules and invoking hook_init().
 | 
					  // Initialize $_GET['q'] prior to loading modules and invoking hook_init().
 | 
				
			||||||
  if (!empty($_GET['q'])) {
 | 
					  if (!empty($_GET['q'])) {
 | 
				
			||||||
    $_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
 | 
					    $_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -116,7 +116,11 @@ function db_set_active($name = 'default') {
 | 
				
			||||||
      include_once($handler);
 | 
					      include_once($handler);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
      die('Unsupported database type');
 | 
					      drupal_maintenance_theme();
 | 
				
			||||||
 | 
					      drupal_set_title('Unsupported database type');
 | 
				
			||||||
 | 
					      print theme('maintenance_page', '<p>The database type '. theme('placeholder', $db_type) .' is unsupported. Please use either <var>mysql</var> for MySQL databases or <var>pgsql</var> for PostgreSQL databases. The database information is in your <code>settings.php</code> file.</p>
 | 
				
			||||||
 | 
					<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
 | 
				
			||||||
 | 
					      exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $db_conns[$name] = db_connect($connect_url);
 | 
					    $db_conns[$name] = db_connect($connect_url);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,9 +34,36 @@ function db_connect($url) {
 | 
				
			||||||
  //   server.
 | 
					  //   server.
 | 
				
			||||||
  // - 2 means CLIENT_FOUND_ROWS: return the number of found
 | 
					  // - 2 means CLIENT_FOUND_ROWS: return the number of found
 | 
				
			||||||
  //   (matched) rows, not the number of affected rows.
 | 
					  //   (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', '<p>This either means that the username and password information in your <code>settings.php</code> file is incorrect or we can\'t contact the MySQL database server. This could mean your hosting provider\'s database server is down.</p>
 | 
				
			||||||
 | 
					<p>The MySQL error was: '. theme('placeholder', mysql_error()) .'.</p>
 | 
				
			||||||
 | 
					<p>Currently, the username is '. theme('placeholder', $url['user']) .' and the database server is '. theme('placeholder', $url['host']) .'.</p>
 | 
				
			||||||
 | 
					<ul>
 | 
				
			||||||
 | 
					  <li>Are you sure you have the correct username and password?</li>
 | 
				
			||||||
 | 
					  <li>Are you sure that you have typed the correct hostname?</li>
 | 
				
			||||||
 | 
					  <li>Are you sure that the database server is running?</li>
 | 
				
			||||||
 | 
					</ul>
 | 
				
			||||||
 | 
					<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
 | 
				
			||||||
 | 
					    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', '<p>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.</p>
 | 
				
			||||||
 | 
					<p>The MySQL error was: '. theme('placeholder', mysql_error()) .'.</p>
 | 
				
			||||||
 | 
					<p>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']) .'.</p>
 | 
				
			||||||
 | 
					<ul>
 | 
				
			||||||
 | 
					  <li>Are you sure you have the correct database name?</li>
 | 
				
			||||||
 | 
					  <li>Are you sure the database exists?</li>
 | 
				
			||||||
 | 
					  <li>Are you sure the username has permission to access the database?</li>
 | 
				
			||||||
 | 
					</ul>
 | 
				
			||||||
 | 
					<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
 | 
				
			||||||
 | 
					    exit;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return $connection;
 | 
					  return $connection;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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 = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'] . ' host=' . $url['host'];
 | 
				
			||||||
  $conn_string .= isset($url['port']) ? ' port=' . $url['port'] : '';
 | 
					  $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', '<p>This either means that the database information in your <code>settings.php</code> file is incorrect or we can\'t contact the PostgreSQL database server. This could mean your hosting provider\'s database server is down.</p>
 | 
				
			||||||
 | 
					<p>The PostgreSQL error was: '. theme('placeholder', decode_entities($php_errormsg)) .'</p>
 | 
				
			||||||
 | 
					<p>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']) .'.</p>
 | 
				
			||||||
 | 
					<ul>
 | 
				
			||||||
 | 
					  <li>Are you sure you have the correct username and password?</li>
 | 
				
			||||||
 | 
					  <li>Are you sure that you have typed the correct hostname?</li>
 | 
				
			||||||
 | 
					  <li>Are you sure you have the correct database name?</li>
 | 
				
			||||||
 | 
					  <li>Are you sure that the database server is running?</li>
 | 
				
			||||||
 | 
					</ul>
 | 
				
			||||||
 | 
					<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
 | 
				
			||||||
 | 
					    exit;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Restore error tracking setting
 | 
				
			||||||
 | 
					  ini_set('track_errors', $track_errors_previous);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return $connection;
 | 
					  return $connection;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -160,7 +160,7 @@ function list_theme_engines($refresh = FALSE) {
 | 
				
			||||||
function theme() {
 | 
					function theme() {
 | 
				
			||||||
  global $theme, $theme_engine;
 | 
					  global $theme, $theme_engine;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!$theme) {
 | 
					  if ($theme === NULL) {
 | 
				
			||||||
    // Initialize the enabled theme.
 | 
					    // Initialize the enabled theme.
 | 
				
			||||||
    $theme = init_theme();
 | 
					    $theme = init_theme();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -440,6 +440,31 @@ function theme_page($content) {
 | 
				
			||||||
  return $output;
 | 
					  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 = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
 | 
				
			||||||
 | 
					  $output .= '<html xmlns="http://www.w3.org/1999/xhtml">';
 | 
				
			||||||
 | 
					  $output .= '<head>';
 | 
				
			||||||
 | 
					  $output .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
 | 
				
			||||||
 | 
					  $output .= ' <title>'. drupal_get_title() .'</title>';
 | 
				
			||||||
 | 
					  $output .= theme_get_styles();
 | 
				
			||||||
 | 
					  $output .= '</head>';
 | 
				
			||||||
 | 
					  $output .= '<body>';
 | 
				
			||||||
 | 
					  $output .= '<h1>' . drupal_get_title() . '</h1>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $output .= theme('status_messages');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $output .= "\n<!-- begin content -->\n";
 | 
				
			||||||
 | 
					  $output .= $content;
 | 
				
			||||||
 | 
					  $output .= "\n<!-- end content -->\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $output .= '</body></html>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return $output;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Returns themed set of status and/or error messages.  The messages are grouped
 | 
					 * Returns themed set of status and/or error messages.  The messages are grouped
 | 
				
			||||||
 * by type.
 | 
					 * by type.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,13 @@ define('UNICODE_ERROR', -1);
 | 
				
			||||||
define('UNICODE_SINGLEBYTE', 0);
 | 
					define('UNICODE_SINGLEBYTE', 0);
 | 
				
			||||||
define('UNICODE_MULTIBYTE', 1);
 | 
					define('UNICODE_MULTIBYTE', 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Wrapper around _unicode_check().
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function unicode_check() {
 | 
				
			||||||
 | 
					  $GLOBALS['multibyte'] = _unicode_check();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Perform checks about Unicode support in PHP, and set the right settings if
 | 
					 * Perform checks about Unicode support in PHP, and set the right settings if
 | 
				
			||||||
 * needed.
 | 
					 * needed.
 | 
				
			||||||
| 
						 | 
					@ -16,7 +23,7 @@ define('UNICODE_MULTIBYTE', 1);
 | 
				
			||||||
 * @param $errors
 | 
					 * @param $errors
 | 
				
			||||||
 *   Whether to report any fatal errors with form_set_error().
 | 
					 *   Whether to report any fatal errors with form_set_error().
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function unicode_check($errors = false) {
 | 
					function _unicode_check($errors = false) {
 | 
				
			||||||
  // Set the standard C locale to ensure consistent, ASCII-only string handling.
 | 
					  // Set the standard C locale to ensure consistent, ASCII-only string handling.
 | 
				
			||||||
  setlocale(LC_CTYPE, 'C');
 | 
					  setlocale(LC_CTYPE, 'C');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,7 +77,7 @@ function unicode_check($errors = false) {
 | 
				
			||||||
 * Return the required Unicode status and errors for admin/settings.
 | 
					 * Return the required Unicode status and errors for admin/settings.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function unicode_settings() {
 | 
					function unicode_settings() {
 | 
				
			||||||
  $status = unicode_check(true);
 | 
					  $status = _unicode_check(true);
 | 
				
			||||||
  $options = array(UNICODE_SINGLEBYTE => t('Standard PHP: operations on Unicode strings are emulated on a best-effort basis. Install the <a href="%url">PHP mbstring extension</a> for improved Unicode support.', array('%url' => 'http://www.php.net/manual/nl/ref.mbstring.php')),
 | 
					  $options = array(UNICODE_SINGLEBYTE => t('Standard PHP: operations on Unicode strings are emulated on a best-effort basis. Install the <a href="%url">PHP mbstring extension</a> for improved Unicode support.', array('%url' => 'http://www.php.net/manual/nl/ref.mbstring.php')),
 | 
				
			||||||
                   UNICODE_MULTIBYTE => t('Multi-byte: operations on Unicode strings are supported through the <a href="%url">PHP mbstring extension</a>.', array('%url' => 'http://www.php.net/manual/nl/ref.mbstring.php')),
 | 
					                   UNICODE_MULTIBYTE => t('Multi-byte: operations on Unicode strings are supported through the <a href="%url">PHP mbstring extension</a>.', array('%url' => 'http://www.php.net/manual/nl/ref.mbstring.php')),
 | 
				
			||||||
                   UNICODE_ERROR => t('Invalid: the current configuration is incompatible with Drupal.'));
 | 
					                   UNICODE_ERROR => t('Invalid: the current configuration is incompatible with Drupal.'));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 4.0 KiB  | 
| 
						 | 
					@ -0,0 +1,19 @@
 | 
				
			||||||
 | 
					body {
 | 
				
			||||||
 | 
					  background: url(druplicon.png) 4.2em 4em no-repeat #fff;
 | 
				
			||||||
 | 
					  color: #000;
 | 
				
			||||||
 | 
					  border: 1px solid #bbb;
 | 
				
			||||||
 | 
					  margin: 3em;
 | 
				
			||||||
 | 
					  padding: 1em 1em 1em 128px;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					h1 {
 | 
				
			||||||
 | 
					  margin: 1.6em 0 1.1em 0;
 | 
				
			||||||
 | 
					  font-family: sans-serif;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					:link {
 | 
				
			||||||
 | 
					  color: #0073ba;
 | 
				
			||||||
 | 
					  font-weight: bold;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					:visited {
 | 
				
			||||||
 | 
					  color: #004975;
 | 
				
			||||||
 | 
					  font-weight: bold;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue