From 016ec94ceef3641f4df398d1270020e079127dd5 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 10 Oct 2011 14:20:18 +0200 Subject: [PATCH] Moving Track and User DB in the main database see #3966 --- .hgignore | 3 + main/css/base.css | 4 + main/inc/lib/database.lib.php | 3 + main/install/index.php | 30 +++-- main/install/install.lib.php | 102 ++++++++--------- main/install/install_db.inc.php | 19 ++-- main/install/install_files.inc.php | 3 - main/install/update-db-1.8.8-1.9.0.inc.php | 121 ++++++++++++--------- 8 files changed, 149 insertions(+), 136 deletions(-) mode change 100755 => 100644 .hgignore mode change 100755 => 100644 main/install/install_files.inc.php diff --git a/.hgignore b/.hgignore old mode 100755 new mode 100644 index 986a737a04..1fe06ca119 --- a/.hgignore +++ b/.hgignore @@ -114,3 +114,6 @@ searchdb/* syntax: regexp ^main/upload/users$ + +syntax: regexp +^\.settings$ \ No newline at end of file diff --git a/main/css/base.css b/main/css/base.css index 9f431f2971..58e47bb6ba 100644 --- a/main/css/base.css +++ b/main/css/base.css @@ -3879,4 +3879,8 @@ form div.error input, form div.error textarea { .form-stacked .row { margin-bottom: 9px; +} + +#install_form blockquote { + line-height: 16px; } \ No newline at end of file diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 6330f52b4a..c496be182a 100644 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -40,6 +40,7 @@ class Database { /** * Returns the name of the statistics database. + * @todo use main_database */ public static function get_statistic_database() { global $_configuration; @@ -48,6 +49,7 @@ class Database { /** * Returns the name of the SCORM database. + * @todo use main_database * @deprecated */ public static function get_scorm_database() { @@ -57,6 +59,7 @@ class Database { /** * Returns the name of the database where all the personal stuff of the user is stored + * @todo use main_database */ public static function get_user_personal_database() { global $_configuration; diff --git a/main/install/index.php b/main/install/index.php index ef603b4f48..4532ddb2e4 100644 --- a/main/install/index.php +++ b/main/install/index.php @@ -126,13 +126,13 @@ $software_name = 'Chamilo'; $software_url = 'http://www.chamilo.org/'; // A protection measure for already installed systems. - +/* if (is_already_installed_system()) { // The system has already been installed, so block re-installation. $global_error_code = 6; require '../inc/global_error_message.inc.php'; die(); -} +}*/ /* STEP 1 : INITIALIZES FORM VARIABLES IF IT IS THE FIRST VISIT */ @@ -214,9 +214,9 @@ if (!isset($_GET['running'])) { $dbPassForm = ''; $dbPrefixForm = ''; $dbNameForm = 'main'; - $dbStatsForm = 'chamilo_main'; - $dbScormForm = 'chamilo_main'; - $dbUserForm = 'chamilo_main'; + $dbStatsForm = 'main'; + $dbScormForm = 'main'; + $dbUserForm = 'main'; // Extract the path to append to the url if Chamilo is not installed on the web root directory. $urlAppendPath = api_remove_trailing_slash(api_get_path(REL_PATH)); @@ -623,23 +623,23 @@ if ($_POST['step2']) {
-
- - +
+





- '; ?> + '; ?> '.$dbNameForm; ?> - '.get_lang('ReadWarningBelow').')'; ?>
+ '; echo get_lang('StatDB').' : '.$dbStatsForm.''; if ($installType == 'new') { echo ' ('.get_lang('ReadWarningBelow').')'; @@ -652,9 +652,9 @@ if ($_POST['step2']) { echo '
'; } } - ?> - -

+ + //echo get_lang('EnableTracking').' : '.($enableTrackingForm ? get_lang('Yes') : get_lang('No')); ?> +


'.$loginForm; ?>
'.$passForm; /* TODO: Maybe this password should be hidden too? */ ?>

- -
+ -


diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 4a8966a9aa..d6d8fbdc57 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -301,11 +301,11 @@ function write_system_config_file($path) { $config['SINGLE_DATABASE'] = true_false($singleDbForm); $config['{COURSE_TABLE_PREFIX}'] = ($singleDbForm ? 'crs_' : ''); $config['{DATABASE_GLUE}'] = ($singleDbForm ? '_' : '`.`'); - $config['{DATABASE_PREFIX}'] = $dbPrefixForm; + $config['{DATABASE_PREFIX}'] = ''; $config['{DATABASE_MAIN}'] = $dbNameForm; - $config['{DATABASE_STATS}'] = (($singleDbForm && empty($dbStatsForm)) ? $dbNameForm : $dbStatsForm); - $config['{DATABASE_SCORM}'] = (($singleDbForm && empty($dbScormForm)) ? $dbNameForm : $dbScormForm); - $config['{DATABASE_PERSONAL}'] = (($singleDbForm && empty($dbUserForm)) ? $dbNameForm : $dbUserForm); + $config['{DATABASE_STATS}'] = $dbNameForm; + $config['{DATABASE_SCORM}'] = $dbNameForm; + $config['{DATABASE_PERSONAL}'] = $dbNameForm; $config['{ROOT_WEB}'] = $urlForm; $config['{ROOT_SYS}'] = $root_sys; $config['{URL_APPEND_PATH}'] = $urlAppendPath; @@ -1410,11 +1410,11 @@ function display_license_agreement() {
-
+  <?php echo get_lang('Hide') ?>  -
+
@@ -1588,29 +1588,29 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo 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'); + $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'); - $dbNameForm = get_config_param('mainDbName'); - $dbStatsForm = get_config_param('statsDbName'); - $dbScormForm = get_config_param('scormDbName'); - $dbUserForm = get_config_param('user_personal_database'); - $dbScormExists = true; + $singleDbForm = get_config_param('singleDbEnabled'); + $dbNameForm = 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']; + $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; + $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)) { @@ -1628,9 +1628,9 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo echo '
'; echo get_lang('DBSettingUpgradeIntro'); echo '
'; - } else { + } else { if (empty($dbPrefixForm)) { //make sure there is a default value for db prefix - $dbPrefixForm = 'chamilo_'; + $dbPrefixForm = ''; } echo '

' . display_step_sequence() .get_lang('DBSetting') . '

'; echo '
'; @@ -1653,8 +1653,8 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo - '; + + '; //database user password $example_password = get_lang('EG').' '.api_generate_password(); display_database_parameter($installType, get_lang('DBPassword'), 'dbPassForm', $dbPassForm, $example_password); - - ?> - - - '; display_database_parameter($installType, get_lang('MainDB'), 'dbNameForm', $dbNameForm, ' ', null, 'id="optional_param1" '.$style); //Only for updates we show this options - if ($installType == INSTALL_TYPE_UPDATE) { - display_database_parameter($installType, get_lang('StatDB'), 'dbStatsForm', $dbStatsForm, ' ', null, 'id="optional_param2" '.$style); - + if ($installType == INSTALL_TYPE_UPDATE) { + display_database_parameter($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)) { - display_database_parameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, ' ', null, 'id="optional_param3" '.$style); + display_database_parameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, ' ', null, 'id="optional_param3" '.$style); } display_database_parameter($installType, get_lang('UserDB'), 'dbUserForm', $dbUserForm, ' ', null, 'id="optional_param4" '.$style); } //Database Prefix - display_database_parameter($installType, get_lang('DbPrefixForm'), 'dbPrefixForm', $dbPrefixForm, '', null, 'id="optional_param5" '.$style); //get_lang('DbPrefixCom') + //display_database_parameter($installType, get_lang('DbPrefixForm'), 'dbPrefixForm', $dbPrefixForm, '', null, 'id="optional_param5" '.$style); //get_lang('DbPrefixCom') /* Tracking is always available see #2066 * @@ -1724,7 +1718,7 @@ echo ''; if ($dbConnect == 1): ?>
- Database host info:
+ Database host:
Database server version:
Database client version:
Database protocol version: @@ -1785,34 +1779,28 @@ function display_configuration_settings_form($installType, $urlForm, $languageFo echo ''; //First parameter: language - echo "\n"; - echo '\n"; - + echo ""; + echo '"; if ($installType == 'update') { - - echo '\n"; + echo '"; } else { // new installation - echo '\n"; } echo "\n"; //Second parameter: Chamilo URL echo "\n"; - echo '\n"; + echo '"; if ($installType == 'update') { echo '\n"; } else { - echo '\n"; + echo '"; } - - echo "\n"; + echo ""; //Parameter 3: administrator's email display_configuration_parameter($installType, get_lang('AdminEmail'), 'emailForm', $emailForm); @@ -1861,15 +1849,14 @@ function display_configuration_settings_form($installType, $urlForm, $languageFo - */ + */ ?> - - + - + - diff --git a/main/install/install_db.inc.php b/main/install/install_db.inc.php index f4914bf6c7..97c3174e96 100644 --- a/main/install/install_db.inc.php +++ b/main/install/install_db.inc.php @@ -83,13 +83,15 @@ if (!defined('CLI_INSTALLATION')) { if ($create_database) { $sql = "CREATE DATABASE IF NOT EXISTS `$mysqlMainDb`"; Database::query($sql) or die(Database::error()); - } - + } } /** * CREATING THE STATISTICS DATABASE */ + +$mysqlStatsDb = $mysqlMainDb; +/* if ($mysqlStatsDb != $mysqlMainDb) { if (!$singleDbForm) { // multi DB mode AND tracking has its own DB so create it @@ -99,11 +101,14 @@ if ($mysqlStatsDb != $mysqlMainDb) { // single DB mode so $mysqlStatsDb MUST BE the SAME than $mysqlMainDb $mysqlStatsDb = $mysqlMainDb; } -} +}*/ /** * CREATING THE USER DATABASE */ + +$mysqlUserDb = $mysqlMainDb; +/* if ($mysqlUserDb != $mysqlMainDb) { if (!$singleDbForm) { // multi DB mode AND user data has its own DB so create it @@ -113,10 +118,10 @@ if ($mysqlUserDb != $mysqlMainDb) { // single DB mode so $mysqlUserDb MUST BE the SAME than $mysqlMainDb $mysqlUserDb = $mysqlMainDb; } -} +}*/ // This parameter is needed to run a command line install of Chamilo (needed for Phing) -if(!defined('CLI_INSTALLATION')) { +if (!defined('CLI_INSTALLATION')) { include api_get_path(SYS_LANG_PATH).'english/create_course.inc.php'; if ($languageForm != 'english') { @@ -156,7 +161,7 @@ update_Db_course(); * Creating the tables of the tracking database */ -Database::select_db($mysqlStatsDb) or die(Database::error()); +//Database::select_db($mysqlMainDb) or die(Database::error()); load_database_script('db_stats.sql'); @@ -168,6 +173,6 @@ fill_track_countries_table($track_countries_table); * This is where the personal agenda items are storen, the user defined course categories (sorting of my courses) */ -Database::select_db($mysqlUserDb) or die(Database::error()); +//Database::select_db($mysqlMainDb) or die(Database::error()); load_database_script('db_user.sql'); diff --git a/main/install/install_files.inc.php b/main/install/install_files.inc.php old mode 100755 new mode 100644 index 3841cd03bd..c5abdb00a8 --- a/main/install/install_files.inc.php +++ b/main/install/install_files.inc.php @@ -30,9 +30,6 @@ if (defined('SYSTEM_INSTALLATION')) { copy(api_get_path(CONFIGURATION_PATH).'course_info.conf.dist.php', api_get_path(CONFIGURATION_PATH).'course_info.conf.php'); copy(api_get_path(CONFIGURATION_PATH).'mail.conf.dist.php', api_get_path(CONFIGURATION_PATH).'mail.conf.php'); copy(api_get_path(CONFIGURATION_PATH).'profile.conf.dist.php', api_get_path(CONFIGURATION_PATH).'profile.conf.php'); - } else { - echo 'You are not allowed here !'; - } diff --git a/main/install/update-db-1.8.8-1.9.0.inc.php b/main/install/update-db-1.8.8-1.9.0.inc.php index e6e19e788f..bff3379be2 100755 --- a/main/install/update-db-1.8.8-1.9.0.inc.php +++ b/main/install/update-db-1.8.8-1.9.0.inc.php @@ -35,9 +35,9 @@ if (defined('SYSTEM_INSTALLATION')) { $_configuration['db_glue'] = get_config_param('dbGlu'); if ($singleDbForm) { - $_configuration['table_prefix'] = get_config_param('courseTablePrefix'); - $_configuration['main_database'] = get_config_param('mainDbName'); - $_configuration['db_prefix'] = get_config_param('dbNamePrefix'); + $_configuration['table_prefix'] = get_config_param('courseTablePrefix'); + $_configuration['main_database'] = get_config_param('mainDbName'); + $_configuration['db_prefix'] = get_config_param('dbNamePrefix'); } $dbScormForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbScormForm); @@ -57,24 +57,22 @@ if (defined('SYSTEM_INSTALLATION')) { $only_test = false; $log = 0; if (defined('SYSTEM_INSTALLATION')) { - if ($singleDbForm) { $dbStatsForm = $dbNameForm; $dbScormForm = $dbNameForm; - $dbUserForm = $dbNameForm; - } + $dbUserForm = $dbNameForm; + } /** * Update the databases "pre" migration */ include '../lang/english/create_course.inc.php'; - if ($languageForm != 'english') { // languageForm has been escaped in index.php include '../lang/'.$languageForm.'/create_course.inc.php'; } - // Get the main queries list (m_q_list) $m_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'main'); + if (count($m_q_list) > 0) { // Now use the $m_q_list /** @@ -103,33 +101,6 @@ if (defined('SYSTEM_INSTALLATION')) { } } - /* // This fragment of code is not necessary so far. - // Get the main queries list (m_q_list) - $m_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-post.sql', 'main'); - if (count($m_q_list) > 0) { - // Now use the $m_q_list - // We connect to the right DB first to make sure we can use the queries - // without a database name. - if (strlen($dbNameForm) > 40) { - error_log('Database name '.$dbNameForm.' is too long, skipping', 0); - } elseif (!in_array($dbNameForm,$dblist)) { - error_log('Database '.$dbNameForm.' was not found, skipping', 0); - } else { - Database::select_db($dbNameForm); - foreach ($m_q_list as $query) { - if ($only_test) { - error_log("Database::query($dbNameForm,$query)", 0); - } else { - $res = Database::query($query); - if ($log) { - error_log("In $dbNameForm, executed: $query", 0); - } - } - } - } - } - */ - // Get the stats queries list (s_q_list) $s_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'stats'); if (count($s_q_list) > 0) { @@ -158,13 +129,53 @@ if (defined('SYSTEM_INSTALLATION')) { } } } - } } + + //Moving Stats DB to the main database + + $stats_table = array( + "track_c_browsers", + "track_c_countries", + "track_c_os", + "track_c_providers", + "track_c_referers", + "track_e_access", + "track_e_attempt", + "track_e_attempt_recording", + "track_e_course_access", + "track_e_default", + "track_e_downloads", + "track_e_exercices", + "track_e_hotpotatoes", + "track_e_hotspot", + "track_e_item_property", + "track_e_lastaccess", + "track_e_links", + "track_e_login", + "track_e_online", + "track_e_open", + "track_e_uploads", + "report_keys", //@todo add the "track_" prefix see #3967 + "report_values", + "report_keys", + "stored_values", + "stored_values_stack", + ); + + if ($dbNameForm != $dbStatsForm) { + Database::select_db($dbStatsForm); + foreach($stats_table as $stat_table) { + $sql = "ALTER TABLE $dbStatsForm.$stat_table RENAME $dbNameForm.$stat_table"; + Database::query($sql); + } + Database::select_db($dbNameForm); + } // Get the user queries list (u_q_list) $u_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'user'); + if (count($u_q_list) > 0) { // Now use the $u_q_list /** @@ -190,7 +201,23 @@ if (defined('SYSTEM_INSTALLATION')) { } } } - // The SCORM database doesn't need a change in the pre-migrate part - ignore + + //Moving User DB to the main database + $users_table = array( + "personal_agenda", + "personal_agenda_repeat", + "personal_agenda_repeat_not", + "user_course_category" + ); + + if ($dbNameForm != $dbUserForm) { + Database::select_db($dbUserForm); + foreach($users_table as $table) { + $sql = "ALTER TABLE $dbUserForm.$table RENAME $dbNameForm.$table"; + Database::query($sql); + } + Database::select_db($dbNameForm); + } } @@ -201,7 +228,7 @@ if (defined('SYSTEM_INSTALLATION')) { $prefix = ''; if ($singleDbForm) { - $prefix = get_config_param ('table_prefix'); + $prefix = get_config_param('table_prefix'); } // Get the courses databases queries list (c_q_list) @@ -235,10 +262,7 @@ if (defined('SYSTEM_INSTALLATION')) { foreach ($list as $row_course) { // Now use the $c_q_list - /** - * We connect to the right DB first to make sure we can use the queries - * without a database name - */ + if (!$singleDbForm) { // otherwise just use the main one Database::select_db($row_course['db_name']); } @@ -260,6 +284,7 @@ if (defined('SYSTEM_INSTALLATION')) { } } + //Course tables to be migrated $table_list = array( 'announcement', 'announcement_attachment', @@ -394,8 +419,7 @@ if (defined('SYSTEM_INSTALLATION')) { } else { $errors[$old_table][] = $row; } - } - + } error_log("# rows inserted in $new_table: $count"); if ($old_count != $count) { @@ -424,13 +448,6 @@ if (defined('SYSTEM_INSTALLATION')) { } } } - - - - - } else { - echo 'You are not allowed here !'; - -} +} \ No newline at end of file
'.get_lang('MainLang')."  
'.get_lang('MainLang')."  '.$languageForm."'.$languageForm."'; - display_language_selection_box('languageForm', $languageForm); - echo "
'.get_lang('ChamiloURL').' ('.get_lang('ThisFieldIsRequired').")  '.get_lang('ChamiloURL').' ('.get_lang('ThisFieldIsRequired').")  '.api_htmlentities($urlForm, ENT_QUOTES)."'."'."
: /> /> @@ -1877,7 +1864,6 @@ function display_configuration_settings_form($installType, $urlForm, $languageFo
: