upgrade_lib.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2007, various contributors
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  14. Mail: info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * This file contains functions used by the new upgrade script.
  20. ==============================================================================
  21. */
  22. /*
  23. ==============================================================================
  24. CONSTANTS
  25. ==============================================================================
  26. */
  27. /*
  28. ==============================================================================
  29. FUNCTIONS
  30. ==============================================================================
  31. */
  32. /**
  33. * see
  34. * - update-db-1.6.x-1.8.0.inc.php
  35. * - update-db-scorm-1.6.x-1.8.0.inc.php
  36. * - migrate-db-1.6.x-1.8.0-post.sql
  37. * - migrate-db-1.6.x-1.8.0-pre.sql
  38. * @todo remove code duplication in this function
  39. */
  40. function upgrade_16x_to_180($values)
  41. {
  42. $is_single_database = $values['database_single'];
  43. $main_database = $values['database_main_db'];
  44. $tracking_database = $values['database_tracking'];
  45. $user_database = $values['database_user'];
  46. /*
  47. PRE SECTION
  48. UPGRADES TO GENERAL DATABASES before course upgrades
  49. */
  50. //MAIN database section
  51. //Get the list of queries to upgrade the main database
  52. $main_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','main');
  53. if(count($main_query_list) > 0)
  54. {
  55. mysql_select_db($main_database);
  56. foreach($main_query_list as $this_query)
  57. {
  58. mysql_query($this_query);
  59. }
  60. }
  61. //TRACKING database section
  62. //Get the list of queries to upgrade the statistics/tracking database
  63. $tracking_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','stats');
  64. if(count($tracking_query_list) > 0)
  65. {
  66. mysql_select_db($tracking_database);
  67. foreach($tracking_query_list as $this_query)
  68. {
  69. mysql_query($this_query);
  70. }
  71. }
  72. //USER database section
  73. //Get the list of queries to upgrade the user database
  74. $user_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','user');
  75. if(count($user_query_list) > 0)
  76. {
  77. mysql_select_db($user_database);
  78. foreach($user_query_list as $this_query)
  79. {
  80. mysql_query($this_query);
  81. }
  82. }
  83. /*
  84. COURSE SECTION
  85. UPGRADES TO COURSE DATABASES
  86. */
  87. $prefix = '';
  88. global $singleDbForm, $_configuration;
  89. if ($singleDbForm)
  90. {
  91. $prefix = $_configuration['table_prefix'];
  92. }
  93. //get the course databases queries list (c_q_list)
  94. $course_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','course');
  95. if(count($course_query_list) > 0)
  96. {
  97. //upgrade course databases
  98. }
  99. /*
  100. SCORM SECTION
  101. */
  102. //see include('update-db-scorm-1.6.x-1.8.0.inc.php');
  103. //deploy in separate function!
  104. /*
  105. POST SECTION
  106. UPGRADES TO GENERAL DATABASES after course upgrades
  107. */
  108. $main_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','main');
  109. if(count($main_query_list) > 0)
  110. {
  111. mysql_select_db($main_database);
  112. foreach($main_query_list as $this_query)
  113. {
  114. mysql_query($this_query);
  115. }
  116. }
  117. $tracking_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','stats');
  118. $tracking_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','stats');
  119. if(count($tracking_query_list) > 0)
  120. {
  121. mysql_select_db($tracking_database);
  122. foreach($tracking_query_list as $this_query)
  123. {
  124. mysql_query($this_query);
  125. }
  126. }
  127. $user_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','user');
  128. if(count($user_query_list) > 0)
  129. {
  130. mysql_select_db($user_database);
  131. foreach($user_query_list as $this_query)
  132. {
  133. mysql_query($this_query);
  134. }
  135. }
  136. $prefix = '';
  137. if ($singleDbForm)
  138. {
  139. $prefix = $_configuration['table_prefix'];
  140. }
  141. //get the course databases queries list (c_q_list)
  142. $course_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','course');
  143. if(count($course_query_list) > 0)
  144. {
  145. //upgrade course databases
  146. mysql_select_db($main_database);
  147. $sql_result = mysql_query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
  148. if(mysql_num_rows($sql_result) > 0)
  149. {
  150. while($row = mysql_fetch_array($sql_result))
  151. {
  152. $course_list[] = $row;
  153. }
  154. //for each course in the course list...
  155. foreach($course_list as $this_course)
  156. {
  157. mysql_select_db($this_course['db_name']);
  158. //... execute the list of course update queries
  159. foreach($course_query_list as $this_query)
  160. {
  161. if ($is_single_database) //otherwise just use the main one
  162. {
  163. $query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/',"$1 $prefix$2$3",$query);
  164. }
  165. mysql_query($this_query);
  166. }
  167. }
  168. }
  169. }
  170. }
  171. /**
  172. * Note - there is no 1.8.1,
  173. * 1.8.2 is the version that came after 1.8.0
  174. * see
  175. * - update-db-1.8.0-1.8.2.inc.php
  176. * - migrate-db-1.8.0-1.8.2-pre.sql
  177. */
  178. function upgrade_180_to_182($values)
  179. {
  180. }
  181. function upgrade_182_to_183($values)
  182. {
  183. //no database/file structure changes needed?
  184. }
  185. ?>