Pārlūkot izejas kodu

Added some files for database migration to 1.10

Yannick Warnier 12 gadi atpakaļ
vecāks
revīzija
82f05fb10b

+ 2 - 1
main/install/db_stats.sql

@@ -287,6 +287,7 @@ ALTER TABLE track_e_access ADD INDEX (access_session_id);
 
 ALTER TABLE track_e_online ADD INDEX (course);
 ALTER TABLE track_e_online ADD INDEX (session_id);
+ALTER TABLE track_e_online ADD INDEX idx_trackonline_uat (login_user_id, access_url_id, login_date);
 
 ALTER TABLE track_e_item_property ADD INDEX (course_id, item_property_id, session_id);
 ALTER TABLE track_e_downloads ADD INDEX (down_session_id);  
@@ -326,4 +327,4 @@ CREATE TABLE track_e_attempt_coeff (
     id int unsigned not null auto_increment primary key,
     attempt_id INT NOT NULL, 
     marks_coeff float(6,2)
-);
+);

+ 20 - 0
main/install/migrate-db-1.9.0-1.10.0-pre.sql

@@ -0,0 +1,20 @@
+-- This script updates the databases structure before migrating the data from
+-- version 1.9.0 (or version 1.9.2, 1.9.4) to version 1.10.0
+-- it is intended as a standalone script, however, this has not been finished
+-- yet, and it should still be parsed by a PHP script.
+-- There is one line per query, allowing the PHP function file() to read
+-- all lines separately into an array. The xxMAINxx-type markers used to be 
+-- there to tell the PHP script which database we're talking about, but since
+-- 1.9.0, everything should be residing in the same, unique xxMAINxx section.
+-- By always using the keyword "TABLE" in the queries, we should be able
+-- to retrieve and modify the table name from the PHP script if needed, which
+-- will allow us to deal with the unique-database-type installations
+
+-- xxMAINxx
+
+-- Optimize tracking query very often queried on busy campuses
+ALTER TABLE track_e_online ADD INDEX idx_trackonline_uat (login_user_id, access_url_id, login_date);
+
+-- Do not move this query
+UPDATE settings_current SET selected_value = '1.10.0.19436' WHERE variable = 'chamilo_database_version';
+

+ 115 - 0
main/install/update-db-1.9.0-1.10.0.inc.php

@@ -0,0 +1,115 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ * Chamilo LMS
+ *
+ * Update the Chamilo database from an older Chamilo version
+ * Notice : This script has to be included by index.php
+ * or update_courses.php (deprecated).
+ *
+ * @package chamilo.install
+ * @todo
+ * - conditional changing of tables. Currently we execute for example
+ * ALTER TABLE $dbNameForm.cours
+ * instructions without checking wether this is necessary.
+ * - reorganise code into functions
+ * @todo use database library
+ */
+Log::notice('Entering file');
+
+$old_file_version = '1.9.0';
+$new_file_version = '1.10.0';
+
+// Check if we come from index.php or update_courses.php - otherwise display error msg
+if (defined('SYSTEM_INSTALLATION')) {
+
+    // Check if the current Chamilo install is eligible for update
+    if (!file_exists('../inc/conf/configuration.php')) {
+        echo '<strong>'.get_lang('Error').' !</strong> Chamilo '.implode('|', $updateFromVersion).' '.get_lang('HasNotBeenFound').'.<br /><br />
+                                '.get_lang('PleasGoBackToStep1').'.
+                                <p><button type="submit" class="back" name="step1" value="&lt; '.get_lang('Back').'">'.get_lang('Back').'</button></p>
+                                </td></tr></table></form></body></html>';
+        exit ();
+    }
+
+    $_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');
+    }
+
+	$dbScormForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbScormForm);
+
+	if (!empty($dbPrefixForm) && strpos($dbScormForm, $dbPrefixForm) !== 0) {
+        $dbScormForm = $dbPrefixForm.$dbScormForm;
+    }
+
+    if (empty($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm) {
+        $dbScormForm = $dbPrefixForm.'scorm';
+    }
+
+    /*   Normal upgrade procedure: start by updating main, statistic, user databases */
+
+    // If this script has been included by index.php, not update_courses.php, so
+    // that we want to change the main databases as well...
+    $only_test = false;
+    if (defined('SYSTEM_INSTALLATION')) {
+        
+        if ($singleDbForm) {
+            $dbStatsForm = $dbNameForm;
+            $dbScormForm = $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
+            /**
+             * We connect to the right DB first to make sure we can use the queries
+             * without a database name
+             */
+            if (strlen($dbNameForm) > 40) {
+                Log::error('Database name '.$dbNameForm.' is too long, skipping');
+            } elseif (!in_array($dbNameForm, $dblist)) {
+                Log::error('Database '.$dbNameForm.' was not found, skipping');
+            } else {
+                iDatabase::select_db($dbNameForm);
+                foreach ($m_q_list as $query){
+                    if ($only_test) {
+                        Log::notice("iDatabase::query($dbNameForm,$query)");
+                    } else {
+                        $res = iDatabase::query($query);
+                        if ($res === false) {
+                        	Log::error('Error in '.$query.': '.iDatabase::error());
+                        }
+                    }
+                }
+            }
+        }
+        
+        if (INSTALL_TYPE_UPDATE == 'update') {
+            
+            //Migrate classes to the new classes (usergroups)
+            
+        }
+        
+    }    
+    
+} else {
+    echo 'You are not allowed here !' . __FILE__;
+}
+