Using Doctrine as a DB layer.

1.10.x
Julio Montoya 11 years ago
parent a40a7f6903
commit a91a2fa35f
  1. 39
      main/inc/global.inc.php
  2. 60
      main/inc/lib/database.lib.php
  3. 252
      main/install/index.php
  4. 135
      main/install/install.lib.php
  5. 15
      main/install/install_db.inc.php

@ -158,41 +158,9 @@ $dbParams = array(
'dbname' => $_configuration['main_database'],
);
$config = Database::getDoctrineConfig();
$config->setEntityNamespaces(
array(
'ChamiloUserBundle' => 'Chamilo\UserBundle\Entity',
'ChamiloCoreBundle' => 'Chamilo\CoreBundle\Entity',
'ChamiloCourseBundle' => 'Chamilo\CourseBundle\Entity'
)
);
$entityManager = EntityManager::create($dbParams, $config);
// Registering Constraints
use Doctrine\Common\Annotations\AnnotationRegistry;
AnnotationRegistry::registerAutoloadNamespace(
'Symfony\Component\Validator\Constraint',
api_get_path(SYS_PATH)."vendor/symfony/validator"
);
AnnotationRegistry::registerFile(
api_get_path(SYS_PATH)."vendor/symfony/doctrine-bridge/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php"
);
// Registering gedmo extensions
AnnotationRegistry::registerAutoloadNamespace(
'Gedmo\Mapping\Annotation',
api_get_path(SYS_PATH)."vendor/gedmo/doctrine-extensions/lib"
);
/*$repo = $entityManager->getRepository('ChamiloCoreBundle:Session');
$repo = $entityManager->getRepository('ChamiloUserBundle:User');
$repo = $entityManager->getRepository('ChamiloCoreBundle:Course');*/
try {
$connect = $entityManager->getConnection()->connect();
$database = new \Database();
$database->connect($dbParams);
} catch (Exception $e) {
$global_error_code = 3;
// The database server is not available or credentials are invalid.
@ -200,9 +168,6 @@ try {
die();
}
$database = new \Database();
$database->setManager($entityManager);
/* RETRIEVING ALL THE CHAMILO CONFIG SETTINGS FOR MULTIPLE URLs FEATURE*/
if (!empty($_configuration['multiple_access_urls'])) {
$_configuration['access_url'] = 1;

@ -4,6 +4,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\Common\Annotations\AnnotationRegistry;
/**
* Class Database
@ -54,13 +55,9 @@ class Database
*
* @param string $short_table_name, the name of the table
*/
public static function get_main_table($short_table_name)
public static function get_main_table($table)
{
return $short_table_name;
/*
return self::format_table_name(
self::get_main_database(),
$short_table_name);*/
return $table;
}
/**
@ -74,9 +71,9 @@ class Database
* @param string $database_name, optional, name of the course database
* - if you don't specify this, you work on the current course.
*/
public static function get_course_table($short_table_name, $extra = null)
public static function get_course_table($table, $extra = null)
{
return DB_COURSE_PREFIX.$short_table_name;
return DB_COURSE_PREFIX.$table;
/*
//forces fatal errors so we can debug more easily
if (!empty($extra)) {
@ -129,19 +126,42 @@ class Database
}
/**
* Opens a connection to a database server.
* @param array $parameters (optional) An array that contains the necessary parameters for accessing the server.
* @return resource/boolean Returns a database connection on success or FALSE on failure.
* Note: Currently the array could contain MySQL-specific parameters:
* $parameters['server'], $parameters['username'], $parameters['password'],
* $parameters['new_link'], $parameters['client_flags'], $parameters['persistent'].
* For details see documentation about the functions mysql_connect() and mysql_pconnect().
* @link http://php.net/manual/en/function.mysql-connect.php
* @link http://php.net/manual/en/function.mysql-pconnect.php
* @param array $params
* @throws \Doctrine\ORM\ORMException
*/
public static function connect($parameters = array()) {
public function connect($params = array())
{
$config = self::getDoctrineConfig();
$config->setEntityNamespaces(
array(
'ChamiloUserBundle' => 'Chamilo\UserBundle\Entity',
'ChamiloCoreBundle' => 'Chamilo\CoreBundle\Entity',
'ChamiloCourseBundle' => 'Chamilo\CourseBundle\Entity'
)
);
$entityManager = EntityManager::create($params, $config);
// Registering Constraints
AnnotationRegistry::registerAutoloadNamespace(
'Symfony\Component\Validator\Constraint',
api_get_path(SYS_PATH)."vendor/symfony/validator"
);
AnnotationRegistry::registerFile(
api_get_path(SYS_PATH)."vendor/symfony/doctrine-bridge/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php"
);
// Registering gedmo extensions
AnnotationRegistry::registerAutoloadNamespace(
'Gedmo\Mapping\Annotation',
api_get_path(SYS_PATH)."vendor/gedmo/doctrine-extensions/lib"
);
$this->setManager($entityManager);
// A MySQL-specific implementation.
if (!isset($parameters['server'])) {
/*if (!isset($parameters['server'])) {
$parameters['server'] = @ini_get('mysql.default_host');
if (empty($parameters['server'])) {
$parameters['server'] = 'localhost:3306';
@ -169,7 +189,7 @@ class Database
$client_flags = isset($parameters['client_flags']) ? $parameters['client_flags'] : null;
return $persistent
? mysql_pconnect($server, $username, $password, $client_flags)
: mysql_connect($server, $username, $password, $new_link, $client_flags);
: mysql_connect($server, $username, $password, $new_link, $client_flags);*/
}
/**

@ -18,11 +18,11 @@
use \ChamiloSession as Session;
define('SYSTEM_INSTALLATION', 1);
define('INSTALL_TYPE_UPDATE', 'update');
define('FORM_FIELD_DISPLAY_LENGTH', 40);
define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25);
define('MAX_FORM_FIELD_LENGTH', 80);
define('SYSTEM_INSTALLATION', 1);
define('INSTALL_TYPE_UPDATE', 'update');
define('FORM_FIELD_DISPLAY_LENGTH', 40);
define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25);
define('MAX_FORM_FIELD_LENGTH', 80);
/* PHP VERSION CHECK */
@ -76,7 +76,6 @@ if (!array_key_exists($install_language, get_language_folder_list())) {
// Loading language files.
require api_get_path(SYS_LANG_PATH).'english/trad4all.inc.php';
require api_get_path(SYS_LANG_PATH).'english/admin.inc.php';
require api_get_path(SYS_LANG_PATH).'english/install.inc.php';
if ($install_language != 'english') {
include_once api_get_path(SYS_LANG_PATH).$install_language.'/trad4all.inc.php';
@ -105,10 +104,9 @@ error_reporting(E_ALL);
// Overriding the timelimit (for large campusses that have to be migrated).
@set_time_limit(0);
// Upgrading from any subversion of 1.6 is just like upgrading from 1.6.5
$update_from_version_6 = array('1.6', '1.6.1', '1.6.2', '1.6.3', '1.6.4', '1.6.5');
// Upgrading from any subversion of 1.8 avoids the additional step of upgrading from 1.6
$update_from_version_8 = array('1.8', '1.8.2', '1.8.3', '1.8.4', '1.8.5', '1.8.6', '1.8.6.1', '1.8.6.2','1.8.7','1.8.7.1','1.8.8','1.8.8.2', '1.8.8.4', '1.8.8.6', '1.9.0', '1.9.2','1.9.4','1.9.6', '1.9.6.1', '1.9.8', '1.9.8.1', '1.9.8.2', '1.9.10');
$update_from_version_6 = array();
// Upgrading from any subversion of 1.9
$update_from_version_8 = array('1.9.0', '1.9.2','1.9.4','1.9.6', '1.9.6.1', '1.9.8', '1.9.8.1', '1.9.8.2', '1.9.10');
$my_old_version = '';
$tmp_version = get_config_param('dokeos_version');
@ -138,13 +136,13 @@ if (isAlreadyInstalledSystem()) {
// Is valid request
$is_valid_request = isset($_REQUEST['is_executable']) ? $_REQUEST['is_executable'] : null;
foreach ($_POST as $request_index => $request_value) {
/*foreach ($_POST as $request_index => $request_value) {
if (substr($request_index, 0, 4) == 'step') {
if ($request_index != $is_valid_request) {
unset($_POST[$request_index]);
}
}
}
}*/
$badUpdatePath = false;
$emptyUpdatePath = true;
@ -214,7 +212,6 @@ if (!isset($_GET['running'])) {
$dbPassForm = '';
$dbPrefixForm = '';
$dbNameForm = 'chamilo';
$dbStatsForm = 'chamilo';
$dbScormForm = 'chamilo';
$dbUserForm = 'chamilo';
@ -223,11 +220,10 @@ if (!isset($_GET['running'])) {
$urlAppendPath = api_remove_trailing_slash(api_get_path(REL_PATH));
$urlForm = api_get_path(WEB_PATH);
$pathForm = api_get_path(SYS_PATH);
$emailForm = 'webmaster@localhost';
if (!empty($_SERVER['SERVER_ADMIN'])) {
$emailForm = $_SERVER['SERVER_ADMIN'];
}
$emailForm = 'webmaster@localhost';
if (!empty($_SERVER['SERVER_ADMIN'])) {
$emailForm = $_SERVER['SERVER_ADMIN'];
}
$email_parts = explode('@', $emailForm);
if (isset($email_parts[1]) && $email_parts[1] == 'localhost') {
$emailForm .= '.localdomain';
@ -242,8 +238,6 @@ if (!isset($_GET['running'])) {
$adminPhoneForm = '(000) 001 02 03';
$institutionForm = 'My Organisation';
$institutionUrlForm = 'http://www.chamilo.org';
// TODO: A better choice to be tested:
//$languageForm = 'english';
$languageForm = api_get_interface_language();
$checkEmailByHashSent = 0;
@ -300,6 +294,7 @@ if ($encryptPassForm == '1') {
} elseif ($encryptPassForm == '0') {
$encryptPassForm = 'none';
}
?>
<!DOCTYPE html>
<head>
@ -320,15 +315,15 @@ if ($encryptPassForm == '1') {
//checked
if ($('#singleDb1').attr('checked')==false) {
//$('#dbStatsForm').removeAttr('disabled');
//$('#dbUserForm').removeAttr('disabled');
$('#dbStatsForm').attr('value','chamilo_main');
$('#dbUserForm').attr('value','chamilo_main');
//$('#dbStatsForm').removeAttr('disabled');
//$('#dbUserForm').removeAttr('disabled');
$('#dbStatsForm').attr('value','chamilo_main');
$('#dbUserForm').attr('value','chamilo_main');
} else if($('#singleDb1').attr('checked')==true){
//$('#dbStatsForm').attr('disabled','disabled');
//$('#dbUserForm').attr('disabled','disabled');
$('#dbStatsForm').attr('value','chamilo_main');
$('#dbUserForm').attr('value','chamilo_main');
//$('#dbStatsForm').attr('disabled','disabled');
//$('#dbUserForm').attr('disabled','disabled');
$('#dbStatsForm').attr('value','chamilo_main');
$('#dbUserForm').attr('value','chamilo_main');
}
$("button").addClass('btn btn-default');
@ -407,11 +402,11 @@ if ($encryptPassForm == '1') {
$(document).ready( function() {
$(".advanced_parameters").click(function() {
if ($("#id_contact_form").css("display") == "none") {
$("#id_contact_form").css("display","block");
$("#img_plus_and_minus").html('&nbsp;<img src="<?php echo api_get_path(WEB_IMG_PATH) ?>div_hide.gif" alt="<?php echo get_lang('Hide') ?>" title="<?php echo get_lang('Hide')?>" style ="vertical-align:middle" >&nbsp;<?php echo get_lang('ContactInformation') ?>');
$("#id_contact_form").css("display","block");
$("#img_plus_and_minus").html('&nbsp;<img src="<?php echo api_get_path(WEB_IMG_PATH) ?>div_hide.gif" alt="<?php echo get_lang('Hide') ?>" title="<?php echo get_lang('Hide')?>" style ="vertical-align:middle" >&nbsp;<?php echo get_lang('ContactInformation') ?>');
} else {
$("#id_contact_form").css("display","none");
$("#img_plus_and_minus").html('&nbsp;<img src="<?php echo api_get_path(WEB_IMG_PATH) ?>div_show.gif" alt="<?php echo get_lang('Show') ?>" title="<?php echo get_lang('Show') ?>" style ="vertical-align:middle" >&nbsp;<?php echo get_lang('ContactInformation') ?>');
$("#id_contact_form").css("display","none");
$("#img_plus_and_minus").html('&nbsp;<img src="<?php echo api_get_path(WEB_IMG_PATH) ?>div_show.gif" alt="<?php echo get_lang('Show') ?>" title="<?php echo get_lang('Show') ?>" style ="vertical-align:middle" >&nbsp;<?php echo get_lang('ContactInformation') ?>');
}
});
});
@ -429,21 +424,21 @@ if ($encryptPassForm == '1') {
data_post += "financial_decision="+$("input[@name='financial_decision']:checked").val();
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) {},
type: "POST",
url: "<?php echo api_get_path(WEB_AJAX_PATH) ?>install.ajax.php?a=send_contact_information",
data: data_post,
success: function(datos) {
if (datos == 'required_field_error') {
message = "<?php echo get_lang('FormHasErrorsPleaseComplete') ?>";
} else if (datos == '1') {
message = "<?php echo get_lang('ContactInformationHasBeenSent') ?>";
} else {
message = "<?php echo get_lang('Error').': '.get_lang('ContactInformationHasNotBeenSent') ?>";
}
alert(message);
}
contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) {},
type: "POST",
url: "<?php echo api_get_path(WEB_AJAX_PATH) ?>install.ajax.php?a=send_contact_information",
data: data_post,
success: function(datos) {
if (datos == 'required_field_error') {
message = "<?php echo get_lang('FormHasErrorsPleaseComplete') ?>";
} else if (datos == '1') {
message = "<?php echo get_lang('ContactInformationHasBeenSent') ?>";
} else {
message = "<?php echo get_lang('Error').': '.get_lang('ContactInformationHasNotBeenSent') ?>";
}
alert(message);
}
});
}
</script>
@ -451,11 +446,11 @@ if ($encryptPassForm == '1') {
</head>
<body dir="<?php echo api_get_text_direction(); ?>" class="install-chamilo">
<div id="wrapper">
<div id="page-wrap">
<div id="main" class="container well-install">
<header>
<div class="row">
<div id="header_left" class="span4">
<div id="header_left" class="col-md-4">
<div id="logo">
<img src="../css/chamilo/images/header-logo.png" hspace="10" vspace="10" alt="Chamilo" />
</div>
@ -481,7 +476,7 @@ if ($encryptPassForm == '1') {
echo '<div class="page-header"><h1>'.get_lang('ChamiloInstallation').' &ndash; '.get_lang('Version_').' '.$new_version.'</h1></div>';
?>
<div class="row">
<div class="span3">
<div class="col-md-3">
<div class="well">
<ol>
<li <?php step_active('1'); ?>><?php echo get_lang('InstallationLanguage'); ?></li>
@ -500,9 +495,9 @@ if ($encryptPassForm == '1') {
</div>
</div>
<div class="span9">
<div class="col-md-9">
<form class="form-horizontal" id="install_form" style="padding: 0px; margin: 0px;" method="post" action="<?php echo api_get_self(); ?>?running=1&amp;installType=<?php echo $installType; ?>&amp;updateFromConfigFile=<?php echo urlencode($updateFromConfigFile); ?>">
<form class="form-horizontal" id="install_form" method="post" action="<?php echo api_get_self(); ?>?running=1&amp;installType=<?php echo $installType; ?>&amp;updateFromConfigFile=<?php echo urlencode($updateFromConfigFile); ?>">
<?php
$instalation_type_label = '';
@ -562,12 +557,25 @@ if ($encryptPassForm == '1') {
<input type="hidden" name="old_version" value="<?php echo api_htmlentities($my_old_version, ENT_QUOTES); ?>" />
<input type="hidden" name="new_version" value="<?php echo api_htmlentities($new_version, ENT_QUOTES); ?>" />
<?php
if (@$_POST['step2']) {
//STEP 3 : LICENSE
display_license_agreement();
} elseif (@$_POST['step3']) {
//STEP 4 : MYSQL DATABASE SETTINGS
display_database_settings_form($installType, $dbHostForm, $dbUsernameForm, $dbPassForm, $dbPrefixForm, $enableTrackingForm, $singleDbForm, $dbNameForm, $dbStatsForm, $dbScormForm, $dbUserForm);
display_database_settings_form(
$installType,
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
$dbPrefixForm,
$enableTrackingForm,
$singleDbForm,
$dbNameForm,
$dbStatsForm,
$dbScormForm,
$dbUserForm
);
} elseif (@$_POST['step4']) {
//STEP 5 : CONFIGURATION SETTINGS
@ -634,7 +642,24 @@ if (@$_POST['step2']) {
if (!empty($tmp)) $allowSelfRegProf = $tmp;
}
}
display_configuration_settings_form($installType, $urlForm, $languageForm, $emailForm, $adminFirstName, $adminLastName, $adminPhoneForm, $campusForm, $institutionForm, $institutionUrlForm, $encryptPassForm, $allowSelfReg, $allowSelfRegProf, $loginForm, $passForm);
display_configuration_settings_form(
$installType,
$urlForm,
$languageForm,
$emailForm,
$adminFirstName,
$adminLastName,
$adminPhoneForm,
$campusForm,
$institutionForm,
$institutionUrlForm,
$encryptPassForm,
$allowSelfReg,
$allowSelfRegProf,
$loginForm,
$passForm
);
} elseif (@$_POST['step5']) {
//STEP 6 : LAST CHECK BEFORE INSTALL
@ -665,30 +690,7 @@ if (@$_POST['step2']) {
<?php echo get_lang('DBHost').' : '.$dbHostForm; ?><br />
<?php echo get_lang('DBLogin').' : '.$dbUsernameForm; ?><br />
<?php echo get_lang('DBPassword').' : '.str_repeat('*', api_strlen($dbPassForm)); ?><br />
<?php //echo get_lang('DbPrefixForm').' : '.$dbPrefixForm.'<br />'; ?>
<?php echo get_lang('MainDB').' : <strong>'.$dbNameForm; ?></strong>
<?php
if (!$singleDbForm) {
//Showing this data only in case a user migrates from a 3 main databases (main, user, tracking)
//@todo should be removed
if ($installType == 'update') {
echo '<br />';
echo get_lang('StatDB').' : <strong>'.$dbStatsForm.'</strong>';
if ($installType == 'new') {
echo ' (<font color="#cc0033">'.get_lang('ReadWarningBelow').'</font>)';
}
echo '<br />';
echo get_lang('UserDB').' : <strong>'.$dbUserForm.'</strong>';
if ($installType == 'new') {
echo ' (<font color="#cc0033">'.get_lang('ReadWarningBelow').'</font>)';
}
echo '<br />';
}
}
//echo get_lang('EnableTracking').' : '.($enableTrackingForm ? get_lang('Yes') : get_lang('No')); ?>
<?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('EncryptMethodUserPass').' : ';
echo $encryptPassForm;
@ -716,7 +718,9 @@ if (@$_POST['step2']) {
<table width="100%">
<tr>
<td>
<button type="submit" class="btn btn-default" name="step4" value="&lt; <?php echo get_lang('Previous'); ?>" ><i class="fa fa-backward"> </i> <?php echo get_lang('Previous'); ?></button>
<button type="submit" class="btn btn-default" name="step4" value="&lt; <?php echo get_lang('Previous'); ?>" >
<i class="fa fa-backward"> </i> <?php echo get_lang('Previous'); ?>
</button>
</td>
<td align="right">
<input type="hidden" name="is_executable" id="is_executable" value="-" />
@ -732,9 +736,7 @@ if (@$_POST['step2']) {
<?php
} elseif (@$_POST['step6']) {
//STEP 6 : INSTALLATION PROCESS
$current_step = 7;
$msg = get_lang('InstallExecution');
if ($installType == 'update') {
@ -745,7 +747,6 @@ if (@$_POST['step2']) {
<div id="pleasewait" class="warning-message">'.get_lang('PleaseWaitThisCouldTakeAWhile').'</div>
</div>';
// Push the web server to send these strings before we start the real
// installation process
flush();
@ -755,9 +756,16 @@ if (@$_POST['step2']) {
}
if ($installType == 'update') {
remove_memory_and_time_limits();
database_server_connect();
//database_server_connect();
$manager = testDbConnect(
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
$dbNameForm
);
// Initialization of the database connection encoding intentionaly is not done.
// This is the old style for connecting to the database server, that is implemented here.
@ -778,15 +786,6 @@ if (@$_POST['step2']) {
$userPasswordCrypted = 'none';
}
//Setting the single db form
if (in_array($_POST['old_version'], $update_from_version_6)) {
$singleDbForm = get_config_param('singleDbEnabled');
} else {
$singleDbForm = isset($_configuration['single_database']) ? $_configuration['single_database'] : false;
}
Log::notice("singledbForm: '$singleDbForm'");
Database::query("SET storage_engine = MYISAM;");
if (version_compare($my_old_version, '1.8.7', '>=')) {
@ -797,64 +796,6 @@ if (@$_POST['step2']) {
}
switch ($my_old_version) {
case '1.6':
case '1.6.0':
case '1.6.1':
case '1.6.2':
case '1.6.3':
case '1.6.4':
case '1.6.5':
include 'update-db-1.6.x-1.8.0.inc.php';
include 'update-files-1.6.x-1.8.0.inc.php';
//intentionally no break to continue processing
case '1.8':
case '1.8.0':
include 'update-db-1.8.0-1.8.2.inc.php';
//intentionally no break to continue processing
case '1.8.2':
include 'update-db-1.8.2-1.8.3.inc.php';
//intentionally no break to continue processing
case '1.8.3':
include 'update-db-1.8.3-1.8.4.inc.php';
include 'update-files-1.8.3-1.8.4.inc.php';
case '1.8.4':
include 'update-db-1.8.4-1.8.5.inc.php';
include 'update-files-1.8.4-1.8.5.inc.php';
case '1.8.5':
include 'update-db-1.8.5-1.8.6.inc.php';
include 'update-files-1.8.5-1.8.6.inc.php';
case '1.8.6':
include 'update-db-1.8.6-1.8.6.1.inc.php';
include 'update-files-1.8.6-1.8.6.1.inc.php';
case '1.8.6.1':
include 'update-db-1.8.6.1-1.8.6.2.inc.php';
include 'update-files-1.8.6.1-1.8.6.2.inc.php';
case '1.8.6.2':
include 'update-db-1.8.6.2-1.8.7.inc.php';
include 'update-files-1.8.6.2-1.8.7.inc.php';
// After database conversion to UTF-8, new encoding initialization is necessary
// to be used for the next upgrade 1.8.7[.1] -> 1.8.8.
Database::query("SET SESSION character_set_server='utf8';");
Database::query("SET SESSION collation_server='utf8_general_ci';");
//Database::query("SET CHARACTER SET 'utf8';"); // See task #1802.
Database::query("SET NAMES 'utf8';");
case '1.8.7':
case '1.8.7.1':
include 'update-db-1.8.7-1.8.8.inc.php';
include 'update-files-1.8.7-1.8.8.inc.php';
case '1.8.8':
case '1.8.8.2':
//Only updates the configuration.inc.php with the new version
include 'update-configuration.inc.php';
case '1.8.8.4':
case '1.8.8.6':
include 'update-db-1.8.8-1.9.0.inc.php';
//include 'update-files-1.8.8-1.9.0.inc.php';
//Only updates the configuration.inc.php with the new version
include 'update-configuration.inc.php';
break;
case '1.9.0':
case '1.9.2':
case '1.9.4':
@ -874,7 +815,14 @@ if (@$_POST['step2']) {
}
} else {
set_file_folder_permissions();
database_server_connect();
//database_server_connect();
$manager = testDbConnect(
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
$dbNameForm
);
// Initialization of the database encoding to be used.
Database::query("SET storage_engine = MYISAM;");
@ -901,7 +849,7 @@ if (@$_POST['step2']) {
}
?>
</form>
</div> <!-- span9-->
</div> <!-- col-md-9-->
</div> <!-- row -->
</div> <!-- main end-->
<div class="push"></div>

@ -614,7 +614,6 @@ function get_config_param($param, $updatePath = '')
*/
function get_config_param_from_db($host, $login, $pass, $dbName, $param = '')
{
Database::connect(array('server' => $host, 'username' => $login, 'password' => $pass));
Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
Database::select_db($dbName);
@ -651,26 +650,6 @@ function database_server_connect()
@Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
}
/**
* Database exists for the MYSQL user
* @param string $database_name The name of the database to check
* @return boolean
*/
function database_exists($database_name)
{
if (empty($database_name)) {
return false;
}
$select_database = @Database::select_db($database_name);
$show_database = false;
$sql = "SHOW DATABASES LIKE '".addslashes($database_name)."'";
$result = @Database::query($sql);
if (Database::num_rows($result)) {
$show_database = true;
}
return $select_database || $show_database;
}
/**
* In step 3. Tests establishing connection to the database server.
* If it's a single database environment the function checks if the database exist.
@ -678,9 +657,7 @@ function database_exists($database_name)
* @param string $dbHostForm DB host
* @param string $dbUsernameForm DB username
* @param string $dbPassForm DB password
* @return int 1 when there is no problem;
* 0 when a new database is impossible to be created, then the single/multiple database configuration is impossible too
* -1 when there is no connection established.
* @return \Doctrine\ORM\EntityManager
*/
function testDbConnect($dbHostForm, $dbUsernameForm, $dbPassForm, $dbNameForm)
{
@ -689,19 +666,13 @@ function testDbConnect($dbHostForm, $dbUsernameForm, $dbPassForm, $dbNameForm)
'host' => $dbHostForm,
'user' => $dbUsernameForm,
'password' => $dbPassForm,
''
'dbname' => $dbNameForm
);
$config = Database::getDoctrineConfig();
$entityManager = \Doctrine\ORM\EntityManager::create($dbParams, $config);
$dbConnect = 1;
try {
$entityManager->getConnection()->connect();
} catch (Exception $e) {
echo $e->getMessage();
$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.
$database = new \Database();
$database->connect($dbParams);
return $database->getManager();
}
/**
@ -1838,35 +1809,19 @@ function display_database_settings_form(
$dbScormForm,
$dbUserForm
) {
if ($installType == 'update') {
global $_configuration, $update_from_version_6;
if (in_array($_POST['old_version'], $update_from_version_6)) {
$dbHostForm = get_config_param('dbHost');
$dbUsernameForm = get_config_param('dbLogin');
$dbPassForm = get_config_param('dbPass');
$dbPrefixForm = get_config_param('dbNamePrefix');
$enableTrackingForm = get_config_param('is_trackingEnabled');
$singleDbForm = get_config_param('singleDbEnabled');
$dbHostForm = get_config_param('mainDbName');
$dbStatsForm = get_config_param('statsDbName');
$dbScormForm = get_config_param('scormDbName');
$dbUserForm = get_config_param('user_personal_database');
$dbScormExists = true;
} else {
$dbHostForm = $_configuration['db_host'];
$dbUsernameForm = $_configuration['db_user'];
$dbPassForm = $_configuration['db_password'];
$dbPrefixForm = $_configuration['db_prefix'];
$enableTrackingForm = $_configuration['tracking_enabled'];
$singleDbForm = $_configuration['single_database'];
$dbNameForm = $_configuration['main_database'];
$dbStatsForm = $_configuration['statistics_database'];
$dbScormForm = $_configuration['scorm_database'];
$dbUserForm = $_configuration['user_personal_database'];
$dbScormExists = true;
}
global $_configuration;
$dbHostForm = $_configuration['db_host'];
$dbUsernameForm = $_configuration['db_user'];
$dbPassForm = $_configuration['db_password'];
$dbPrefixForm = $_configuration['db_prefix'];
$enableTrackingForm = $_configuration['tracking_enabled'];
$singleDbForm = $_configuration['single_database'];
$dbNameForm = $_configuration['main_database'];
$dbStatsForm = $_configuration['statistics_database'];
$dbScormForm = $_configuration['scorm_database'];
$dbUserForm = $_configuration['user_personal_database'];
$dbScormExists = true;
if (empty($dbScormForm)) {
if ($singleDbForm) {
@ -1932,16 +1887,16 @@ function display_database_settings_form(
$dbNameForm = replace_dangerous_char($dbNameForm);
}
displayDatabaseParameter($installType, get_lang('MainDB'), 'dbNameForm', $dbNameForm, '&nbsp;', null, 'id="optional_param1" '.$style);
displayDatabaseParameter(
$installType,
get_lang('MainDB'),
'dbNameForm',
$dbNameForm,
'&nbsp;',
null,
'id="optional_param1" '.$style
);
//Only for updates we show this options
if ($installType == INSTALL_TYPE_UPDATE) {
displayDatabaseParameter($installType, get_lang('StatDB'), 'dbStatsForm', $dbStatsForm, '&nbsp;', null, 'id="optional_param2" '.$style);
if ($installType == INSTALL_TYPE_UPDATE && in_array($_POST['old_version'], $update_from_version_6)) {
displayDatabaseParameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, '&nbsp;', null, 'id="optional_param3" '.$style);
}
displayDatabaseParameter($installType, get_lang('UserDB'), 'dbUserForm', $dbUserForm, '&nbsp;', null, 'id="optional_param4" '.$style);
}
?>
<tr>
<td></td>
@ -1956,17 +1911,31 @@ function display_database_settings_form(
<td>
<?php
$dbConnect = testDbConnect($dbHostForm, $dbUsernameForm, $dbPassForm, $dbNameForm);
$database_exists_text = '';
if (database_exists($dbNameForm)) {
try {
$manager = testDbConnect(
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
$dbNameForm
);
} catch (Exception $e) {
$database_exists_text = $e->getMessage();
}
$databases = $manager->getConnection()->getSchemaManager()->listDatabases();
if (in_array($dbNameForm, $databases)) {
$database_exists_text = '<div class="warning-message">'.get_lang('ADatabaseWithTheSameNameAlreadyExists').'</div>';
} else {
if ($dbConnect == -1) {
$database_exists_text = '<div class="warning-message">'.sprintf(get_lang('UserXCantHaveAccessInTheDatabaseX'), $dbUsernameForm, $dbNameForm).'</div>';
} else {
//Try to create the database
$manager->getConnection()->getSchemaManager()->createDatabase($dbNameForm);
/*
//Try to create the database
$user_can_create_databases = false;
$multipleDbCheck = @Database::query("CREATE DATABASE ".mysql_real_escape_string($dbNameForm));
if ($multipleDbCheck !== false) {
@ -1979,18 +1948,18 @@ function display_database_settings_form(
} else {
$dbConnect = 0;
$database_exists_text = '<div class="warning-message">'.sprintf(get_lang('DatabaseXCantBeCreatedUserXDoestHaveEnoughPermissions'), $dbNameForm, $dbUsernameForm).'</div>';
}
}*/
}
}
if ($dbConnect == 1): ?>
if ($manager): ?>
<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 />
Database client version: <strong><?php echo Database::get_client_info(); ?></strong><br />
Database protocol version: <strong><?php echo Database::get_proto_info(); ?></strong>
Database host: <strong><?php echo $manager->getConnection()->getHost(); ?></strong><br />
Database server version: <strong><?php //echo Database::get_server_info(); ?></strong><br />
Database client version: <strong><?php //echo Database::get_client_info(); ?></strong><br />
Database protocol version: <strong><?php //echo Database::get_proto_info(); ?></strong>
<div style="clear:both;"></div>
</div>
</td>
@ -2016,7 +1985,7 @@ function display_database_settings_form(
<td>&nbsp;</td>
<td align="right">
<input type="hidden" name="is_executable" id="is_executable" value="-" />
<?php if ($dbConnect == 1) { ?>
<?php if ($manager) { ?>
<button type="submit" class="btn btn-success" name="step4" value="<?php echo get_lang('Next'); ?> &gt;" >
<i class="fa fa-forward"> </i> <?php echo get_lang('Next'); ?>
</button>

@ -72,14 +72,19 @@ if (!defined('CLI_INSTALLATION')) {
$mysqlRepositorySys = $mysqlRepositorySys['Value'];
$create_database = true;
/** @var \Doctrine\ORM\EntityManager $manager */
global $manager;
$databases = $manager->getConnection()->getSchemaManager()->listDatabases();
if (database_exists($mysqlMainDb)) {
if (in_array($mysqlMainDb, $databases)) {
$create_database = false;
}
//Create database
// Create database
if ($create_database) {
$sql = "CREATE DATABASE IF NOT EXISTS `$mysqlMainDb`";
Database::query($sql) or die(Database::error());
$manager->getConnection()->getSchemaManager()->createDatabase($mysqlMainDb);
/*$sql = "CREATE DATABASE IF NOT EXISTS `$mysqlMainDb`";
Database::query($sql) or die(Database::error());*/
}
}
@ -95,7 +100,7 @@ if (!defined('CLI_INSTALLATION')) {
}
}
Database::select_db($mysqlMainDb) or die(Database::error());
//Database::select_db($mysqlMainDb) or die(Database::error());
$installation_settings = array();
$installation_settings['{ORGANISATIONNAME}'] = $institutionForm;

Loading…
Cancel
Save