Commit 9a5bfda0 authored by Dries's avatar Dries

- Patch #82173 by flk: allow users to configure a port number.

parent 97112941
...@@ -33,15 +33,10 @@ function drupal_test_mysqli($url, &$success) { ...@@ -33,15 +33,10 @@ function drupal_test_mysqli($url, &$success) {
$url['host'] = urldecode($url['host']); $url['host'] = urldecode($url['host']);
$url['path'] = urldecode($url['path']); $url['path'] = urldecode($url['path']);
// Allow for non-standard MySQL port.
if (isset($url['port'])) {
$url['host'] = $url['host'] .':'. $url['port'];
}
$connection = mysqli_init(); $connection = mysqli_init();
@mysqli_real_connect($connection, $url['host'], $url['user'], $url['pass'], substr($url['path'], 1), $url['port'], NULL, MYSQLI_CLIENT_FOUND_ROWS); @mysqli_real_connect($connection, $url['host'], $url['user'], $url['pass'], substr($url['path'], 1), $url['port'], NULL, MYSQLI_CLIENT_FOUND_ROWS);
if (mysqli_connect_errno() >= 2000 || mysqli_connect_errno() == 1045) { if (mysqli_connect_errno() >= 2000 || mysqli_connect_errno() == 1045) {
drupal_set_message(st('Failure to connect to your MySQL database server. MySQL reports the following message: %error.<ul><li>Are you sure you have the correct username and password?</li><li>Are you sure that you have typed the correct database hostname?</li><li>Are you sure that the database server is running?</li></ul>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.', array('%error' => mysqli_errno())), 'error'); drupal_set_message(st('Failure to connect to your MySQL database server. MySQL reports the following message: %error.<ul><li>Are you sure you have the correct username and password?</li><li>Are you sure that you have typed the correct database hostname?</li><li>Are you sure that the database server is running?</li></ul>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.', array('%error' => mysqli_error($connection))), 'error');
return FALSE; return FALSE;
} }
......
...@@ -109,10 +109,11 @@ function install_verify_settings() { ...@@ -109,10 +109,11 @@ function install_verify_settings() {
$db_user = urldecode($url['user']); $db_user = urldecode($url['user']);
$db_pass = urldecode($url['pass']); $db_pass = urldecode($url['pass']);
$db_host = urldecode($url['host']); $db_host = urldecode($url['host']);
$db_port = urldecode($url['port']);
$db_path = ltrim(urldecode($url['path']), '/'); $db_path = ltrim(urldecode($url['path']), '/');
$settings_file = './'. conf_path() .'/settings.php'; $settings_file = './'. conf_path() .'/settings.php';
_install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_path, $settings_file); _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file);
if (!form_get_errors()) { if (!form_get_errors()) {
return TRUE; return TRUE;
} }
...@@ -130,6 +131,7 @@ function install_change_settings() { ...@@ -130,6 +131,7 @@ function install_change_settings() {
$db_user = urldecode($url['user']); $db_user = urldecode($url['user']);
$db_pass = urldecode($url['pass']); $db_pass = urldecode($url['pass']);
$db_host = urldecode($url['host']); $db_host = urldecode($url['host']);
$db_port = urldecode($url['port']);
$db_path = ltrim(urldecode($url['path']), '/'); $db_path = ltrim(urldecode($url['path']), '/');
$settings_file = './'. conf_path() .'/settings.php'; $settings_file = './'. conf_path() .'/settings.php';
...@@ -151,7 +153,7 @@ function install_change_settings() { ...@@ -151,7 +153,7 @@ function install_change_settings() {
if ($db_url == 'mysql://username:password@localhost/databasename') { if ($db_url == 'mysql://username:password@localhost/databasename') {
$db_user = $db_pass = $db_path = ''; $db_user = $db_pass = $db_path = '';
} }
$output = drupal_get_form('install_settings_form', $profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_path); $output = drupal_get_form('install_settings_form', $profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_port, $db_path);
drupal_set_title(st('Database configuration')); drupal_set_title(st('Database configuration'));
print theme('install_page', $output); print theme('install_page', $output);
exit; exit;
...@@ -161,7 +163,7 @@ function install_change_settings() { ...@@ -161,7 +163,7 @@ function install_change_settings() {
/** /**
* Form API array definition for install_settings. * Form API array definition for install_settings.
*/ */
function install_settings_form($profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_path) { function install_settings_form($profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_port, $db_path) {
$db_types = drupal_detect_database_types(); $db_types = drupal_detect_database_types();
if (count($db_types) == 0) { if (count($db_types) == 0) {
$form['no_db_types'] = array( $form['no_db_types'] = array(
...@@ -248,6 +250,16 @@ function install_settings_form($profile, $install_locale, $settings_file, $db_ur ...@@ -248,6 +250,16 @@ function install_settings_form($profile, $install_locale, $settings_file, $db_ur
'#description' => st('If your database is located on a different server, change this.'), '#description' => st('If your database is located on a different server, change this.'),
); );
// Database port
$form['advanced_options']['db_port'] = array(
'#type' => 'textfield',
'#title' => st('Database port'),
'#default_value' => $db_port,
'#size' => 45,
'#maxlength' => 45,
'#description' => st('If your database server is listening to a non-standard port, enter its number.'),
);
// Database prefix // Database prefix
$form['advanced_options']['db_prefix'] = array( $form['advanced_options']['db_prefix'] = array(
'#type' => 'textfield', '#type' => 'textfield',
...@@ -276,13 +288,13 @@ function install_settings_form($profile, $install_locale, $settings_file, $db_ur ...@@ -276,13 +288,13 @@ function install_settings_form($profile, $install_locale, $settings_file, $db_ur
*/ */
function install_settings_form_validate($form_id, $form_values, $form) { function install_settings_form_validate($form_id, $form_values, $form) {
global $db_url; global $db_url;
_install_settings_form_validate($form_values['db_prefix'], $form_values['db_type'], $form_values['db_user'], $form_values['db_pass'], $form_values['db_host'], $form_values['db_path'], $form_values['settings_file'], $form); _install_settings_form_validate($form_values['db_prefix'], $form_values['db_type'], $form_values['db_user'], $form_values['db_pass'], $form_values['db_host'], $form_values['db_port'], $form_values['db_path'], $form_values['settings_file'], $form);
} }
/** /**
* Helper function for install_settings_validate. * Helper function for install_settings_validate.
*/ */
function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_path, $settings_file, $form = NULL) { function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file, $form = NULL) {
global $db_url; global $db_url;
// Check for default username/password // Check for default username/password
...@@ -295,6 +307,10 @@ function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pas ...@@ -295,6 +307,10 @@ function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pas
form_set_error('db_prefix', st('The database prefix you have entered, %db_prefix, is invalid. The database prefix can only contain alphanumeric characters and underscores.', array('%db_prefix' => $db_prefix)), 'error'); form_set_error('db_prefix', st('The database prefix you have entered, %db_prefix, is invalid. The database prefix can only contain alphanumeric characters and underscores.', array('%db_prefix' => $db_prefix)), 'error');
} }
if (!empty($db_port) && !is_numeric($db_port)) {
form_set_error('db_port', st('Database port must be a number.'));
}
// Check database type // Check database type
if (!isset($form)) { if (!isset($form)) {
$db_type = substr($db_url, 0, strpos($db_url, '://')); $db_type = substr($db_url, 0, strpos($db_url, '://'));
...@@ -305,7 +321,7 @@ function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pas ...@@ -305,7 +321,7 @@ function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pas
} }
else { else {
// Verify // Verify
$db_url = $db_type .'://'. urlencode($db_user) .($db_pass ? ':'. urlencode($db_pass) : '') .'@'. ($db_host ? urlencode($db_host) : 'localhost') .'/'. urlencode($db_path); $db_url = $db_type .'://'. urlencode($db_user) .($db_pass ? ':'. urlencode($db_pass) : '') .'@'. ($db_host ? urlencode($db_host) : 'localhost'). ($db_port ? ":$db_port" : '') .'/'. urlencode($db_path);
if (isset($form)) { if (isset($form)) {
form_set_value($form['_db_url'], $db_url); form_set_value($form['_db_url'], $db_url);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment