Beispiel #1
0
/**
 * Helper function for install_settings_validate.
 */
function _install_settings_form_validate($database, $settings_file, &$form_state, $form = NULL)
{
    global $databases;
    // Verify the table prefix
    if (!empty($database['prefix']) && is_string($database['prefix']) && !preg_match('/^[A-Za-z0-9_.]+$/', $database['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'])) {
        form_set_error('db_port', st('Database port must be a number.'));
    }
    // Check database type
    $database_types = drupal_detect_database_types();
    $driver = $database['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'])));
    } else {
        if (isset($form)) {
            form_set_value($form['_database'], $database, $form_state);
        }
        $class = "DatabaseInstaller_{$driver}";
        $test = new $class();
        $databases = array('default' => array('default' => $database));
        $return = $test->test();
        if (!$return || $test->error) {
            if (!empty($test->success)) {
                form_set_error('db_type', st('In order for Drupal to work, and to continue with the installation process, you must resolve all permission issues reported above. We were able to verify that we have permission for the following commands: %commands. For more help with configuring your database server, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what any of this means you should probably contact your hosting provider.', array('%commands' => implode($test->success, ', '))));
            } else {
                form_set_error('driver', '');
            }
        }
    }
}
Beispiel #2
0
/**
 * Helper function for install_settings_validate.
 */
function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file, &$form_state, $form = NULL)
{
    global $db_url;
    // Verify the table prefix
    if (!empty($db_prefix) && is_string($db_prefix) && !preg_match('/^[A-Za-z0-9_.]+$/', $db_prefix)) {
        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($db_port) && !is_numeric($db_port)) {
        form_set_error('db_port', st('Database port must be a number.'));
    }
    // Check database type
    if (!isset($form)) {
        $_db_url = is_array($db_url) ? $db_url['default'] : $db_url;
        $db_type = substr($_db_url, 0, strpos($_db_url, '://'));
    }
    $databases = drupal_detect_database_types();
    if (!in_array($db_type, $databases)) {
        form_set_error('db_type', st("In your %settings_file file you have configured @drupal to use a %db_type server, however your PHP installation currently does not support this database type.", array('%settings_file' => $settings_file, '@drupal' => drupal_install_profile_name(), '%db_type' => $db_type)));
    } else {
        // Verify
        $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)) {
            form_set_value($form['_db_url'], $db_url, $form_state);
        }
        $success = array();
        $function = 'drupal_test_' . $db_type;
        if (!$function($db_url, $success)) {
            if (isset($success['CONNECT'])) {
                form_set_error('db_type', st('In order for Drupal to work, and to continue with the installation process, you must resolve all permission issues reported above. We were able to verify that we have permission for the following commands: %commands. For more help with configuring your database server, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what any of this means you should probably contact your hosting provider.', array('%commands' => implode($success, ', '))));
            } else {
                form_set_error('db_type', '');
            }
        }
    }
}
Beispiel #3
0
/**
 * Check a database connection and return any errors.
 */
function install_database_errors($database, $settings_file)
{
    global $databases;
    $errors = array();
    // Verify the table prefix
    if (!empty($database['db_prefix']) && is_string($database['db_prefix']) && !preg_match('/^[A-Za-z0-9_.]+$/', $database['db_prefix'])) {
        $errors['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' => $database['db_prefix']));
    }
    if (!empty($database['port']) && !is_numeric($database['port'])) {
        $errors['db_port'] = st('Database port must be a number.');
    }
    // Check database type
    $database_types = drupal_detect_database_types();
    $driver = $database['driver'];
    if (!isset($database_types[$driver])) {
        $errors['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']));
    } else {
        // Run tasks associated with the database type. Any errors are caught in the
        // calling function
        $databases['default']['default'] = $database;
        // Just changing the global doesn't get the new information processed.
        // We tell tell the Database class to re-parse $databases.
        Database::parseConnectionInfo();
        try {
            db_run_tasks($database['driver']);
        } catch (DatabaseTaskException $e) {
            // These are generic errors, so we do not have any specific key of the
            // database connection array to attach them to; therefore, we just put
            // them in the error array with standard numeric keys.
            $errors[] = $e->getMessage();
        }
    }
    return $errors;
}