From a91a2fa35f88dbe765b5aaaf9053e6ddae63b8ec Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 26 Mar 2015 13:07:13 +0100 Subject: [PATCH] Using Doctrine as a DB layer. --- main/inc/global.inc.php | 39 +---- main/inc/lib/database.lib.php | 60 +++++--- main/install/index.php | 252 +++++++++++++------------------- main/install/install.lib.php | 135 +++++++---------- main/install/install_db.inc.php | 15 +- 5 files changed, 204 insertions(+), 297 deletions(-) diff --git a/main/inc/global.inc.php b/main/inc/global.inc.php index 8bba0dbf84..d93e0588cd 100755 --- a/main/inc/global.inc.php +++ b/main/inc/global.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; diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 4dc5fa24f6..16570af075 100755 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -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);*/ } /** diff --git a/main/install/index.php b/main/install/index.php index ad1e7ce20e..ea639a8a98 100755 --- a/main/install/index.php +++ b/main/install/index.php @@ -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'; } + ?> @@ -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(' <?php echo get_lang('Hide') ?> '); + $("#id_contact_form").css("display","block"); + $("#img_plus_and_minus").html(' <?php echo get_lang('Hide') ?> '); } else { - $("#id_contact_form").css("display","none"); - $("#img_plus_and_minus").html(' <?php echo get_lang('Show') ?> '); + $("#id_contact_form").css("display","none"); + $("#img_plus_and_minus").html(' <?php echo get_lang('Show') ?> '); } }); }); @@ -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: "install.ajax.php?a=send_contact_information", - data: data_post, - success: function(datos) { - if (datos == 'required_field_error') { - message = ""; - } else if (datos == '1') { - message = ""; - } else { - message = ""; - } - alert(message); - } + contentType: "application/x-www-form-urlencoded", + beforeSend: function(objeto) {}, + type: "POST", + url: "install.ajax.php?a=send_contact_information", + data: data_post, + success: function(datos) { + if (datos == 'required_field_error') { + message = ""; + } else if (datos == '1') { + message = ""; + } else { + message = ""; + } + alert(message); + } }); } @@ -451,11 +446,11 @@ if ($encryptPassForm == '1') { -
+
-
+
@@ -481,7 +476,7 @@ if ($encryptPassForm == '1') { echo ''; ?>
-
+
  1. >
  2. @@ -500,9 +495,9 @@ if ($encryptPassForm == '1') {
-
+
-
+ " />


- '; ?> '.$dbNameForm; ?> - - '; - echo get_lang('StatDB').' : '.$dbStatsForm.''; - if ($installType == 'new') { - echo ' ('.get_lang('ReadWarningBelow').')'; - } - echo '
'; - echo get_lang('UserDB').' : '.$dbUserForm.''; - if ($installType == 'new') { - echo ' ('.get_lang('ReadWarningBelow').')'; - } - echo '
'; - } - } - - //echo get_lang('EnableTracking').' : '.($enableTrackingForm ? get_lang('Yes') : get_lang('No')); ?> -


- + @@ -732,9 +736,7 @@ if (@$_POST['step2']) { '.get_lang('PleaseWaitThisCouldTakeAWhile').'
'; - // 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']) { } ?> -
+
diff --git a/main/install/install.lib.php b/main/install/install.lib.php index d28167a9e7..8de55aaeb6 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -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, ' ', null, 'id="optional_param1" '.$style); + displayDatabaseParameter( + $installType, + get_lang('MainDB'), + 'dbNameForm', + $dbNameForm, + ' ', + null, + 'id="optional_param1" '.$style + ); - //Only for updates we show this options - if ($installType == INSTALL_TYPE_UPDATE) { - displayDatabaseParameter($installType, get_lang('StatDB'), 'dbStatsForm', $dbStatsForm, ' ', 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, ' ', null, 'id="optional_param3" '.$style); - } - displayDatabaseParameter($installType, get_lang('UserDB'), 'dbUserForm', $dbUserForm, ' ', null, 'id="optional_param4" '.$style); - } ?> @@ -1956,17 +1911,31 @@ function display_database_settings_form( getMessage(); + } + + $databases = $manager->getConnection()->getSchemaManager()->listDatabases(); + + if (in_array($dbNameForm, $databases)) { $database_exists_text = '
'.get_lang('ADatabaseWithTheSameNameAlreadyExists').'
'; } else { + if ($dbConnect == -1) { $database_exists_text = '
'.sprintf(get_lang('UserXCantHaveAccessInTheDatabaseX'), $dbUsernameForm, $dbNameForm).'
'; } 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 = '
'.sprintf(get_lang('DatabaseXCantBeCreatedUserXDoestHaveEnoughPermissions'), $dbNameForm, $dbUsernameForm).'
'; - } + }*/ } } - if ($dbConnect == 1): ?> + if ($manager): ?>
- Database host:
- Database server version:
- Database client version:
- Database protocol version: + Database host: getConnection()->getHost(); ?>
+ Database server version:
+ Database client version:
+ Database protocol version:
@@ -2016,7 +1985,7 @@ function display_database_settings_form(   - + diff --git a/main/install/install_db.inc.php b/main/install/install_db.inc.php index 80a1f493d2..fc053b203f 100755 --- a/main/install/install_db.inc.php +++ b/main/install/install_db.inc.php @@ -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;