Version20151101082300.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. namespace Application\Migrations\Schema\V110;
  4. use Application\Migrations\AbstractMigrationChamilo;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\DBAL\Types\Type;
  7. /**
  8. * Calendar color
  9. */
  10. class Version20151101082300 extends AbstractMigrationChamilo
  11. {
  12. /**
  13. * @param Schema $schema
  14. */
  15. public function up(Schema $schema)
  16. {
  17. $accessUrl = $schema->getTable('access_url');
  18. $accessUrl->getColumn('id')->setUnsigned(false);
  19. $this->connection->executeQuery('UPDATE access_url_rel_course SET access_url_id = NULL WHERE access_url_id NOT IN (SELECT id FROM access_url)');
  20. $accessUrlRelCourse = $schema->getTable('access_url_rel_course');
  21. $accessUrlRelCourse->getColumn('access_url_id')->setUnsigned(false);
  22. $accessUrlRelCourse->addForeignKeyConstraint('access_url', ['access_url_id'], ['id']);
  23. $accessUrlRelCourse->addForeignKeyConstraint('course', ['c_id'], ['id']);
  24. if ($schema->hasTable('class')) {
  25. $schema->renameTable('class', 'class_item');
  26. }
  27. if ($schema->hasTable('class_user')) {
  28. $classUser = $schema->getTable('class_user');
  29. $classUser->getColumn('class_id')->setUnsigned(false);
  30. $classUser->getColumn('user_id')->setUnsigned(false);
  31. }
  32. $course = $schema->getTable('course');
  33. $course->getColumn('course_type_id')->setUnsigned(false);
  34. $course->addForeignKeyConstraint('room', ['room_id'], ['id']);
  35. if ($schema->hasTable('course_rel_class')) {
  36. $courseRelClass = $schema->getTable('course_rel_class');
  37. $courseRelClass->getColumn('class_id')->setUnsigned(false)->setType(Type::getType(Type::INTEGER));
  38. }
  39. $courseRelUser = $schema->getTable('course_rel_user');
  40. $courseRelUser->addForeignKeyConstraint('course', ['c_id'], ['id']);
  41. $courseRelUser->addForeignKeyConstraint('user', ['user_id'], ['id']);
  42. if ($schema->hasTable('course_type')) {
  43. $courseType = $schema->getTable('course_type');
  44. $courseType->getColumn('id')->setUnsigned(false);
  45. }
  46. $schema->getTable('c_announcement')->addIndex(['c_id']);
  47. $schema->getTable('c_announcement_attachment')->addIndex(['c_id']);
  48. $schema->getTable('c_attendance')->addIndex(['c_id']);
  49. $schema->getTable('c_attendance_calendar')->addIndex(['c_id']);
  50. $cAttendanceCalendarRelGroup = $schema->getTable('c_attendance_calendar_rel_group');
  51. $cAttendanceCalendarRelGroup->addIndex(['c_id']);
  52. $cAttendanceCalendarRelGroup->addIndex(['group_id']);
  53. $schema->getTable('c_attendance_result')->addIndex(['c_id']);
  54. $cAttendanceSheet = $schema->getTable('c_attendance_sheet');
  55. $cAttendanceSheet->addIndex(['c_id']);
  56. $cAttendanceSheet->addIndex(['user_id']);
  57. $schema->getTable('c_attendance_sheet_log')->addIndex(['c_id']);
  58. $schema->getTable('c_blog')->addIndex(['c_id']);
  59. $schema->getTable('c_blog_attachment')->addIndex(['c_id']);
  60. $schema->getTable('c_blog_comment')->addIndex(['c_id']);
  61. $schema->getTable('c_blog_post')->addIndex(['c_id']);
  62. $schema->getTable('c_blog_rating')->addIndex(['c_id']);
  63. $cBlogRelUser = $schema->getTable('c_blog_rel_user');
  64. $cBlogRelUser->getColumn('blog_id')->setUnsigned(false);
  65. $cBlogRelUser->getColumn('user_id')->setUnsigned(false);
  66. $cBlogRelUser->addIndex(['c_id']);
  67. $schema->getTable('c_blog_task')->addIndex(['c_id']);
  68. $cBlogTaskRelUser = $schema->getTable('c_blog_task_rel_user');
  69. $cBlogTaskRelUser->getColumn('blog_id')->setUnsigned(false);
  70. $cBlogTaskRelUser->getColumn('user_id')->setUnsigned(false);
  71. $cBlogTaskRelUser->getColumn('task_id')->setUnsigned(false);
  72. $cBlogTaskRelUser->addIndex(['c_id']);
  73. $cBlogTaskRelUser->addIndex(['user_id']);
  74. $cBlogTaskRelUser->addIndex(['task_id']);
  75. $cCalendarEvent = $schema->getTable('c_calendar_event');
  76. $cCalendarEvent->addIndex(['c_id']);
  77. $schema->getTable('c_calendar_event_attachment')->addIndex(['c_id']);
  78. $schema->getTable('c_calendar_event_repeat')->addIndex(['c_id']);
  79. $schema->getTable('c_calendar_event_repeat_not')->addIndex(['c_id']);
  80. $cChatConnected = $schema->getTable('c_chat_connected');
  81. $cChatConnected->addIndex(['c_id']);
  82. $cChatConnected->addIndex(['user_id']);
  83. $schema->getTable('c_course_setting')->addIndex(['c_id']);
  84. $schema->getTable('c_document')->addIndex(['c_id']);
  85. $schema->getTable('c_dropbox_category')->addIndex(['c_id']);
  86. $schema->getTable('c_dropbox_feedback')->addIndex(['c_id']);
  87. $schema->getTable('c_dropbox_file')->addIndex(['c_id']);
  88. $cDropboxPerson = $schema->getTable('c_dropbox_person');
  89. $cDropboxPerson->addIndex(['c_id']);
  90. $cDropboxPerson->addIndex(['user_id']);
  91. $cDropboxPost = $schema->getTable('c_dropbox_post');
  92. $cDropboxPost->addIndex(['c_id']);
  93. $cDropboxPost->addIndex(['dest_user_id']);
  94. $schema->getTable('c_forum_attachment')->addIndex(['c_id']);
  95. $schema->getTable('c_forum_category')->addIndex(['c_id']);
  96. $schema->getTable('c_forum_forum')->addIndex(['c_id']);
  97. $cForumMailcue = $schema->getTable('c_forum_mailcue');
  98. $cForumMailcue->addIndex(['c_id']);
  99. $cForumMailcue->addIndex(['thread_id']);
  100. $cForumMailcue->addIndex(['user_id']);
  101. $cForumMailcue->addIndex(['post_id']);
  102. $cForumNotification = $schema->getTable('c_forum_notification');
  103. $cForumNotification->addIndex(['c_id']);
  104. $cForumNotification->addIndex(['thread_id']);
  105. $cForumNotification->addIndex(['post_id']);
  106. $schema->getTable('c_forum_post')->addIndex(['c_id']);
  107. $schema->getTable('c_forum_thread')->addIndex(['c_id']);
  108. $schema->getTable('c_forum_thread_qualify')->addIndex(['c_id']);
  109. $schema->getTable('c_forum_thread_qualify_log')->addIndex(['c_id']);
  110. $schema->getTable('c_glossary')->addIndex(['c_id']);
  111. $schema->getTable('c_group_category')->addIndex(['c_id']);
  112. $schema->getTable('c_group_info')->addIndex(['c_id']);
  113. $schema->getTable('c_group_rel_tutor')->addIndex(['c_id']);
  114. $schema->getTable('c_group_rel_user')->addIndex(['c_id']);
  115. $schema->getTable('c_link')->addIndex(['c_id']);
  116. $schema->getTable('c_link_category')->addIndex(['c_id']);
  117. $schema->getTable('c_lp')->addIndex(['c_id']);
  118. $schema->getTable('c_lp_category')->addIndex(['c_id']);
  119. $schema->getTable('c_lp_item')->addIndex(['c_id']);
  120. $schema->getTable('c_lp_item_view')->addIndex(['c_id']);
  121. $schema->getTable('c_lp_iv_interaction')->addIndex(['c_id']);
  122. $schema->getTable('c_lp_iv_objective')->addIndex(['c_id']);
  123. $schema->getTable('c_lp_view')->addIndex(['c_id']);
  124. $schema->getTable('c_notebook')->addIndex(['c_id']);
  125. $schema->getTable('c_online_connected')->addIndex(['c_id']);
  126. $schema->getTable('c_online_link')->addIndex(['c_id']);
  127. $schema->getTable('c_permission_group')->addIndex(['c_id']);
  128. $schema->getTable('c_permission_task')->addIndex(['c_id']);
  129. $schema->getTable('c_permission_user')->addIndex(['c_id']);
  130. $schema->getTable('c_quiz')->addIndex(['c_id']);
  131. $schema->getTable('c_quiz_answer')->addIndex(['c_id']);
  132. $schema->getTable('c_quiz_question')->addIndex(['c_id']);
  133. $schema->getTable('c_quiz_question_category')->addIndex(['c_id']);
  134. $schema->getTable('c_quiz_question_option')->addIndex(['c_id']);
  135. $schema->getTable('c_quiz_question_rel_category')->addIndex(['c_id']);
  136. $cQuizRelQuestion = $schema->getTable('c_quiz_rel_question');
  137. $cQuizRelQuestion->addIndex(['c_id']);
  138. $cQuizRelQuestion->addIndex(['question_id']);
  139. $cQuizRelQuestion->addIndex(['exercice_id']);
  140. $schema->getTable('c_resource')->addIndex(['c_id']);
  141. $schema->getTable('c_role')->addIndex(['c_id']);
  142. $cRoleGroup = $schema->getTable('c_role_group');
  143. $cRoleGroup->addIndex(['c_id']);
  144. $cRoleGroup->addIndex(['group_id']);
  145. $cRolePermissions = $schema->getTable('c_role_permissions');
  146. $cRolePermissions->addIndex(['c_id']);
  147. $cRolePermissions->addIndex(['role_id']);
  148. $cRoleUser = $schema->getTable('c_role_user');
  149. $cRoleUser->addIndex(['c_id']);
  150. $cRoleUser->addIndex(['user_id']);
  151. $schema->getTable('c_student_publication')->addIndex(['c_id']);
  152. $schema->getTable('c_student_publication_assignment')->addIndex(['c_id']);
  153. $cStudentPublicationComment = $schema->getTable('c_student_publication_comment');
  154. $cStudentPublicationComment->addIndex(['c_id']);
  155. $cStudentPublicationComment->addIndex(['user_id']);
  156. $cStudentPublicationComment->addIndex(['work_id']);
  157. $cStudentPublicationComment = $schema->getTable('c_student_publication_rel_document');
  158. $cStudentPublicationComment->addIndex(['c_id']);
  159. $cStudentPublicationComment->addIndex(['work_id']);
  160. $cStudentPublicationComment->addIndex(['document_id']);
  161. $cStudentPublicationComment = $schema->getTable('c_student_publication_rel_user');
  162. $cStudentPublicationComment->addIndex(['c_id']);
  163. $cStudentPublicationComment->addIndex(['work_id']);
  164. $cStudentPublicationComment->addIndex(['user_id']);
  165. $schema->getTable('c_survey')->addIndex(['c_id']);
  166. $schema->getTable('c_survey_answer')->addIndex(['c_id']);
  167. $schema->getTable('c_survey_group')->addIndex(['c_id']);
  168. $schema->getTable('c_survey_invitation')->addIndex(['c_id']);
  169. $schema->getTable('c_survey_question')->addIndex(['c_id']);
  170. $schema->getTable('c_survey_question_option')->addIndex(['c_id']);
  171. $schema->getTable('c_thematic')->addIndex(['c_id']);
  172. $schema->getTable('c_thematic_advance')->addIndex(['c_id']);
  173. $schema->getTable('c_thematic_plan')->addIndex(['c_id']);
  174. $schema->getTable('c_tool')->addIndex(['c_id']);
  175. $schema->getTable('c_tool_intro')->addIndex(['c_id']);
  176. $schema->getTable('c_userinfo_content')->addIndex(['c_id']);
  177. $schema->getTable('c_userinfo_def')->addIndex(['c_id']);
  178. $schema->getTable('c_wiki')->addIndex(['c_id']);
  179. $schema->getTable('c_wiki_conf')->addIndex(['c_id']);
  180. $schema->getTable('c_wiki_discuss')->addIndex(['c_id']);
  181. $cWikiMailcue = $schema->getTable('c_wiki_mailcue');
  182. $cWikiMailcue->addIndex(['c_id']);
  183. $cWikiMailcue->addIndex(['user_id']);
  184. $schema->getTable('extra_field_values')->addForeignKeyConstraint('extra_field', ['field_id'], ['id']);
  185. $session = $schema->getTable('session');
  186. $session->getColumn('id_coach')->setUnsigned(false);
  187. $session->addIndex(['session_category_id']);
  188. $session->addIndex(['id_coach']);
  189. $session->addForeignKeyConstraint('session_category', ['session_category_id'], ['id']);
  190. $session->addForeignKeyConstraint('user', ['id_coach'], ['id']);
  191. $this->connection->executeQuery('UPDATE session_category SET access_url_id = 1 WHERE access_url_id NOT IN (SELECT id FROM access_url)');
  192. $sessionCategory = $schema->getTable('session_category');
  193. $sessionCategory->addIndex(['access_url_id']);
  194. $sessionCategory->addForeignKeyConstraint('access_url', ['access_url_id'], ['id']);
  195. $sessionRelCourse = $schema->getTable('session_rel_course');
  196. $sessionRelCourse->dropColumn('course_code');
  197. $sessionRelCourse->addColumn('id', Type::INTEGER)->setAutoincrement(true);
  198. $sessionRelCourse->getColumn('c_id')->setUnsigned(false);
  199. $sessionRelCourse->setPrimaryKey(['id']);
  200. $sessionRelCourse->addIndex(['c_id']);
  201. $sessionRelCourse->addIndex(['session_id']);
  202. $sessionRelCourse->addForeignKeyConstraint('course', ['c_id'], ['id']);
  203. $sessionRelCourse->addForeignKeyConstraint('session', ['session_id'], ['id']);
  204. $this->connection->executeQuery('DELETE FROM session_rel_course_rel_user WHERE c_id NOT IN (SELECT id FROM course)');
  205. $this->connection->executeQuery('DELETE FROM session_rel_course_rel_user WHERE session_id NOT IN (SELECT id FROM session)');
  206. $this->connection->executeQuery('DELETE FROM session_rel_course_rel_user WHERE user_id NOT IN (SELECT id FROM user)');
  207. $sessionRelCourseRelUser = $schema->getTable('session_rel_course_rel_user');
  208. $sessionRelCourseRelUser->dropColumn('course_code');
  209. $sessionRelCourseRelUser->addColumn('id', Type::INTEGER)->setAutoincrement(true);
  210. $sessionRelCourseRelUser->getColumn('c_id')->setUnsigned(false);
  211. $sessionRelCourseRelUser->setPrimaryKey(['id']);
  212. $sessionRelCourseRelUser->addIndex(['c_id']);
  213. $sessionRelCourseRelUser->addIndex(['session_id']);
  214. $sessionRelCourseRelUser->addForeignKeyConstraint('course', ['c_id'], ['id']);
  215. $sessionRelCourseRelUser->addForeignKeyConstraint('session', ['session_id'], ['id']);
  216. $sessionRelCourseRelUser->addForeignKeyConstraint('user', ['user_id'], ['id']);
  217. $this->connection->executeQuery('DELETE FROM session_rel_user WHERE user_id NOT IN (SELECT id FROM user)');
  218. $this->connection->executeQuery('DELETE FROM session_rel_user WHERE session_id NOT IN (SELECT id FROM session)');
  219. $sessionRelUser = $schema->getTable('session_rel_user');
  220. $sessionRelUser->addColumn('moved_to', Type::INTEGER)->setNotnull(false);
  221. $sessionRelUser->addColumn('moved_status', Type::INTEGER)->setNotnull(false);
  222. $sessionRelUser->addColumn('moved_at', Type::DATETIME)->setNotnull(false);
  223. $sessionRelUser->addIndex(['session_id']);
  224. $sessionRelUser->addIndex(['user_id']);
  225. $sessionRelUser->addIndex(['user_id', 'moved_to']);
  226. $sessionRelUser->addForeignKeyConstraint('user', ['user_id'], ['id']);
  227. $sessionRelUser->addForeignKeyConstraint('session', ['session_id'], ['id']);
  228. $settingsCurrent = $schema->getTable('settings_current');
  229. $settingsCurrent->addUniqueIndex(['variable', 'subkey', 'access_url']);
  230. $settingsCurrent = $schema->getTable('settings_options');
  231. $settingsCurrent->dropIndex('id');
  232. $settingsCurrent->addUniqueIndex(['variable', 'value']);
  233. $schema->getTable('track_e_access')->addIndex(['c_id']);
  234. $schema->getTable('track_e_attempt')->addIndex(['c_id']);
  235. $schema->getTable('track_e_course_access')->addIndex(['c_id']);
  236. $trackEDefault = $schema->getTable('track_e_default');
  237. $trackEDefault->addIndex(['c_id']);
  238. $trackEDefault->addIndex(['session_id']);
  239. $schema->getTable('track_e_downloads')->addIndex(['c_id']);
  240. $schema->getTable('track_e_exercises')->addIndex(['c_id']);
  241. $schema->getTable('track_e_hotpotatoes')->addIndex(['c_id']);
  242. $schema->getTable('track_e_lastaccess')->addIndex(['c_id']);
  243. $schema->getTable('track_e_links')->addIndex(['c_id']);
  244. $schema->getTable('track_e_online')->addIndex(['c_id']);
  245. $schema->getTable('track_e_uploads')->addIndex(['c_id']);
  246. $schema->getTable('user')->addUniqueIndex(['username_canonical']);
  247. $this->connection->executeQuery('DELETE FROM usergroup_rel_user WHERE user_id NOT IN (SELECT id FROM user)');
  248. $this->connection->executeQuery('DELETE FROM usergroup_rel_user WHERE usergroup_id NOT IN (SELECT id FROM usergroup)');
  249. $usergroupRelUSer = $schema->getTable('usergroup_rel_user');
  250. $usergroupRelUSer->addIndex(['user_id']);
  251. $usergroupRelUSer->addIndex(['usergroup_id']);
  252. $usergroupRelUSer->addForeignKeyConstraint('usergroup', ['usergroup_id'], ['id']);
  253. $usergroupRelUSer->addForeignKeyConstraint('user', ['user_id'], ['id']);
  254. }
  255. /**
  256. * @param Schema $schema
  257. */
  258. public function down(Schema $schema)
  259. {
  260. }
  261. }