? includes/database/install.inc ? sites/all/modules/cvs Index: install.php =================================================================== RCS file: /cvs/drupal/drupal/install.php,v retrieving revision 1.153 diff -u -p -r1.153 install.php --- install.php 8 Feb 2009 20:27:51 -0000 1.153 +++ install.php 8 Feb 2009 21:41:15 -0000 @@ -210,117 +210,28 @@ function install_change_settings($profil include_once DRUPAL_ROOT . '/includes/form.inc'; install_task_list('database'); - $output = drupal_get_form('install_settings_form', $profile, $install_locale, $settings_file, $database); + $output = drupal_get_form('install_database_select_form', $profile, $install_locale, $settings_file, $database); drupal_set_title(st('Database configuration')); print theme('install_page', $output); exit; } - -/** - * Form API array definition for install_settings. - */ -function install_settings_form(&$form_state, $profile, $install_locale, $settings_file, $database) { +function install_database_select_form(&$form_state, $profile, $install_locale, $settings_file, $database) { $drivers = drupal_detect_database_types(); - + if (!$drivers) { $form['no_drivers'] = array( '#markup' => st('Your web server does not appear to support any common database types. Check with your hosting provider to see if they offer any databases that Drupal supports.', array('@drupal-databases' => 'http://drupal.org/node/270#database')), ); } else { - $form['basic_options'] = array( - '#type' => 'fieldset', - '#title' => st('Basic options'), - '#description' => '
' . st('To set up your @drupal database, enter the following information.', array('@drupal' => drupal_install_profile_name())) . '
', - ); - - if (count($drivers) == 1) { - $form['basic_options']['driver'] = array( - '#type' => 'hidden', - '#value' => current(array_keys($drivers)), - ); - $database_description = st('The name of the %driver database your @drupal data will be stored in. It must exist on your server before @drupal can be installed.', array('%driver' => current($drivers), '@drupal' => drupal_install_profile_name())); - } - else { - $form['basic_options']['driver'] = array( - '#type' => 'radios', - '#title' => st('Database type'), - '#required' => TRUE, - '#options' => $drivers, - '#default_value' => !empty($database['driver']) ? $database['driver'] : current(array_keys($drivers)), - '#description' => st('The type of database your @drupal data will be stored in.', array('@drupal' => drupal_install_profile_name())), - ); - $database_description = st('The name of the database your @drupal data will be stored in. It must exist on your server before @drupal can be installed.', array('@drupal' => drupal_install_profile_name())); - } - - // Database name - $form['basic_options']['database'] = array( - '#type' => 'textfield', - '#title' => st('Database name'), - '#default_value' => empty($database['database']) ? '' : $database['database'], - '#size' => 45, - '#maxlength' => 45, - '#required' => TRUE, - '#description' => $database_description, - ); - - // Database username - $form['basic_options']['username'] = array( - '#type' => 'textfield', - '#title' => st('Database username'), - '#default_value' => empty($database['username']) ? '' : $database['username'], - '#size' => 45, - '#maxlength' => 45, - ); - - // Database username - $form['basic_options']['password'] = array( - '#type' => 'password', - '#title' => st('Database password'), - '#default_value' => empty($database['password']) ? '' : $database['password'], - '#size' => 45, - '#maxlength' => 45, - ); - - $form['advanced_options'] = array( - '#type' => 'fieldset', - '#title' => st('Advanced options'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#description' => st("These options are only necessary for some sites. If you're not sure what you should enter here, leave the default settings or check with your hosting provider.") - ); - - // Database host - $form['advanced_options']['host'] = array( - '#type' => 'textfield', - '#title' => st('Database host'), - '#default_value' => empty($database['host']) ? 'localhost' : $database['host'], - '#size' => 45, - '#maxlength' => 45, + $form['driver'] = array( + '#type' => 'radios', + '#title' => st('Database type'), '#required' => TRUE, - '#description' => st('If your database is located on a different server, change this.'), - ); - - // Database port - $form['advanced_options']['port'] = array( - '#type' => 'textfield', - '#title' => st('Database port'), - '#default_value' => empty($database['port']) ? '' : $database['port'], - '#size' => 45, - '#maxlength' => 45, - '#description' => st('If your database server is listening to a non-standard port, enter its number.'), - ); - - // Table prefix - $db_prefix = ($profile == 'default') ? 'drupal_' : $profile . '_'; - $form['advanced_options']['db_prefix'] = array( - '#type' => 'textfield', - '#title' => st('Table prefix'), - '#default_value' => '', - '#size' => 45, - '#maxlength' => 45, - '#description' => st('If more than one application will be sharing this database, enter a table prefix such as %prefix for your @drupal site here.', array('@drupal' => drupal_install_profile_name(), '%prefix' => $db_prefix)), + '#options' => $drivers, + '#default_value' => !empty($database['driver']) ? $database['driver'] : current(array_keys($drivers)), + '#description' => st('The type of database your @drupal data will be stored in.', array('@drupal' => drupal_install_profile_name())), ); $form['save'] = array( @@ -338,40 +249,134 @@ function install_settings_form(&$form_st } /** - * Form API validate for install_settings form. + * Form API array definition for install_settings. */ -function install_settings_form_validate($form, &$form_state) { - global $db_url; - _install_settings_form_validate($form_state['values'], $form_state['values']['settings_file'], $form_state, $form); +function install_database_settings_form(&$form_state, $profile, $install_locale, $settings_file, $database) { + $drivers = drupal_detect_database_types(); + + $form['basic_options'] = array( + '#type' => 'fieldset', + '#title' => st('Basic options'), + '#description' => '' . st('To set up your @drupal database, enter the following information.', array('@drupal' => drupal_install_profile_name())) . '
', + ); + + // Database name + $form['basic_options']['database'] = array( + '#type' => 'textfield', + '#title' => st('Database name'), + '#default_value' => empty($database['database']) ? '' : $database['database'], + '#size' => 45, + '#maxlength' => 45, + '#required' => TRUE, + '#description' => st('Your database must exist.'), + ); + + // Database username + $form['basic_options']['username'] = array( + '#type' => 'textfield', + '#title' => st('Database username'), + '#default_value' => empty($database['username']) ? '' : $database['username'], + '#size' => 45, + '#maxlength' => 45, + ); + + // Database username + $form['basic_options']['password'] = array( + '#type' => 'password', + '#title' => st('Database password'), + '#default_value' => empty($database['password']) ? '' : $database['password'], + '#size' => 45, + '#maxlength' => 45, + ); + + $form['advanced_options'] = array( + '#type' => 'fieldset', + '#title' => st('Advanced options'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#description' => st("These options are only necessary for some sites. If you're not sure what you should enter here, leave the default settings or check with your hosting provider.") + ); + + // Database host + $form['advanced_options']['host'] = array( + '#type' => 'textfield', + '#title' => st('Database host'), + '#default_value' => empty($database['host']) ? 'localhost' : $database['host'], + '#size' => 45, + '#maxlength' => 45, + '#required' => TRUE, + '#description' => st('If your database is located on a different server, change this.'), + ); + + // Database port + $form['advanced_options']['port'] = array( + '#type' => 'textfield', + '#title' => st('Database port'), + '#default_value' => empty($database['port']) ? '' : $database['port'], + '#size' => 45, + '#maxlength' => 45, + '#description' => st('If your database server is listening to a non-standard port, enter its number.'), + ); + + // Table prefix + $db_prefix = ($profile == 'default') ? 'drupal_' : $profile . '_'; + $form['advanced_options']['db_prefix'] = array( + '#type' => 'textfield', + '#title' => st('Table prefix'), + '#default_value' => '', + '#size' => 45, + '#maxlength' => 45, + '#description' => st('If more than one application will be sharing this database, enter a table prefix such as %prefix for your @drupal site here.', array('@drupal' => drupal_install_profile_name(), '%prefix' => $db_prefix)), + ); + + $form['save'] = array( + '#type' => 'submit', + '#value' => st('Save and continue'), + ); + + $form['errors'] = array(); + $form['settings_file'] = array('#type' => 'value', '#value' => $settings_file); + $form['_database'] = array('#type' => 'value'); + $form['#action'] = "install.php?profile=$profile" . ($install_locale ? "&locale=$install_locale" : ''); + $form['#redirect'] = FALSE; + + $class = "DatabaseInstaller_{$database['driver']}"; + if (method_exists($class, 'form_alter')) { + $test = new $class; + $test->form_alter($form, $form_state, 'install_database_settings_form'); + } + + return $form; } /** - * Helper function for install_settings_validate. + * Form API validate for install_settings form. */ -function _install_settings_form_validate($database, $settings_file, &$form_state, $form = NULL) { - global $databases; +function install_database_settings_form_validate($form, &$form_state) { + global $db_url, $databases; + // Verify the table prefix - if (!empty($database['prefix']) && is_string($database['prefix']) && !preg_match('/^[A-Za-z0-9_.]+$/', $database['dprefix'])) { + if (!empty($form_state['values']['prefix']) && is_string($form_state['values']['prefix']) && !preg_match('/^[A-Za-z0-9_.]+$/', $form_state['values']['dprefix'])) { form_set_error('db_prefix', st('The database table prefix you have entered, %db_prefix, is invalid. The table prefix can only contain alphanumeric characters, periods, or underscores.', array('%db_prefix' => $db_prefix)), 'error'); } - if (!empty($database['port']) && !is_numeric($database['port'])) { + if (!empty($form_state['values']['port']) && !is_numeric($form_state['values']['port'])) { form_set_error('db_port', st('Database port must be a number.')); } // Check database type $database_types = drupal_detect_database_types(); - $driver = $database['driver']; + $driver = $form_state['values']['driver']; if (!isset($database_types[$driver])) { - form_set_error('driver', st("In your %settings_file file you have configured @drupal to use a %driver server, however your PHP installation currently does not support this database type.", array('%settings_file' => $settings_file, '@drupal' => drupal_install_profile_name(), '%driver' => $database['driver']))); + form_set_error('driver', st("In your %settings_file file you have configured @drupal to use a %driver server, however your PHP installation currently does not support this database type.", array('%settings_file' => form_state['values']['settings_file'], '@drupal' => drupal_install_profile_name(), '%driver' => $form_state['values']['driver']))); } else { if (isset($form)) { - form_set_value($form['_database'], $database, $form_state); + form_set_value($form['_database'], $form_state['values'], $form_state); } $class = "DatabaseInstaller_$driver"; $test = new $class; - $databases = array('default' => array('default' => $database)); + $databases = array('default' => array('default' => $form_state['values'])); $return = $test->test(); if (!$return || $test->error) { if (!empty($test->success)) { Index: includes/database/sqlite/install.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/database/sqlite/install.inc,v retrieving revision 1.1 diff -u -p -r1.1 install.inc --- includes/database/sqlite/install.inc 23 Nov 2008 06:06:15 -0000 1.1 +++ includes/database/sqlite/install.inc 8 Feb 2009 21:41:15 -0000 @@ -11,5 +11,15 @@ class DatabaseInstaller_sqlite extends D public function name() { return 'SQLite'; } + + public function form_alter(&$form, $form_state, $form_id) { + if ($form_id == 'install_database_settings_form') { + unset($form['basic_options']['database']['#maxlength']); + $form['basic_options']['database']['#description'] = st('Enter a path to a sqlite file. The database will be automatically created for you.'); + $form['basic_options']['username']['#access'] = FALSE; + $form['basic_options']['password']['#access'] = FALSE; + $form['advanced_options']['#access'] = FALSE; + } + } }