summaryrefslogtreecommitdiff
path: root/includes/install.inc
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-11-29 02:55:57 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-11-29 02:55:57 +0000
commitff119bc0ccfa224279456c901904955a6b1f4d05 (patch)
tree7219f746418770bc7082236f9ddc031ba82042a8 /includes/install.inc
parent3d353c47fab804d22411bdfa87407b81a4a415c6 (diff)
downloadbrdo-ff119bc0ccfa224279456c901904955a6b1f4d05.tar.gz
brdo-ff119bc0ccfa224279456c901904955a6b1f4d05.tar.bz2
#346494 by hswong3i, Pancho, Dave Reid, duellj, dalin: Fixed DB drivers need to be able to change the configure database form during install
Diffstat (limited to 'includes/install.inc')
-rw-r--r--includes/install.inc127
1 files changed, 126 insertions, 1 deletions
diff --git a/includes/install.inc b/includes/install.inc
index 6e0b7dc7b..2c9810a08 100644
--- a/includes/install.inc
+++ b/includes/install.inc
@@ -230,6 +230,22 @@ function drupal_detect_baseurl($file = 'install.php') {
* An array of database types compiled into PHP.
*/
function drupal_detect_database_types() {
+ $databases = drupal_get_database_types();
+
+ foreach ($databases as $driver => $installer) {
+ $databases[$driver] = $installer->name();
+ }
+
+ return $databases;
+}
+
+/**
+ * Return all supported database installer objects that are compiled into PHP.
+ *
+ * @return
+ * An array of database installer objects compiled into PHP.
+ */
+function drupal_get_database_types() {
$databases = array();
// We define a driver as a directory in /includes/database that in turn
@@ -249,7 +265,7 @@ function drupal_detect_database_types() {
$class = 'DatabaseTasks_' . $driver;
$installer = new $class();
if ($installer->installable()) {
- $databases[$driver] = $installer->name();
+ $databases[$driver] = $installer;
}
}
@@ -445,7 +461,116 @@ abstract class DatabaseTasks {
$this->fail(st("The database version %version is less than the minimum required version %minimum_version.", array('%version' => Database::getConnection()->version(), '%minimum_version' => $this->minimumVersion())));
}
}
+
+ /**
+ * Return driver specific configuration options.
+ *
+ * @param $database
+ * An array of driver specific configuration options.
+ *
+ * @return
+ * The options form array.
+ */
+ public function getFormOptions($database) {
+ $form['database'] = array(
+ '#type' => 'textfield',
+ '#title' => st('Database name'),
+ '#default_value' => empty($database['database']) ? '' : $database['database'],
+ '#size' => 45,
+ '#required' => TRUE,
+ '#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_distribution_name())),
+ );
+
+ $form['username'] = array(
+ '#type' => 'textfield',
+ '#title' => st('Database username'),
+ '#default_value' => empty($database['username']) ? '' : $database['username'],
+ '#required' => TRUE,
+ '#size' => 45,
+ );
+
+ $form['password'] = array(
+ '#type' => 'password',
+ '#title' => st('Database password'),
+ '#default_value' => empty($database['password']) ? '' : $database['password'],
+ '#required' => FALSE,
+ '#size' => 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."),
+ '#weight' => 10,
+ );
+
+ $profile = drupal_get_profile();
+ $db_prefix = ($profile == 'standard') ? 'drupal_' : $profile . '_';
+ $form['advanced_options']['db_prefix'] = array(
+ '#type' => 'textfield',
+ '#title' => st('Table prefix'),
+ '#default_value' => '',
+ '#size' => 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_distribution_name(), '%prefix' => $db_prefix)),
+ '#weight' => 10,
+ );
+
+ $form['advanced_options']['host'] = array(
+ '#type' => 'textfield',
+ '#title' => st('Database host'),
+ '#default_value' => empty($database['host']) ? 'localhost' : $database['host'],
+ '#size' => 45,
+ // Hostnames can be 255 characters long.
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#description' => st('If your database is located on a different server, change this.'),
+ );
+
+ $form['advanced_options']['port'] = array(
+ '#type' => 'textfield',
+ '#title' => st('Database port'),
+ '#default_value' => empty($database['port']) ? '' : $database['port'],
+ '#size' => 45,
+ // The maximum port number is 65536, 5 digits.
+ '#maxlength' => 5,
+ '#description' => st('If your database server is listening to a non-standard port, enter its number.'),
+ );
+
+ return $form;
+ }
+
+ /**
+ * Validates driver specific configuration settings.
+ *
+ * Checks to ensure correct basic database settings and that a proper
+ * connection to the database can be established.
+ *
+ * @param $database
+ * An array of driver specific configuration options.
+ *
+ * @return
+ * An array of driver configuration errors, keyed by form element name.
+ */
+ public function validateDatabaseSettings($database) {
+ $errors = array();
+
+ // Verify the table prefix.
+ if (!empty($database['prefix']) && is_string($database['prefix']) && !preg_match('/^[A-Za-z0-9_.]+$/', $database['prefix'])) {
+ $errors[$database['driver'] . '][advanced_options][db_prefix'] = st('The database table prefix you have entered, %prefix, is invalid. The table prefix can only contain alphanumeric characters, periods, or underscores.', array('%prefix' => $database['prefix']));
+ }
+
+ // Verify the database port.
+ if (!empty($database['port']) && !is_numeric($database['port'])) {
+ $errors[$database['driver'] . '][advanced_options][port'] = st('Database port must be a number.');
+ }
+
+ return $errors;
+ }
+
}
+
/**
* @class Exception class used to throw error if the DatabaseInstaller fails.
*/