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'], '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 { try {
$connect = $entityManager->getConnection()->connect(); $database = new \Database();
$database->connect($dbParams);
} catch (Exception $e) { } catch (Exception $e) {
$global_error_code = 3; $global_error_code = 3;
// The database server is not available or credentials are invalid. // The database server is not available or credentials are invalid.
@ -200,9 +168,6 @@ try {
die(); die();
} }
$database = new \Database();
$database->setManager($entityManager);
/* RETRIEVING ALL THE CHAMILO CONFIG SETTINGS FOR MULTIPLE URLs FEATURE*/ /* RETRIEVING ALL THE CHAMILO CONFIG SETTINGS FOR MULTIPLE URLs FEATURE*/
if (!empty($_configuration['multiple_access_urls'])) { if (!empty($_configuration['multiple_access_urls'])) {
$_configuration['access_url'] = 1; $_configuration['access_url'] = 1;

@ -4,6 +4,7 @@
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\Statement;
use Doctrine\Common\Annotations\AnnotationRegistry;
/** /**
* Class Database * Class Database
@ -54,13 +55,9 @@ class Database
* *
* @param string $short_table_name, the name of the table * @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 $table;
/*
return self::format_table_name(
self::get_main_database(),
$short_table_name);*/
} }
/** /**
@ -74,9 +71,9 @@ class Database
* @param string $database_name, optional, name of the course database * @param string $database_name, optional, name of the course database
* - if you don't specify this, you work on the current course. * - 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 //forces fatal errors so we can debug more easily
if (!empty($extra)) { if (!empty($extra)) {
@ -129,19 +126,42 @@ class Database
} }
/** /**
* Opens a connection to a database server. * @param array $params
* @param array $parameters (optional) An array that contains the necessary parameters for accessing the server. * @throws \Doctrine\ORM\ORMException
* @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
*/ */
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. // A MySQL-specific implementation.
if (!isset($parameters['server'])) { /*if (!isset($parameters['server'])) {
$parameters['server'] = @ini_get('mysql.default_host'); $parameters['server'] = @ini_get('mysql.default_host');
if (empty($parameters['server'])) { if (empty($parameters['server'])) {
$parameters['server'] = 'localhost:3306'; $parameters['server'] = 'localhost:3306';
@ -169,7 +189,7 @@ class Database
$client_flags = isset($parameters['client_flags']) ? $parameters['client_flags'] : null; $client_flags = isset($parameters['client_flags']) ? $parameters['client_flags'] : null;
return $persistent return $persistent
? mysql_pconnect($server, $username, $password, $client_flags) ? 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; use \ChamiloSession as Session;
define('SYSTEM_INSTALLATION', 1); define('SYSTEM_INSTALLATION', 1);
define('INSTALL_TYPE_UPDATE', 'update'); define('INSTALL_TYPE_UPDATE', 'update');
define('FORM_FIELD_DISPLAY_LENGTH', 40); define('FORM_FIELD_DISPLAY_LENGTH', 40);
define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25); define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25);
define('MAX_FORM_FIELD_LENGTH', 80); define('MAX_FORM_FIELD_LENGTH', 80);
/* PHP VERSION CHECK */ /* PHP VERSION CHECK */
@ -76,7 +76,6 @@ if (!array_key_exists($install_language, get_language_folder_list())) {
// Loading language files. // Loading language files.
require api_get_path(SYS_LANG_PATH).'english/trad4all.inc.php'; 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'; require api_get_path(SYS_LANG_PATH).'english/install.inc.php';
if ($install_language != 'english') { if ($install_language != 'english') {
include_once api_get_path(SYS_LANG_PATH).$install_language.'/trad4all.inc.php'; 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). // Overriding the timelimit (for large campusses that have to be migrated).
@set_time_limit(0); @set_time_limit(0);
// Upgrading from any subversion of 1.6 is just like upgrading from 1.6.5 $update_from_version_6 = array();
$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.9
// Upgrading from any subversion of 1.8 avoids the additional step of upgrading from 1.6 $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');
$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');
$my_old_version = ''; $my_old_version = '';
$tmp_version = get_config_param('dokeos_version'); $tmp_version = get_config_param('dokeos_version');
@ -138,13 +136,13 @@ if (isAlreadyInstalledSystem()) {
// Is valid request // Is valid request
$is_valid_request = isset($_REQUEST['is_executable']) ? $_REQUEST['is_executable'] : null; $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 (substr($request_index, 0, 4) == 'step') {
if ($request_index != $is_valid_request) { if ($request_index != $is_valid_request) {
unset($_POST[$request_index]); unset($_POST[$request_index]);
} }
} }
} }*/
$badUpdatePath = false; $badUpdatePath = false;
$emptyUpdatePath = true; $emptyUpdatePath = true;
@ -214,7 +212,6 @@ if (!isset($_GET['running'])) {
$dbPassForm = ''; $dbPassForm = '';
$dbPrefixForm = ''; $dbPrefixForm = '';
$dbNameForm = 'chamilo'; $dbNameForm = 'chamilo';
$dbStatsForm = 'chamilo'; $dbStatsForm = 'chamilo';
$dbScormForm = 'chamilo'; $dbScormForm = 'chamilo';
$dbUserForm = 'chamilo'; $dbUserForm = 'chamilo';
@ -223,11 +220,10 @@ if (!isset($_GET['running'])) {
$urlAppendPath = api_remove_trailing_slash(api_get_path(REL_PATH)); $urlAppendPath = api_remove_trailing_slash(api_get_path(REL_PATH));
$urlForm = api_get_path(WEB_PATH); $urlForm = api_get_path(WEB_PATH);
$pathForm = api_get_path(SYS_PATH); $pathForm = api_get_path(SYS_PATH);
$emailForm = 'webmaster@localhost';
$emailForm = 'webmaster@localhost'; if (!empty($_SERVER['SERVER_ADMIN'])) {
if (!empty($_SERVER['SERVER_ADMIN'])) { $emailForm = $_SERVER['SERVER_ADMIN'];
$emailForm = $_SERVER['SERVER_ADMIN']; }
}
$email_parts = explode('@', $emailForm); $email_parts = explode('@', $emailForm);
if (isset($email_parts[1]) && $email_parts[1] == 'localhost') { if (isset($email_parts[1]) && $email_parts[1] == 'localhost') {
$emailForm .= '.localdomain'; $emailForm .= '.localdomain';
@ -242,8 +238,6 @@ if (!isset($_GET['running'])) {
$adminPhoneForm = '(000) 001 02 03'; $adminPhoneForm = '(000) 001 02 03';
$institutionForm = 'My Organisation'; $institutionForm = 'My Organisation';
$institutionUrlForm = 'http://www.chamilo.org'; $institutionUrlForm = 'http://www.chamilo.org';
// TODO: A better choice to be tested:
//$languageForm = 'english';
$languageForm = api_get_interface_language(); $languageForm = api_get_interface_language();
$checkEmailByHashSent = 0; $checkEmailByHashSent = 0;
@ -300,6 +294,7 @@ if ($encryptPassForm == '1') {
} elseif ($encryptPassForm == '0') { } elseif ($encryptPassForm == '0') {
$encryptPassForm = 'none'; $encryptPassForm = 'none';
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<head> <head>
@ -320,15 +315,15 @@ if ($encryptPassForm == '1') {
//checked //checked
if ($('#singleDb1').attr('checked')==false) { if ($('#singleDb1').attr('checked')==false) {
//$('#dbStatsForm').removeAttr('disabled'); //$('#dbStatsForm').removeAttr('disabled');
//$('#dbUserForm').removeAttr('disabled'); //$('#dbUserForm').removeAttr('disabled');
$('#dbStatsForm').attr('value','chamilo_main'); $('#dbStatsForm').attr('value','chamilo_main');
$('#dbUserForm').attr('value','chamilo_main'); $('#dbUserForm').attr('value','chamilo_main');
} else if($('#singleDb1').attr('checked')==true){ } else if($('#singleDb1').attr('checked')==true){
//$('#dbStatsForm').attr('disabled','disabled'); //$('#dbStatsForm').attr('disabled','disabled');
//$('#dbUserForm').attr('disabled','disabled'); //$('#dbUserForm').attr('disabled','disabled');
$('#dbStatsForm').attr('value','chamilo_main'); $('#dbStatsForm').attr('value','chamilo_main');
$('#dbUserForm').attr('value','chamilo_main'); $('#dbUserForm').attr('value','chamilo_main');
} }
$("button").addClass('btn btn-default'); $("button").addClass('btn btn-default');
@ -407,11 +402,11 @@ if ($encryptPassForm == '1') {
$(document).ready( function() { $(document).ready( function() {
$(".advanced_parameters").click(function() { $(".advanced_parameters").click(function() {
if ($("#id_contact_form").css("display") == "none") { if ($("#id_contact_form").css("display") == "none") {
$("#id_contact_form").css("display","block"); $("#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') ?>'); $("#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 { } else {
$("#id_contact_form").css("display","none"); $("#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') ?>'); $("#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(); data_post += "financial_decision="+$("input[@name='financial_decision']:checked").val();
$.ajax({ $.ajax({
contentType: "application/x-www-form-urlencoded", contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) {}, beforeSend: function(objeto) {},
type: "POST", type: "POST",
url: "<?php echo api_get_path(WEB_AJAX_PATH) ?>install.ajax.php?a=send_contact_information", url: "<?php echo api_get_path(WEB_AJAX_PATH) ?>install.ajax.php?a=send_contact_information",
data: data_post, data: data_post,
success: function(datos) { success: function(datos) {
if (datos == 'required_field_error') { if (datos == 'required_field_error') {
message = "<?php echo get_lang('FormHasErrorsPleaseComplete') ?>"; message = "<?php echo get_lang('FormHasErrorsPleaseComplete') ?>";
} else if (datos == '1') { } else if (datos == '1') {
message = "<?php echo get_lang('ContactInformationHasBeenSent') ?>"; message = "<?php echo get_lang('ContactInformationHasBeenSent') ?>";
} else { } else {
message = "<?php echo get_lang('Error').': '.get_lang('ContactInformationHasNotBeenSent') ?>"; message = "<?php echo get_lang('Error').': '.get_lang('ContactInformationHasNotBeenSent') ?>";
} }
alert(message); alert(message);
} }
}); });
} }
</script> </script>
@ -451,11 +446,11 @@ if ($encryptPassForm == '1') {
</head> </head>
<body dir="<?php echo api_get_text_direction(); ?>" class="install-chamilo"> <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"> <div id="main" class="container well-install">
<header> <header>
<div class="row"> <div class="row">
<div id="header_left" class="span4"> <div id="header_left" class="col-md-4">
<div id="logo"> <div id="logo">
<img src="../css/chamilo/images/header-logo.png" hspace="10" vspace="10" alt="Chamilo" /> <img src="../css/chamilo/images/header-logo.png" hspace="10" vspace="10" alt="Chamilo" />
</div> </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>'; echo '<div class="page-header"><h1>'.get_lang('ChamiloInstallation').' &ndash; '.get_lang('Version_').' '.$new_version.'</h1></div>';
?> ?>
<div class="row"> <div class="row">
<div class="span3"> <div class="col-md-3">
<div class="well"> <div class="well">
<ol> <ol>
<li <?php step_active('1'); ?>><?php echo get_lang('InstallationLanguage'); ?></li> <li <?php step_active('1'); ?>><?php echo get_lang('InstallationLanguage'); ?></li>
@ -500,9 +495,9 @@ if ($encryptPassForm == '1') {
</div> </div>
</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 <?php
$instalation_type_label = ''; $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="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); ?>" /> <input type="hidden" name="new_version" value="<?php echo api_htmlentities($new_version, ENT_QUOTES); ?>" />
<?php <?php
if (@$_POST['step2']) { if (@$_POST['step2']) {
//STEP 3 : LICENSE //STEP 3 : LICENSE
display_license_agreement(); display_license_agreement();
} elseif (@$_POST['step3']) { } elseif (@$_POST['step3']) {
//STEP 4 : MYSQL DATABASE SETTINGS //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']) { } elseif (@$_POST['step4']) {
//STEP 5 : CONFIGURATION SETTINGS //STEP 5 : CONFIGURATION SETTINGS
@ -634,7 +642,24 @@ if (@$_POST['step2']) {
if (!empty($tmp)) $allowSelfRegProf = $tmp; 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']) { } elseif (@$_POST['step5']) {
//STEP 6 : LAST CHECK BEFORE INSTALL //STEP 6 : LAST CHECK BEFORE INSTALL
@ -665,30 +690,7 @@ if (@$_POST['step2']) {
<?php echo get_lang('DBHost').' : '.$dbHostForm; ?><br /> <?php echo get_lang('DBHost').' : '.$dbHostForm; ?><br />
<?php echo get_lang('DBLogin').' : '.$dbUsernameForm; ?><br /> <?php echo get_lang('DBLogin').' : '.$dbUsernameForm; ?><br />
<?php echo get_lang('DBPassword').' : '.str_repeat('*', api_strlen($dbPassForm)); ?><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 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('AllowSelfReg').' : '.($allowSelfReg ? get_lang('Yes') : get_lang('No')); ?><br />
<?php echo get_lang('EncryptMethodUserPass').' : '; <?php echo get_lang('EncryptMethodUserPass').' : ';
echo $encryptPassForm; echo $encryptPassForm;
@ -716,7 +718,9 @@ if (@$_POST['step2']) {
<table width="100%"> <table width="100%">
<tr> <tr>
<td> <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>
<td align="right"> <td align="right">
<input type="hidden" name="is_executable" id="is_executable" value="-" /> <input type="hidden" name="is_executable" id="is_executable" value="-" />
@ -732,9 +736,7 @@ if (@$_POST['step2']) {
<?php <?php
} elseif (@$_POST['step6']) { } elseif (@$_POST['step6']) {
//STEP 6 : INSTALLATION PROCESS //STEP 6 : INSTALLATION PROCESS
$current_step = 7; $current_step = 7;
$msg = get_lang('InstallExecution'); $msg = get_lang('InstallExecution');
if ($installType == 'update') { if ($installType == 'update') {
@ -745,7 +747,6 @@ if (@$_POST['step2']) {
<div id="pleasewait" class="warning-message">'.get_lang('PleaseWaitThisCouldTakeAWhile').'</div> <div id="pleasewait" class="warning-message">'.get_lang('PleaseWaitThisCouldTakeAWhile').'</div>
</div>'; </div>';
// Push the web server to send these strings before we start the real // Push the web server to send these strings before we start the real
// installation process // installation process
flush(); flush();
@ -755,9 +756,16 @@ if (@$_POST['step2']) {
} }
if ($installType == 'update') { if ($installType == 'update') {
remove_memory_and_time_limits(); 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. // 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. // This is the old style for connecting to the database server, that is implemented here.
@ -778,15 +786,6 @@ if (@$_POST['step2']) {
$userPasswordCrypted = 'none'; $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;"); Database::query("SET storage_engine = MYISAM;");
if (version_compare($my_old_version, '1.8.7', '>=')) { if (version_compare($my_old_version, '1.8.7', '>=')) {
@ -797,64 +796,6 @@ if (@$_POST['step2']) {
} }
switch ($my_old_version) { 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.0':
case '1.9.2': case '1.9.2':
case '1.9.4': case '1.9.4':
@ -874,7 +815,14 @@ if (@$_POST['step2']) {
} }
} else { } else {
set_file_folder_permissions(); set_file_folder_permissions();
database_server_connect();
//database_server_connect();
$manager = testDbConnect(
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
$dbNameForm
);
// Initialization of the database encoding to be used. // Initialization of the database encoding to be used.
Database::query("SET storage_engine = MYISAM;"); Database::query("SET storage_engine = MYISAM;");
@ -901,7 +849,7 @@ if (@$_POST['step2']) {
} }
?> ?>
</form> </form>
</div> <!-- span9--> </div> <!-- col-md-9-->
</div> <!-- row --> </div> <!-- row -->
</div> <!-- main end--> </div> <!-- main end-->
<div class="push"></div> <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 = '') function get_config_param_from_db($host, $login, $pass, $dbName, $param = '')
{ {
Database::connect(array('server' => $host, 'username' => $login, 'password' => $pass)); Database::connect(array('server' => $host, 'username' => $login, 'password' => $pass));
Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5) Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
Database::select_db($dbName); 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::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. * In step 3. Tests establishing connection to the database server.
* If it's a single database environment the function checks if the database exist. * 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 $dbHostForm DB host
* @param string $dbUsernameForm DB username * @param string $dbUsernameForm DB username
* @param string $dbPassForm DB password * @param string $dbPassForm DB password
* @return int 1 when there is no problem; * @return \Doctrine\ORM\EntityManager
* 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.
*/ */
function testDbConnect($dbHostForm, $dbUsernameForm, $dbPassForm, $dbNameForm) function testDbConnect($dbHostForm, $dbUsernameForm, $dbPassForm, $dbNameForm)
{ {
@ -689,19 +666,13 @@ function testDbConnect($dbHostForm, $dbUsernameForm, $dbPassForm, $dbNameForm)
'host' => $dbHostForm, 'host' => $dbHostForm,
'user' => $dbUsernameForm, 'user' => $dbUsernameForm,
'password' => $dbPassForm, '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, $dbScormForm,
$dbUserForm $dbUserForm
) { ) {
if ($installType == 'update') { if ($installType == 'update') {
global $_configuration, $update_from_version_6; global $_configuration;
$dbHostForm = $_configuration['db_host'];
if (in_array($_POST['old_version'], $update_from_version_6)) { $dbUsernameForm = $_configuration['db_user'];
$dbHostForm = get_config_param('dbHost'); $dbPassForm = $_configuration['db_password'];
$dbUsernameForm = get_config_param('dbLogin'); $dbPrefixForm = $_configuration['db_prefix'];
$dbPassForm = get_config_param('dbPass'); $enableTrackingForm = $_configuration['tracking_enabled'];
$dbPrefixForm = get_config_param('dbNamePrefix'); $singleDbForm = $_configuration['single_database'];
$enableTrackingForm = get_config_param('is_trackingEnabled'); $dbNameForm = $_configuration['main_database'];
$singleDbForm = get_config_param('singleDbEnabled'); $dbStatsForm = $_configuration['statistics_database'];
$dbHostForm = get_config_param('mainDbName'); $dbScormForm = $_configuration['scorm_database'];
$dbStatsForm = get_config_param('statsDbName'); $dbUserForm = $_configuration['user_personal_database'];
$dbScormForm = get_config_param('scormDbName'); $dbScormExists = true;
$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;
}
if (empty($dbScormForm)) { if (empty($dbScormForm)) {
if ($singleDbForm) { if ($singleDbForm) {
@ -1932,16 +1887,16 @@ function display_database_settings_form(
$dbNameForm = replace_dangerous_char($dbNameForm); $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> <tr>
<td></td> <td></td>
@ -1956,17 +1911,31 @@ function display_database_settings_form(
<td> <td>
<?php <?php
$dbConnect = testDbConnect($dbHostForm, $dbUsernameForm, $dbPassForm, $dbNameForm);
$database_exists_text = ''; $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>'; $database_exists_text = '<div class="warning-message">'.get_lang('ADatabaseWithTheSameNameAlreadyExists').'</div>';
} else { } else {
if ($dbConnect == -1) { if ($dbConnect == -1) {
$database_exists_text = '<div class="warning-message">'.sprintf(get_lang('UserXCantHaveAccessInTheDatabaseX'), $dbUsernameForm, $dbNameForm).'</div>'; $database_exists_text = '<div class="warning-message">'.sprintf(get_lang('UserXCantHaveAccessInTheDatabaseX'), $dbUsernameForm, $dbNameForm).'</div>';
} else { } else {
//Try to create the database $manager->getConnection()->getSchemaManager()->createDatabase($dbNameForm);
/*
//Try to create the database
$user_can_create_databases = false; $user_can_create_databases = false;
$multipleDbCheck = @Database::query("CREATE DATABASE ".mysql_real_escape_string($dbNameForm)); $multipleDbCheck = @Database::query("CREATE DATABASE ".mysql_real_escape_string($dbNameForm));
if ($multipleDbCheck !== false) { if ($multipleDbCheck !== false) {
@ -1979,18 +1948,18 @@ function display_database_settings_form(
} else { } else {
$dbConnect = 0; $dbConnect = 0;
$database_exists_text = '<div class="warning-message">'.sprintf(get_lang('DatabaseXCantBeCreatedUserXDoestHaveEnoughPermissions'), $dbNameForm, $dbUsernameForm).'</div>'; $database_exists_text = '<div class="warning-message">'.sprintf(get_lang('DatabaseXCantBeCreatedUserXDoestHaveEnoughPermissions'), $dbNameForm, $dbUsernameForm).'</div>';
} }*/
} }
} }
if ($dbConnect == 1): ?> if ($manager): ?>
<td colspan="2"> <td colspan="2">
<?php echo $database_exists_text ?> <?php echo $database_exists_text ?>
<div id="db_status" class="confirmation-message"> <div id="db_status" class="confirmation-message">
Database host: <strong><?php echo Database::get_host_info(); ?></strong><br /> Database host: <strong><?php echo $manager->getConnection()->getHost(); ?></strong><br />
Database server version: <strong><?php echo Database::get_server_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 client version: <strong><?php //echo Database::get_client_info(); ?></strong><br />
Database protocol version: <strong><?php echo Database::get_proto_info(); ?></strong> Database protocol version: <strong><?php //echo Database::get_proto_info(); ?></strong>
<div style="clear:both;"></div> <div style="clear:both;"></div>
</div> </div>
</td> </td>
@ -2016,7 +1985,7 @@ function display_database_settings_form(
<td>&nbsp;</td> <td>&nbsp;</td>
<td align="right"> <td align="right">
<input type="hidden" name="is_executable" id="is_executable" value="-" /> <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;" > <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'); ?> <i class="fa fa-forward"> </i> <?php echo get_lang('Next'); ?>
</button> </button>

@ -72,14 +72,19 @@ if (!defined('CLI_INSTALLATION')) {
$mysqlRepositorySys = $mysqlRepositorySys['Value']; $mysqlRepositorySys = $mysqlRepositorySys['Value'];
$create_database = true; $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 = false;
} }
//Create database
// Create database
if ($create_database) { if ($create_database) {
$sql = "CREATE DATABASE IF NOT EXISTS `$mysqlMainDb`"; $manager->getConnection()->getSchemaManager()->createDatabase($mysqlMainDb);
Database::query($sql) or die(Database::error()); /*$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 = array();
$installation_settings['{ORGANISATIONNAME}'] = $institutionForm; $installation_settings['{ORGANISATIONNAME}'] = $institutionForm;

Loading…
Cancel
Save