PageRenderTime 71ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/claroline/admin/upgrade/upgrade_course_110.lib.php

https://github.com/TeamRocketScience/Claroline-TRS-Edition
PHP | 285 lines | 160 code | 84 blank | 41 comment | 20 complexity | 382ea6ff1e2665c6d19819421b312ebb MD5 | raw file
  1. <?php // $Id$
  2. if ( count( get_included_files() ) == 1 ) die( '---' );
  3. /**
  4. * CLAROLINE
  5. *
  6. * Function to update course tool from 1.9 to 1.10
  7. *
  8. * - READ THE SAMPLE AND COPY PASTE IT
  9. * - ADD TWICE MORE COMMENT THAT YOU THINK NEEDED
  10. *
  11. * This code would be splited by task for the 1.8 Stable but code inside
  12. * function won't change, so let's go to write it.
  13. *
  14. * @version 1.10 $Revision: 12380 $
  15. * @copyright (c) 2001-2011, Universite catholique de Louvain (UCL)
  16. * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE
  17. * @package UPGRADE
  18. * @author Claro Team <cvs@claroline.net>
  19. * @author Antonin Bourguignon <antonin.bourguignon@claroline.net>
  20. *
  21. */
  22. /*===========================================================================
  23. Upgrade to claroline 1.10
  24. ===========================================================================*/
  25. function announcements_upgrade_to_110 ($course_code)
  26. {
  27. global $currentCourseVersion;
  28. $versionRequiredToProceed = '/^1.9/';
  29. $tool = 'ANNOUNCEMENTS';
  30. $currentCourseDbNameGlu = claro_get_course_db_name_glued($course_code);
  31. if ( preg_match($versionRequiredToProceed,$currentCourseVersion) )
  32. {
  33. // On init , $step = 1
  34. switch( $step = get_upgrade_status($tool,$course_code) )
  35. {
  36. case 1 :
  37. // Add the attribute sourceCourseId to the course table
  38. $sqlForUpdate[] = "ALTER TABLE `" . $currentCourseDbNameGlu . "announcement` ADD `visibleFrom` DATE NULL DEFAULT NULL AFTER `contenu`";
  39. if ( upgrade_apply_sql($sqlForUpdate) ) $step = set_upgrade_status($tool, $step+1, $course_code);
  40. else return $step;
  41. unset($sqlForUpdate);
  42. case 2 :
  43. // Add the attribute sourceCourseId to the course table
  44. $sqlForUpdate[] = "ALTER TABLE `" . $currentCourseDbNameGlu . "announcement` ADD `visibleUntil` DATE NULL DEFAULT NULL AFTER `visibleFrom`";
  45. if ( upgrade_apply_sql($sqlForUpdate) ) $step = set_upgrade_status($tool, $step+1, $course_code);
  46. else return $step;
  47. unset($sqlForUpdate);
  48. default :
  49. $step = set_upgrade_status($tool, 0);
  50. return $step;
  51. }
  52. }
  53. return false;
  54. }
  55. function calendar_upgrade_to_110 ($course_code)
  56. {
  57. global $currentCourseVersion;
  58. $versionRequiredToProceed = '/^1.9/';
  59. $tool = 'CALENDAR';
  60. $currentCourseDbNameGlu = claro_get_course_db_name_glued($course_code);
  61. if ( preg_match($versionRequiredToProceed,$currentCourseVersion) )
  62. {
  63. // On init , $step = 1
  64. switch( $step = get_upgrade_status($tool,$course_code) )
  65. {
  66. case 1 :
  67. // Add the attribute sourceCourseId to the course table
  68. $sqlForUpdate[] = "ALTER TABLE `" . $currentCourseDbNameGlu . "calendar_event` ADD `speakers` VARCHAR(150) NULL DEFAULT NULL AFTER `lasting`";
  69. if ( upgrade_apply_sql($sqlForUpdate) ) $step = set_upgrade_status($tool, $step+1, $course_code);
  70. else return $step;
  71. unset($sqlForUpdate);
  72. case 2 :
  73. // Change the attribute location
  74. $sqlForUpdate[] = "ALTER TABLE `" . $currentCourseDbNameGlu . "calendar_event` CHANGE `location` `location` VARCHAR(150) NULL DEFAULT NULL";
  75. if ( upgrade_apply_sql($sqlForUpdate) ) $step = set_upgrade_status($tool, $step+1, $course_code);
  76. else return $step;
  77. unset($sqlForUpdate);
  78. case 3 :
  79. // Add the attribute group_id into the course table
  80. $sqlForUpdate[] = "ALTER TABLE `" . $currentCourseDbNameGlu . "calendar_event` ADD `group_id` INT(4) NOT NULL DEFAULT 0";
  81. if ( upgrade_apply_sql($sqlForUpdate) ) $step = set_upgrade_status($tool, $step+1, $course_code);
  82. else return $step;
  83. unset($sqlForUpdate);
  84. default :
  85. $step = set_upgrade_status($tool, 0);
  86. return $step;
  87. }
  88. }
  89. return false;
  90. }
  91. function exercise_upgrade_to_110 ($course_code)
  92. {
  93. global $currentCourseVersion;
  94. $versionRequiredToProceed = '/^1.9/';
  95. $tool = 'CLQWZ';
  96. $currentCourseDbNameGlu = claro_get_course_db_name_glued($course_code);
  97. if ( preg_match($versionRequiredToProceed,$currentCourseVersion) )
  98. {
  99. // On init , $step = 1
  100. switch( $step = get_upgrade_status($tool,$course_code) )
  101. {
  102. case 1 :
  103. // Add the attribute sourceCourseId to the course table
  104. $sqlForUpdate[] = "ALTER TABLE `" . $currentCourseDbNameGlu . "qwz_question` ADD `id_category` INT(11) NULL DEFAULT '0' AFTER `grade`";
  105. upgrade_apply_sql($sqlForUpdate);
  106. $step = set_upgrade_status($tool, $step+1, $course_code);
  107. unset($sqlForUpdate);
  108. case 2 :
  109. // Add the key
  110. $sqlForUpdate[] = "ALTER TABLE `" . $currentCourseDbNameGlu . "qwz_tracking` ADD INDEX `user_id` (`user_id`)";
  111. upgrade_apply_sql($sqlForUpdate);
  112. $step = set_upgrade_status($tool, $step+1, $course_code);
  113. unset($sqlForUpdate);
  114. case 3 :
  115. // Add the key
  116. $sqlForUpdate[] = "ALTER TABLE `" . $currentCourseDbNameGlu . "qwz_tracking` ADD INDEX `exo_id` (`exo_id`)";
  117. upgrade_apply_sql($sqlForUpdate);
  118. $step = set_upgrade_status($tool, $step+1, $course_code);
  119. unset($sqlForUpdate);
  120. case 4 :
  121. // Add the key
  122. $sqlForUpdate[] = "ALTER TABLE `" . $currentCourseDbNameGlu . "qwz_tracking_questions` ADD INDEX `exercise_track_id` (`exercise_track_id`)";
  123. upgrade_apply_sql($sqlForUpdate);
  124. $step = set_upgrade_status($tool, $step+1, $course_code);
  125. unset($sqlForUpdate);
  126. case 5 :
  127. // Add the key
  128. $sqlForUpdate[] = "ALTER TABLE `" . $currentCourseDbNameGlu . "qwz_tracking_questions` ADD INDEX `question_id` (`question_id`)";
  129. upgrade_apply_sql($sqlForUpdate);
  130. $step = set_upgrade_status($tool, $step+1, $course_code);
  131. unset($sqlForUpdate);
  132. case 6 :
  133. // Add the key
  134. $sqlForUpdate[] = "ALTER TABLE `" . $currentCourseDbNameGlu . "qwz_tracking_answers` ADD INDEX `details_id` (`details_id`)";
  135. upgrade_apply_sql($sqlForUpdate);
  136. $step = set_upgrade_status($tool, $step+1, $course_code);
  137. unset($sqlForUpdate);
  138. case 7 :
  139. $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $currentCourseDbNameGlu . "qwz_users_random_questions` (
  140. `id` int(11) NOT NULL auto_increment,
  141. `user_id` int(11) NOT NULL,
  142. `exercise_id` int(11) NOT NULL,
  143. `questions` text NOT NULL,
  144. PRIMARY KEY (`id`)
  145. ) ENGINE=MyISAM;";
  146. $step = set_upgrade_status( $tool, $step+1, $course_code);
  147. default :
  148. $step = set_upgrade_status($tool, 0);
  149. return $step;
  150. }
  151. }
  152. return false;
  153. }
  154. function tool_intro_upgrade_to_110 ($course_code)
  155. {
  156. global $currentCourseVersion;
  157. $versionRequiredToProceed = '/^1.9/';
  158. $tool = 'CLTI';
  159. $currentCourseDbNameGlu = claro_get_course_db_name_glued($course_code);
  160. if ( preg_match($versionRequiredToProceed,$currentCourseVersion) )
  161. {
  162. // On init , $step = 1
  163. switch( $step = get_upgrade_status($tool,$course_code) )
  164. {
  165. case 1 :
  166. // Are there any tool_intro to migrate ?
  167. $req = "SELECT
  168. COUNT(id) AS nbToolIntro
  169. FROM `" . $currentCourseDbNameGlu . "tool_intro`
  170. WHERE `tool_id` <= 0";
  171. $sql = mysql_query($req);
  172. $res = mysql_fetch_assoc($sql);
  173. // If yes: create a portlet for this course in `rel_course_portlet`
  174. if (isset($res['nbToolIntro']) && $res['nbToolIntro'] > 0)
  175. {
  176. // Select the id of the course (int)
  177. $req = "SELECT cours_id AS courseId
  178. FROM `" . get_conf('mainTblPrefix') . "cours`
  179. WHERE `code` = '".$course_code."'";
  180. $sql = mysql_query($req);
  181. $res = mysql_fetch_assoc($sql);
  182. // Insert the portlet
  183. $sqlForUpdate[] = "INSERT INTO `" . get_conf('mainTblPrefix') . "rel_course_portlet`
  184. (courseId, rank, label, visible)
  185. VALUES
  186. ('".$res['courseId']."', 1, 'CLTI', 1)";
  187. }
  188. else
  189. {
  190. $sqlForUpdate = array();
  191. }
  192. if ( upgrade_apply_sql($sqlForUpdate) ) $step = set_upgrade_status($tool, $step+1, $course_code);
  193. else return $step;
  194. unset($sqlForUpdate);
  195. default :
  196. $step = set_upgrade_status($tool, 0);
  197. return $step;
  198. }
  199. }
  200. return false;
  201. }