upgrade_lib.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. if ($singleDbForm)
  89. {
  90. $prefix = $_configuration['table_prefix'];
  91. }
  92. //get the course databases queries list (c_q_list)
  93. $course_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','course');
  94. if(count($course_query_list) > 0)
  95. {
  96. //upgrade course databases
  97. }
  98. /*
  99. SCORM SECTION
  100. */
  101. //see include('update-db-scorm-1.6.x-1.8.0.inc.php');
  102. //deploy in separate function!
  103. /*
  104. POST SECTION
  105. UPGRADES TO GENERAL DATABASES after course upgrades
  106. */
  107. $main_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','main');
  108. if(count($main_query_list) > 0)
  109. {
  110. mysql_select_db($main_database);
  111. foreach($main_query_list as $this_query)
  112. {
  113. mysql_query($this_query);
  114. }
  115. }
  116. $tracking_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','stats');
  117. $tracking_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','stats');
  118. if(count($tracking_query_list) > 0)
  119. {
  120. mysql_select_db($tracking_database);
  121. foreach($tracking_query_list as $this_query)
  122. {
  123. mysql_query($this_query);
  124. }
  125. }
  126. $user_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','user');
  127. if(count($user_query_list) > 0)
  128. {
  129. mysql_select_db($user_database);
  130. foreach($user_query_list as $this_query)
  131. {
  132. mysql_query($this_query);
  133. }
  134. }
  135. $prefix = '';
  136. if ($singleDbForm)
  137. {
  138. $prefix = $_configuration['table_prefix'];
  139. }
  140. //get the course databases queries list (c_q_list)
  141. $course_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','course');
  142. if(count($course_query_list) > 0)
  143. {
  144. //upgrade course databases
  145. mysql_select_db($main_database);
  146. $sql_result = mysql_query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
  147. if(mysql_num_rows($sql_result) > 0)
  148. {
  149. while($row = mysql_fetch_array($sql_result))
  150. {
  151. $course_list[] = $row;
  152. }
  153. //for each course in the course list...
  154. foreach($course_list as $this_course)
  155. {
  156. mysql_select_db($this_course['db_name']);
  157. //... execute the list of course update queries
  158. foreach($course_query_list as $this_query)
  159. {
  160. if ($is_single_database) //otherwise just use the main one
  161. {
  162. $query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/',"$1 $prefix$2$3",$query);
  163. }
  164. mysql_query($this_query);
  165. }
  166. }
  167. }
  168. }
  169. }
  170. /**
  171. * Note - there is no 1.8.1,
  172. * 1.8.2 is the version that came after 1.8.0
  173. * see
  174. * - update-db-1.8.0-1.8.2.inc.php
  175. * - migrate-db-1.8.0-1.8.2-pre.sql
  176. */
  177. function upgrade_180_to_182($values)
  178. {
  179. }
  180. function upgrade_182_to_183($values)
  181. {
  182. //no database/file structure changes needed?
  183. }
  184. ?>