Feature #272 - The installation scripts: An easy rework about the database connection testing button.

skala
Ivan Tcholakov 15 years ago
parent 481d3b8d12
commit a37dc7eec3
  1. 35
      main/inc/lib/database.lib.php
  2. 13
      main/install/index.php
  3. 82
      main/install/install_functions.inc.php

@ -776,6 +776,41 @@ class Database {
return mysql_free_result($result);
}
/**
* Returns the database client library version.
* @return strung Returns a string that represents the client library version.
*/
public function get_client_info() {
return mysql_get_client_info();
}
/**
* Returns information about the type of the current connection and the server host name.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return string/boolean Returns string data on success or FALSE on failure.
*/
public function get_host_info($connection = null) {
return self::use_default_connection($connection) ? mysql_get_host_info() : mysql_get_host_info($connection);
}
/**
* Retrieves database client/server protocol version.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return int/boolean Returns the protocol version on success or FALSE on failure.
*/
public function get_proto_info($connection = null) {
return self::use_default_connection($connection) ? mysql_get_proto_info() : mysql_get_proto_info($connection);
}
/**
* Retrieves the database server version.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return string/boolean Returns the MySQL server version on success or FALSE on failure.
*/
public function get_server_info($connection = null) {
return self::use_default_connection($connection) ? mysql_get_server_info() : mysql_get_server_info($connection);
}
/**
* Gets the ID of the last item inserted into the database
* @param resource $connection (optional) The database server connection, for detailed description see the method query().

@ -131,7 +131,7 @@ foreach ($_POST as $request_index => $request_value) {
$badUpdatePath = false;
$emptyUpdatePath = true;
$proposedUpdatePath = '';
if(!empty($_POST['updatePath'])) {
if (!empty($_POST['updatePath'])) {
$proposedUpdatePath = $_POST['updatePath'];
}
@ -341,8 +341,7 @@ if ($encryptPassForm == '1') {
if(init_visibility == 0) {
document.getElementById('optional_param1').style.display = '';
document.getElementById('optional_param2').style.display = '';
if(document.getElementById('optional_param3'))
{
if(document.getElementById('optional_param3')) {
document.getElementById('optional_param3').style.display = '';
}
document.getElementById('optional_param4').style.display = '';
@ -552,7 +551,7 @@ if ($_POST['step2']) {
<?php echo get_lang('DBLogin').' : '.$dbUsernameForm; ?><br />
<?php echo get_lang('DBPassword').' : '.str_repeat('*', strlen($dbPassForm)); ?><br />
<?php if (!empty($dbPrefixForm)) echo get_lang('DbPrefixForm').' : '.$dbPrefixForm.'<br />'; ?>
<?php echo get_lang('MainDB').' : <strong>'.$dbNameForm; ?></strong><?php if($installType == 'new') echo ' (<font color="#cc0033">'.get_lang('ReadWarningBelow').'</font>)'; ?><br />
<?php echo get_lang('MainDB').' : <strong>'.$dbNameForm; ?></strong><?php if ($installType == 'new') echo ' (<font color="#cc0033">'.get_lang('ReadWarningBelow').'</font>)'; ?><br />
<?php
if (!$singleDbForm) {
echo get_lang('StatDB').' : <strong>'.$dbStatsForm.'</strong>';
@ -568,10 +567,10 @@ if ($_POST['step2']) {
echo '<br />';
}
?>
<?php echo get_lang('EnableTracking').' : '.($enableTrackingForm?get_lang('Yes'):get_lang('No')); ?><br />
<?php echo get_lang('SingleDb').' : '.($singleDbForm?get_lang('One'):get_lang('Several')); ?><br /><br />
<?php echo get_lang('EnableTracking').' : '.($enableTrackingForm ? get_lang('Yes') : get_lang('No')); ?><br />
<?php echo get_lang('SingleDb').' : '.($singleDbForm ? get_lang('One') : get_lang('Several')); ?><br /><br />
<?php echo get_lang('AllowSelfReg').' : '.($allowSelfReg?get_lang('Yes'):get_lang('No')); ?><br />
<?php echo get_lang('AllowSelfReg').' : '.($allowSelfReg ? get_lang('Yes') : get_lang('No')); ?><br />
<?php echo get_lang('EncryptMethodUserPass').' : ';
echo $encryptPassForm;
?><br /><br/>

@ -269,10 +269,10 @@ function get_config_param_from_db($host, $login, $pass, $db_name, $param = '') {
}
/**
* Return a list of language directories.
* @todo function does not belong here, move to code library,
* also see infocours.php which contains similar function
*/
* Return a list of language directories.
* @todo function does not belong here, move to code library,
* also see infocours.php which contains similar function
*/
function get_language_folder_list($dirname) {
if ($dirname[strlen($dirname)-1] != '/') {
$dirname .= '/';
@ -359,7 +359,7 @@ function display_language_selection() { ?>
*
* @author unknow
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/
*/
function display_requirements($installType, $badUpdatePath, $updatePath = '', $update_from_version_8 = array(), $update_from_version_6 = array()) {
echo '<h2>'.display_step_sequence().get_lang('Requirements')."</h2>\n";
@ -633,12 +633,14 @@ function display_requirements($installType, $badUpdatePath, $updatePath = '', $u
echo '</ul>';
echo '</div>';
}
// check wether a Dokeos configuration file already exists.
elseif(file_exists('../inc/conf/configuration.php')) {
// check wether a Chamilo configuration file already exists.
elseif (file_exists('../inc/conf/configuration.php')) {
echo '<div style="color:red; background-color:white; font-weight:bold; text-align:center;">';
echo get_lang('WarningExistingDokeosInstallationDetected');
echo '</div>';
}
//and now display the choice buttons (go back or install)
?>
<p align="center">
@ -662,10 +664,10 @@ function display_requirements($installType, $badUpdatePath, $updatePath = '', $u
}
/**
* Displays the license (GNU GPL) as step 2, with
* - an "I accept" button named step3 to proceed to step 3;
* - a "Back" button named step1 to go back to the first step.
*/
* Displays the license (GNU GPL) as step 2, with
* - an "I accept" button named step3 to proceed to step 3;
* - a "Back" button named step1 to go back to the first step.
*/
function display_license_agreement() {
echo '<h2>'.display_step_sequence().get_lang('Licence').'</h2>';
echo '<p>'.get_lang('DokeosLicenseInfo').'</p>';
@ -696,19 +698,18 @@ function display_license_agreement() {
}
/**
* Displays a parameter in a table row.
* Used by the display_database_settings_form function.
* @param string Type of install
* @param string Name of parameter
* @param string Field name (in the HTML form)
* @param string Field value
* @param string Extra notice (to show on the right side)
* @param boolean Whether to display in update mode
* @param string Additional attribute for the <tr> element
* @return void Direct output
*/
function display_database_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $extra_notice, $display_when_update = true, $tr_attribute = '')
{
* Displays a parameter in a table row.
* Used by the display_database_settings_form function.
* @param string Type of install
* @param string Name of parameter
* @param string Field name (in the HTML form)
* @param string Field value
* @param string Extra notice (to show on the right side)
* @param boolean Whether to display in update mode
* @param string Additional attribute for the <tr> element
* @return void Direct output
*/
function display_database_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $extra_notice, $display_when_update = true, $tr_attribute = '') {
echo "<tr ".$tr_attribute.">\n";
echo "<td>$parameter_name&nbsp;&nbsp;</td>\n";
if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update) {
@ -863,16 +864,17 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo
<td><button type="submit" class="login" name="step3" value="<?php echo get_lang('CheckDatabaseConnection'); ?>" ><?php echo get_lang('CheckDatabaseConnection'); ?></button></td>
<?php
$dbConnect = test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm);
if ($dbConnect==1): ?>
if ($dbConnect == 1): ?>
<td colspan="2">
<div class="confirmation-message">
<!--<div style="float:left; margin-right:10px;">
<img src="../img/message_confirmation.png" alt="Confirmation" />
</div>-->
<!--<div style="float:left;">-->
MySQL host info: <?php echo mysql_get_host_info(); ?><br />
MySQL server version: <?php echo mysql_get_server_info(); ?><br />
MySQL protocol version: <?php echo mysql_get_proto_info(); ?>
MySQL host info: <?php echo Database::get_host_info(); ?><br />
MySQL server version: <?php echo Database::get_server_info(); ?><br />
MySQL client version: <?php echo Database::get_client_info(); ?><br />
MySQL protocol version: <?php echo Database::get_proto_info(); ?>
<!--</div>-->
<div style="clear:both;"></div>
</div>
@ -884,8 +886,8 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo
<img src="../img/message_error.png" alt="Error" />
</div>-->
<div style="float:left;">
<strong>MySQL error: <?php echo mysql_errno(); ?></strong><br />
<?php echo mysql_error().'<br/>'; ?>
<strong>MySQL 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>
@ -902,9 +904,9 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo
}
/**
* Displays a parameter in a table row.
* Used by the display_configuration_settings_form function.
*/
* Displays a parameter in a table row.
* Used by the display_configuration_settings_form function.
*/
function display_configuration_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $display_when_update = 'true') {
echo "<tr>\n";
echo "<td>$parameter_name&nbsp;&nbsp;</td>\n";
@ -1093,8 +1095,8 @@ function display_configuration_settings_form($installType, $urlForm, $languageFo
}
/**
* After installation is completed (step 6), this message is displayed.
*/
* After installation is completed (step 6), this message is displayed.
*/
function display_after_install_message($installType, $nbr_courses) {
?>
<h2><?php echo display_step_sequence() . get_lang("CfgSetting"); ?></h2>
@ -1116,16 +1118,17 @@ function display_after_install_message($installType, $nbr_courses) {
echo '</div>';
?>
</form>
<a class="portal" href="../../index.php"><?php echo get_lang('GoToYourNewlyCreatedPortal'); ?></a>
<?php
}
/**
* In step 3. Test the connection to the DB in case of single or multy DB.
* Return "1"if no problems, "0" if, in case of multiDB we can't create a new DB and "-1" if there is no connection.
*/
* In step 3. Tests establishing connection to the database server. Tests also the possibility for multiple databases configuration.
* @return int 1 when there is no problem;
* 0 when a new database is impossible to be created, then the multiple databases configuration is impossible too;
* -1 when there is no connection established.
*/
function test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm) {
$dbConnect = -1;
if ($singleDbForm == 1) {
@ -1142,7 +1145,6 @@ function test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbFor
if ($res !== false) {
// The system has not been designed to use special SQL modes that were introduced since MySQL 5
@mysql_query("set session sql_mode='';");
$multipleDbCheck = @mysql_query("CREATE DATABASE ".$dbPrefixForm."test_dokeos_connection");
if ($multipleDbCheck !== false) {
$multipleDbCheck = @mysql_query("DROP DATABASE IF EXISTS ".$dbPrefixForm."test_dokeos_connection");

Loading…
Cancel
Save