Improving installation DB errors messages see #4219

skala
Julio Montoya 14 years ago
parent e4917b85fa
commit 670fbb9a6c
  1. 2
      main/inc/lib/database.lib.php
  2. 8
      main/install/index.php
  3. 49
      main/install/install.lib.php
  4. 5
      main/install/install_db.inc.php
  5. 4
      main/lang/english/install.inc.php

@ -1338,7 +1338,7 @@ class Database {
}
}
return false;
}
}
/*
DEPRECATED METHODS

@ -742,11 +742,12 @@ if ($_POST['step2']) {
$perm_file = api_get_permissions_for_new_files();
if (empty($my_old_version)) { $my_old_version = '1.8.6.2'; } //we guess
$_configuration['main_database'] = $dbNameForm;
//$urlAppendPath = get_config_param('urlAppend');
error_log('Starting migration process from '.$my_old_version.' ('.time().')', 0);
error_log('Starting migration process from '.$my_old_version.' ('.time().')', 0);
if ($userPasswordCrypted == '1') {
if ($userPasswordCrypted == '1') {
$userPasswordCrypted = 'md5';
} elseif ($userPasswordCrypted == '0') {
$userPasswordCrypted = 'none';
@ -822,7 +823,8 @@ if ($_POST['step2']) {
default:
break;
}
} else {
} else {
set_file_folder_permissions();
database_server_connect();

@ -597,12 +597,19 @@ function database_server_connect() {
@Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
}
/**
* Database exists for the MYSQL user
* @param type $database_name
* @return boolean
*/
function database_exists($database_name) {
$select_database = Database::select_db($database_name);
$show_database = false;
$result = @Database::query("SHOW DATABASES LIKE '".Database::escape_string($database_name)."' ");
if (Database::num_rows($result)) {
return true;
}
return false;
$show_database = true;
}
return $select_database || $show_database;
}
/**
@ -618,7 +625,7 @@ function test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbFor
$dbConnect = -1;
//Checking user credentials
if (@Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm)) !== false) {
$check_user_can_create_databases = true;
//$check_user_can_create_databases = true;
//Checking if single database exist
/*if ($singleDbForm) {
@ -653,7 +660,7 @@ function test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbFor
} else {
$dbConnect = -1;
}
return $dbConnect; //return "1"if no problems, "0" if, in case we can't create a new DB and "-1" if there is no connection.
return $dbConnect; //return 1, if no problems, "0" if, in case we can't create a new DB and "-1" if there is no connection.
}
/**
@ -1731,9 +1738,35 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo
<?php echo get_lang('CheckDatabaseConnection'); ?></button>
</td>
<?php
$dbConnect = test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm, $dbNameForm);
if (database_exists($dbNameForm)) {
$database_exists_text = '<div class="normal-message">'.get_lang('ADatabaseWithTheSameNameAlreadyExists').'</div>';
} else {
if (!$dbConnect) {
$database_exists_text = '<div class="warning-message">'.sprintf(get_lang('UserXCantHaveAccessInTheDatabaseX'), $dbNameForm, $dbUsernameForm).'</div>';
} else {
//Try to create the database
$user_can_create_databases = false;
$multipleDbCheck = @Database::query("CREATE DATABASE test_chamilo_connection");
if ($multipleDbCheck !== false) {
$multipleDbCheck = @Database::query("DROP DATABASE IF EXISTS test_chamilo_connection");
$user_can_create_databases = true;
}
if ($user_can_create_databases) {
$database_exists_text = '<div class="normal-message">'.sprintf(get_lang('DatabaseXWillBeCreated'), $dbNameForm, $dbUsernameForm).'</div>';
} else {
$dbConnect = 0;
$database_exists_text = '<div class="warning-message">'.sprintf(get_lang('DatabaseXCantBeCreatedUserXDoestHaveEnoughtPermissions'), $dbNameForm, $dbUsernameForm).'</div>';
}
}
}
if ($dbConnect == 1): ?>
<td colspan="2">
<?php echo $database_exists_text ?>
<div id="db_status" class="confirmation-message">
Database host: <strong><?php echo Database::get_host_info(); ?></strong><br />
Database server version: <strong><?php echo Database::get_server_info(); ?></strong><br />
@ -1742,13 +1775,15 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo
<div style="clear:both;"></div>
</div>
</td>
<?php else: ?>
<?php else: ?>
<td colspan="2">
<?php echo $database_exists_text ?>
<div id="db_status" style="float:left;" class="error-message">
<div style="float:left;">
<strong><?php echo get_lang('FailedConectionDatabase'); ?></strong><br />
<strong>Database error: <?php echo Database::errno(); ?></strong><br />
<?php echo Database::error().'<br />'; ?>
<strong><?php echo get_lang('Details').': '. get_lang('FailedConectionDatabase'); ?></strong><br />
</div>
</div>
</td>

@ -132,6 +132,7 @@ if (!defined('CLI_INSTALLATION')) {
/**
* Creating the tables of the main database
*/
Database::select_db($mysqlMainDb) or die(Database::error());
$installation_settings['{ORGANISATIONNAME}'] = $institutionForm;
@ -149,13 +150,13 @@ $installation_settings['{ADMINPHONE}'] = $adminPhoneForm;
$installation_settings['{PLATFORM_AUTH_SOURCE}'] = PLATFORM_AUTH_SOURCE;
$installation_settings['{ADMINLANGUAGE}'] = $languageForm;
$installation_settings['{HASHFUNCTIONMODE}'] = $encryptPassForm;
load_main_database($installation_settings);
load_main_database($installation_settings);
//Adds the c_XXX courses tables see #3910
require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
update_Db_course();
update_Db_course();
/**
* Creating the tables of the tracking database

@ -125,4 +125,8 @@ $PHPVersionError = "Your PHP version does not match the requirements for this so
$ExtensionSessionsNotAvailable = "Sessions extension not available";
$ExtensionZlibNotAvailable = "Zlib extension not available";
$ExtensionPCRENotAvailable = "PCRE extension not available";
$DatabaseXWillBeCreated = "Database <b>%s</b> will be created";
$ADatabaseWithTheSameNameAlreadyExistsGoOnOrCheckTheDatabase = "A database with the same name <b>already exists</b>. The contents in the database will be lost.";
$UserXCantHaveAccessInTheDatabaseX = "User <b>%s</b> can't have access in the database <b>%s</b>";
$DatabaseXCantBeCreatedUserXDoestHaveEnoughtPermissions = "Database <b>%s</b> can't be created user <b>%s</b> doesn't have enought permissions";
?>
Loading…
Cancel
Save