Ver código fonte

Moving Track and User DB in the main database see #3966

Julio Montoya 13 anos atrás
pai
commit
016ec94cee

+ 3 - 0
.hgignore

@@ -114,3 +114,6 @@ searchdb/*
 
 syntax: regexp
 ^main/upload/users$
+
+syntax: regexp
+^\.settings$

+ 4 - 0
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;
 }

+ 3 - 0
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;

+ 14 - 16
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']) {
 	</div>
     <div class="RequirementContent">
 		<?php echo get_lang('HereAreTheValuesYouEntered'); ?>
-	</div>
-	<strong><?php echo get_lang('PrintThisPageToRememberPassAndOthers'); ?></strong>
-
+	</div><br />
+	
 	<blockquote>
 
 	<?php echo get_lang('MainLang').' : '.$languageForm; ?><br /><br />
 	<?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('DbPrefixForm').' : '.$dbPrefixForm.'<br />'; ?>
 	<?php echo get_lang('MainDB').' : <strong>'.$dbNameForm; ?></strong>
-	<?php if ($installType == 'new') echo ' (<font color="#cc0033">'.get_lang('ReadWarningBelow').'</font>)'; ?><br />
+	
 	<?php
 	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>)';
@@ -652,9 +652,9 @@ if ($_POST['step2']) {
 			echo '<br />';
 		}
 	}
-	?>
-	<?php //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 />
+	
+	//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;
@@ -673,10 +673,8 @@ if ($_POST['step2']) {
 	<?php if ($installType == 'new'): ?>
 	<?php echo get_lang('AdminLogin').' : <strong>'.$loginForm; ?></strong><br />
 	<?php echo get_lang('AdminPass').' : <strong>'.$passForm; /* TODO: Maybe this password should be hidden too? */ ?></strong><br /><br />
-	<?php else: ?>
-	<br />
+	<?php else: ?>	
 	<?php endif; ?>
-
 	<?php echo get_lang('CampusName').' : '.$campusForm; ?><br />
 	<?php echo get_lang('InstituteShortName').' : '.$institutionForm; ?><br />
 	<?php echo get_lang('InstituteURL').' : '.$institutionUrlForm; ?><br />

+ 44 - 58
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() {
 
     <!-- Contact information form -->
 	<div>
-    	<div class="formw">
+    	
         	<a href="javascript://" class = "advanced_parameters" >
             	<span id="img_plus_and_minus">&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') ?></span>
            	</a>
-		</div>
+		
 	</div>
                     
     <div id="id_contact_form" style="display:block">
@@ -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 '<div class="RequirementContent">';
         echo get_lang('DBSettingUpgradeIntro');
         echo '</div>';
-    } else {        
+    } else {
         if (empty($dbPrefixForm)) { //make sure there is a default value for db prefix
-            $dbPrefixForm = 'chamilo_';
+            $dbPrefixForm = '';
         }
         echo '<div class="RequirementHeading"><h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2></div>';
         echo '<div class="RequirementContent">';
@@ -1653,8 +1653,8 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo
       <td width="30%"><?php echo get_lang('EG').' localhost'; ?></td>
       <?php endif; ?>
     </tr>
-    <?php
-echo '<tr>';
+    <tr>
+    <?php	
     //database user username
     $example_login = get_lang('EG').' root';
     display_database_parameter($installType, get_lang('DBLogin'), 'dbUsernameForm', $dbUsernameForm, $example_login);
@@ -1662,11 +1662,6 @@ echo '<tr>';
     //database user password
     $example_password = get_lang('EG').' '.api_generate_password();
     display_database_parameter($installType, get_lang('DBPassword'), 'dbPassForm', $dbPassForm, $example_password);
-    
-    ?>
-
-        
-	<?php 
 
     //Fields for the four standard Chamilo databases    
     if ($installType != INSTALL_TYPE_UPDATE) {        
@@ -1688,17 +1683,16 @@ echo '<tr>';
     display_database_parameter($installType, get_lang('MainDB'), 'dbNameForm',  $dbNameForm,  '&nbsp;', 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, '&nbsp;', null, 'id="optional_param2" '.$style);    
-    
+    if ($installType == INSTALL_TYPE_UPDATE) {
+    	display_database_parameter($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)) {
-        display_database_parameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, '&nbsp;', null, 'id="optional_param3" '.$style);
+        	display_database_parameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, '&nbsp;', null, 'id="optional_param3" '.$style);
     	}    
     	display_database_parameter($installType, get_lang('UserDB'), 'dbUserForm', $dbUserForm, '&nbsp;', 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 '<tr>';
         if ($dbConnect == 1): ?>
         <td colspan="2">
             <div class="confirmation-message">                
-                Database host info: <strong><?php echo Database::get_host_info(); ?></strong><br />
+                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>
@@ -1785,34 +1779,28 @@ function display_configuration_settings_form($installType, $urlForm, $languageFo
     echo '<table class="data_table_no_border">';
 
     //First parameter: language
-    echo "<tr>\n";
-    echo '<td>'.get_lang('MainLang')."&nbsp;&nbsp;</td>\n";
-
+    echo "<tr>";
+    echo '<td>'.get_lang('MainLang')."&nbsp;&nbsp;</td>";
     if ($installType == 'update') {
-
-        echo '<td><input type="hidden" name="languageForm" value="'.api_htmlentities($languageForm, ENT_QUOTES).'" />'.$languageForm."</td>\n";
+        echo '<td><input type="hidden" name="languageForm" value="'.api_htmlentities($languageForm, ENT_QUOTES).'" />'.$languageForm."</td>";
 
     } else { // new installation
-
         echo '<td>';
-
         display_language_selection_box('languageForm', $languageForm);
-
         echo "</td>\n";
     }
     echo "</tr>\n";
 
     //Second parameter: Chamilo URL
     echo "<tr>\n";
-    echo '<td>'.get_lang('ChamiloURL').' (<font color="red">'.get_lang('ThisFieldIsRequired')."</font>)&nbsp;&nbsp;</td>\n";
+    echo '<td>'.get_lang('ChamiloURL').' (<font color="red">'.get_lang('ThisFieldIsRequired')."</font>)&nbsp;&nbsp;</td>";
 
     if ($installType == 'update') {
         echo '<td>'.api_htmlentities($urlForm, ENT_QUOTES)."</td>\n";
     } else {
-        echo '<td><input type="text" size="40" maxlength="100" name="urlForm" value="'.api_htmlentities($urlForm, ENT_QUOTES).'" />'."</td>\n";
+        echo '<td><input type="text" size="40" maxlength="100" name="urlForm" value="'.api_htmlentities($urlForm, ENT_QUOTES).'" />'."</td>";
     }
-
-    echo "</tr>\n";
+    echo "</tr>";
 
     //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
       <?php endif; ?>
     </tr>
 
-     */
+    */
 
     ?>
     <tr>
       <td><?php echo get_lang("EncryptMethodUserPass"); ?> :</td>
-
-      <?php if ($installType == 'update'){ ?>
+      <?php if ($installType == 'update') { ?>
       <td><input type="hidden" name="encryptPassForm" value="<?php echo $encryptPassForm; ?>" /><?php echo $encryptPassForm; ?></td>
-      <?php }else{ ?>
+      <?php } else { ?>
       <td>
         <input class="checkbox" type="radio" name="encryptPassForm" value="sha1" id="encryptPass1" <?php echo ($encryptPassForm == 'sha1') ? 'checked="checked" ': ''; ?>/> <label for="encryptPass1"><?php echo 'sha1'; ?></label>
         <input class="checkbox" type="radio" name="encryptPassForm" value="md5" id="encryptPass0" <?php echo $encryptPassForm == 1 ? 'checked="checked" ' : ''; ?>/> <label for="encryptPass0"><?php echo 'md5'; ?></label>
@@ -1877,7 +1864,6 @@ function display_configuration_settings_form($installType, $urlForm, $languageFo
       </td>
       <?php } ?>
     </tr>
-
     <tr>
       <td><?php echo get_lang('AllowSelfReg'); ?> :</td>
 

+ 12 - 7
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');

+ 0 - 3
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 !';
-
 }

+ 69 - 52
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 !';
-
-}
+}