From 2df17831fb31cf72846e5e99fd049acb61a00245 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Mon, 15 Jan 2007 02:27:08 +0100 Subject: [PATCH] [svn r10712] Improvements to main database migration process --- main/install/migrate-db-1.6.x-1.8.0-post.sql | 5 + main/install/migrate-db-1.6.x-1.8.0-pre.sql | 42 ++++-- main/install/update_db.inc.php | 143 +++++++++++++++++-- 3 files changed, 166 insertions(+), 24 deletions(-) diff --git a/main/install/migrate-db-1.6.x-1.8.0-post.sql b/main/install/migrate-db-1.6.x-1.8.0-post.sql index 4fa9f1688a..e74fea0b3c 100644 --- a/main/install/migrate-db-1.6.x-1.8.0-post.sql +++ b/main/install/migrate-db-1.6.x-1.8.0-post.sql @@ -13,6 +13,11 @@ -- This first part is for the main database -- xxMAINxx +ALTER TABLE sys_announcement DROP COLUMN visible_teacher_temp; +ALTER TABLE sys_announcement DROP COLUMN visible_student_temp; +ALTER TABLE sys_announcement DROP COLUMN visible_guest_temp; + + -- xxSTATSxx -- xxUSERxx diff --git a/main/install/migrate-db-1.6.x-1.8.0-pre.sql b/main/install/migrate-db-1.6.x-1.8.0-pre.sql index 95f2083237..871382c022 100644 --- a/main/install/migrate-db-1.6.x-1.8.0-pre.sql +++ b/main/install/migrate-db-1.6.x-1.8.0-pre.sql @@ -12,12 +12,22 @@ -- -- This first part is for the main database -- xxMAINxx -ALTER TABLE admin CHANGE user_id user_id int unsigned NOT NULL default '0'; -ALTER TABLE class_user CHANGE class_id class_id mediumint unsigned NOT NULL default '0'; -ALTER TABLE class_user CHANGE user_id user_id int unsigned NOT NULL default '0'; +ALTER TABLE admin CHANGE user_id user_id int unsigned NOT NULL default 0; + +ALTER TABLE class_user CHANGE class_id class_id mediumint unsigned NOT NULL default 0; +ALTER TABLE class_user CHANGE user_id user_id int unsigned NOT NULL default 0; + ALTER TABLE course ADD registration_code varchar(255) NOT NULL default ''; -ALTER TABLE course_rel_class CHANGE class_id class_id mediumint unsigned NOT NULL default '0'; -ALTER TABLE course_rel_user CHANGE user_id user_id int unsigned NOT NULL default '0'; + +ALTER TABLE course_rel_user CHANGE user_id user_id int unsigned NOT NULL default 0; +ALTER TABLE course_rel_user CHANGE sort sort int default NULL; + +ALTER TABLE user CHANGE auth_source auth_source varchar(50) default 'platform'; +ALTER TABLE user ADD language varchar(40) default NULL; +ALTER TABLE user ADD registration_date datetime NOT NULL default '0000-00-00 00:00:00'; +ALTER TABLE user ADD expiration_date datetime NOT NULL default '0000-00-00 00:00:00'; +ALTER TABLE user ADD active enum('0','1') NOT NULL default '1'; + -- Rename table session into php_session RENAME TABLE session TO php_session; ALTER TABLE php_session DROP PRIMARY KEY; @@ -27,28 +37,36 @@ ALTER TABLE php_session CHANGE sess_time session_time int NOT NULL default '0'; ALTER TABLE php_session CHANGE sess_start session_start int NOT NULL default '0'; ALTER TABLE php_session CHANGE sess_value session_value text NOT NULL; ALTER TABLE php_session ADD PRIMARY KEY (session_id); + -- We might want to review the following table structure -- CREATE TABLE session (id smallint unsigned NOT NULL auto_increment, id_coach int unsigned NOT NULL default '0', name char(50) NOT NULL default '', nbr_courses smallint unsigned NOT NULL default '0', nbr_users mediumint unsigned NOT NULL default '0', nbr_classes mediumint unsigned NOT NULL default '0', date_start date NOT NULL default '0000-00-00', date_end date NOT NULL default '0000-00-00', PRIMARY KEY (id), UNIQUE KEY name (name)); + -- We might want to review the following table structure -- CREATE TABLE session_rel_course(id_session smallint unsigned NOT NULL default '0', course_code char(40) NOT NULL default '', id_coach int unsigned NOT NULL default '0', nbr_users smallint(5) unsigned NOT NULL default '0', PRIMARY KEY (id_session,course_code), KEY course_code (course_code)); + -- We might want to review the following table structure -- CREATE TABLE session_rel_course_rel_user(id_session smallint unsigned NOT NULL default '0', course_code char(40) NOT NULL default '', id_user int unsigned NOT NULL default '0', PRIMARY KEY (id_session,course_code,id_user), KEY id_user (id_user), KEY course_code (course_code)); + -- We might want to review the following table structure -- CREATE TABLE session_rel_user(id_session mediumint unsigned NOT NULL default '0', id_user mediumint unsigned NOT NULL default '0', PRIMARY KEY (id_session,id_user)); + -- We might want to review the following table structure -- CREATE TABLE course_rel_survey (id int NOT NULL auto_increment, course_code varchar(200) default NULL, db_name varchar(200) default NULL, survey_id varchar(200) default NULL, PRIMARY KEY (id)); + -- We might want to review the following table structure -- CREATE TABLE survey_reminder(sid int NOT NULL default '0', db_name varchar(100) NOT NULL default '', email varchar(100) NOT NULL default '', access int NOT NULL default '0', subject text NOT NULL, content text NOT NULL, reminder_choice int NOT NULL default '0', reminder_time text NOT NULL, avail_till date NOT NULL default '0000-00-00'); + -- We might want to review the following table structure -- CREATE TABLE survey_user_info(id int NOT NULL auto_increment, user_id int NOT NULL default '0', survey_id int NOT NULL default '0', db_name varchar(200) default NULL, firstname varchar(200) default NULL, lastname varchar(200) default NULL, email varchar(200) default NULL, organization text, age int default NULL, registered char(1) default NULL, attempted varchar(10) NOT NULL default '', PRIMARY KEY (id)); --- ALTER TABLE sys_announcement CHANGE visible_student visible_student enum('0','1') NOT NULL default '0'; --- ALTER TABLE sys_announcement CHANGE visible_guest visible_guest enum('0','1') NOT NULL default '0'; + +ALTER TABLE sys_announcement CHANGE visible_teacher visible_teacher_temp enum('true','false') NOT NULL DEFAULT 'false'; +ALTER TABLE sys_announcement CHANGE visible_student visible_student_temp enum('true','false') NOT NULL DEFAULT 'false'; +ALTER TABLE sys_announcement CHANGE visible_guest visible_guest_temp enum('true','false') NOT NULL DEFAULT 'false'; +ALTER TABLE sys_announcement ADD COLUMN visible_teacher tinyint NOT NULL DEFAULT 0; +ALTER TABLE sys_announcement ADD COLUMN visible_student tinyint NOT NULL DEFAULT 0; +ALTER TABLE sys_announcement ADD COLUMN visible_guest tinyint NOT NULL DEFAULT 0; ALTER TABLE sys_announcement ADD lang varchar(70) NULL; -ALTER TABLE user CHANGE auth_source auth_source varchar(50) default 'platform'; -ALTER TABLE user ADD language varchar(40) default NULL; -ALTER TABLE user ADD registration_date datetime NOT NULL default '0000-00-00 00:00:00'; -ALTER TABLE user ADD expiration_date datetime NOT NULL default '0000-00-00 00:00:00'; -ALTER TABLE user ADD active enum('0','1') NOT NULL default '1'; + -- xxSTATSxx CREATE TABLE track_e_attempt(exe_id int default NULL, user_id int NOT NULL default '0', question_id int NOT NULL default '0', answer text NOT NULL, teacher_comment text NOT NULL, marks int NOT NULL default '0', course_code varchar(40) NOT NULL default '', position int default '0'); CREATE TABLE track_e_course_access(course_access_id int NOT NULL auto_increment, course_code varchar(40) NOT NULL, user_id int NOT NULL, login_course_date datetime NOT NULL default '0000-00-00 00:00:00', logout_course_date datetime default NULL, counter int NOT NULL, PRIMARY KEY (course_access_id)); diff --git a/main/install/update_db.inc.php b/main/install/update_db.inc.php index a712950af9..ce58f22a54 100644 --- a/main/install/update_db.inc.php +++ b/main/install/update_db.inc.php @@ -49,7 +49,7 @@ require_once("install_upgrade.lib.php"); if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) { //check if the current Dokeos install is elligible for update - if (empty ($updateFromConfigFile) || !file_exists($_POST['updatePath'].$updateFromConfigFile) || !in_array(get_config_param('clarolineVersion'), $updateFromVersion)) + if (empty ($updateFromConfigFile) || !file_exists($_POST['updatePath'].$updateFromConfigFile) || !in_array(get_config_param('clarolineVersion'), $update_from_version)) { echo ''.get_lang('Error').' ! Dokeos '.implode('|', $updateFromVersion).' '.get_lang('HasNotBeenFound').'.

'.get_lang('PleasGoBackToStep1').'. @@ -103,26 +103,107 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) /* ----------------------------------------------------------- Normal upgrade procedure: - start by updating main, statistic, scorm, user databases + start by updating main, statistic, user databases ----------------------------------------------------------- */ - if (defined('DOKEOS_INSTALL')) + //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 = true; + if (defined('DOKEOS_INSTALL')) { - /* - ----------------------------------------------------------- - Update the main Dokeos database - ----------------------------------------------------------- - */ + /** + * 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"); } //TODO deal with migrate-db-1.6.x-1.8.0-pre.sql here + //get the main queries list (m_q_list) + $m_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-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 + */ + mysql_select_db($dbNameForm); + foreach($m_q_list as $query){ + if($only_test){ + echo "mysql_query($dbNameForm,$query)
"; + }else{ + $res = mysql_query($query); + } + } + } + //manual updates in here + //update all users with auth_source 'claroline' to auth_source 'platform' + //$sql_upd = "UPDATE user SET auth_source='platform' WHERE auth_source='claroline'"; + //$res_upd = mysql_query($sql_upd); + //update all registration_date, expiration_date and active fields + //$sql_upd = "UPDATE user SET registration_date=NOW()"; + //$res_upd = mysql_query($sql_upd); + //update all sys_announcement.visible_* fields to become tinyint + //$sql_upd = "UPDATE sys_announcement SET visible_teacher = 0 WHERE visible_teacher_temp='false'"; + //$res_upd = mysql_query($sql_upd); + //$sql_upd = "UPDATE sys_announcement SET visible_teacher = 1 WHERE visible_teacher_temp='true'"; + //$res_upd = mysql_query($sql_upd); + //$sql_upd = "UPDATE sys_announcement SET visible_student = 0 WHERE visible_student_temp='false'"; + //$res_upd = mysql_query($sql_upd); + //$sql_upd = "UPDATE sys_announcement SET visible_student = 1 WHERE visible_student_temp='true'"; + //$res_upd = mysql_query($sql_upd); + //$sql_upd = "UPDATE sys_announcement SET visible_guest = 0 WHERE visible_guest_temp='false'"; + //$res_upd = mysql_query($sql_upd); + //$sql_upd = "UPDATE sys_announcement SET visible_guest = 1 WHERE visible_guest_temp='true'"; + //$res_upd = mysql_query($sql_upd); + //end of manual updates + //get the stats queries list (s_q_list) + $s_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','stats'); + if(count($s_q_list)>0) + { + //now use the $s_q_list + /** + * We connect to the right DB first to make sure we can use the queries + * without a database name + */ + mysql_select_db($dbStatsForm); + foreach($s_q_list as $query){ + if($only_test){ + echo "mysql_query($dbStatsForm,$query)
"; + }else{ + $res = mysql_query($query); + } + } + } + //get the user queries list (u_q_list) + $u_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','user'); + if(count($u_q_list)>0) + { + //now use the $u_q_list + /** + * We connect to the right DB first to make sure we can use the queries + * without a database name + */ + mysql_select_db($dbUserForm); + foreach($u_q_list as $query){ + if($only_test){ + echo "mysql_query($dbUserForm,$query)
"; + }else{ + $res = mysql_query($query); + } + } + } + //the SCORM database doesn't need a change in the pre-migrate part - ignore + + die(); //TODO only update this table + /* $language_table = "`$dbNameForm`.`language`"; fill_language_table($language_table); @@ -154,7 +235,8 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) // ('".TOOL_RECYCLE_COURSE."', 'coursecopy/recycle_course.php' , 'recycle.gif', 2, 3, 'courseadmin')"); //... //mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_LEARNPATH."' WHERE link LIKE 'scorm/%'"); - + */ + } /* ----------------------------------------------------------- @@ -168,6 +250,46 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) MAX_COURSE_TRANSFER courses are upgraded. ----------------------------------------------------------- */ + + //get the courses databases queries list (c_q_list) + $c_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','course'); + if(count($c_q_list)>0) + { + //get the courses list + mysql_select_db($dbNameForm); + $res = mysql_query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL"); + if($res===false){die('Error while querying the courses list in update_db.inc.php');} + if(mysql_num_rows($res)>0) + { + while($row = mysql_fetch_array($res)) + { + $list[] = $row; + } + foreach($list as $row) + { + //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 + */ + mysql_select_db($row['db_name']); + foreach($c_q_list as $query) + { + if($only_test) + { + echo "mysql_query(".$row['db_name'].",$query)
"; + }else{ + $res = mysql_query($query); + } + } + } + } + } + + + + + $newPath = str_replace('\\', '/', realpath('../..')).'/'; $coursePath = array (); @@ -515,7 +637,4 @@ function get_forumcategory_id_by_name($forum_category_name) //echo $row['cat_id']; return $row['cat_id']; } - - - ?> \ No newline at end of file