Version20160907140300.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. namespace Application\Migrations\Schema\V111;
  4. use Application\Migrations\AbstractMigrationChamilo;
  5. use Doctrine\DBAL\Schema\Schema;
  6. /**
  7. * Class Version20160907140300
  8. * Change tables engine to InnoDB
  9. * @package Application\Migrations\Schema\V111
  10. */
  11. class Version20160907140300 extends AbstractMigrationChamilo
  12. {
  13. /**
  14. * @param Schema $schema
  15. */
  16. public function up(Schema $schema)
  17. {
  18. error_log('Version20160907140300');
  19. $data = [
  20. 'career' => [
  21. 'created_at',
  22. 'updated_at',
  23. ],
  24. 'chat' => [
  25. 'sent',
  26. ],
  27. 'course' => [
  28. 'last_visit',
  29. 'last_edit',
  30. 'creation_date',
  31. 'expiration_date',
  32. ],
  33. 'course_request' => [
  34. 'request_date',
  35. ],
  36. 'gradebook_certificate' => [
  37. 'created_at',
  38. ],
  39. 'gradebook_evaluation' => [
  40. 'created_at',
  41. ],
  42. 'gradebook_link' => [
  43. 'created_at',
  44. ],
  45. 'gradebook_linkeval_log' => [
  46. 'created_at',
  47. ],
  48. 'gradebook_result' => [
  49. 'created_at',
  50. ],
  51. 'gradebook_result_log' => [
  52. 'created_at',
  53. ],
  54. 'message' => [
  55. 'send_date',
  56. ],
  57. 'notification' => [
  58. 'sent_at'
  59. ],
  60. 'promotion' => [
  61. 'created_at',
  62. 'updated_at',
  63. ],
  64. 'shared_survey' => [
  65. 'creation_date',
  66. ],
  67. 'sequence_value' => [
  68. 'success_date',
  69. 'available_start_date',
  70. 'available_end_date',
  71. ],
  72. 'session_rel_user' => [
  73. 'moved_at',
  74. 'registered_at',
  75. ],
  76. 'skill' => [
  77. 'updated_at',
  78. ],
  79. 'sys_announcement' => [
  80. 'date_start',
  81. 'date_end',
  82. ],
  83. 'track_e_attempt_recording' => [
  84. 'insert_date',
  85. ],
  86. 'track_e_course_access' => [
  87. 'login_course_date',
  88. 'logout_course_date',
  89. ],
  90. 'track_e_downloads' => [
  91. 'down_date',
  92. ],
  93. 'track_e_exercises' => [
  94. 'start_date',
  95. 'exe_date',
  96. ],
  97. 'track_e_hotpotatoes' => [
  98. 'exe_date',
  99. ],
  100. 'track_e_item_property' => [
  101. 'lastedit_date',
  102. ],
  103. 'track_e_links' => [
  104. 'links_date',
  105. ],
  106. 'track_e_login' => [
  107. 'logout_date',
  108. ],
  109. 'track_e_online' => [
  110. 'login_date',
  111. ],
  112. 'track_e_open' => [
  113. 'open_date',
  114. ],
  115. 'track_e_uploads' => [
  116. 'upload_date',
  117. ],
  118. 'user_api_key' => [
  119. 'created_date',
  120. 'validity_start_date',
  121. 'validity_end_date',
  122. ],
  123. 'user_rel_user' => [
  124. 'last_edit',
  125. ],
  126. 'c_attendance_calendar' => [
  127. 'date_time',
  128. ],
  129. 'c_attendance_sheet_log' => [
  130. 'calendar_date_value',
  131. ],
  132. 'c_blog' => [
  133. 'date_creation',
  134. ],
  135. 'c_blog_comment' => [
  136. 'date_creation',
  137. ],
  138. 'c_blog_post' => [
  139. 'date_creation',
  140. ],
  141. 'c_blog_task_rel_user' => [
  142. 'target_date',
  143. ],
  144. 'c_chat_connected' => [
  145. 'last_connection',
  146. ],
  147. 'c_dropbox_feedback' => [
  148. 'feedback_date',
  149. ],
  150. 'c_dropbox_file' => [
  151. 'upload_date',
  152. 'last_upload_date',
  153. ],
  154. 'c_dropbox_post' => [
  155. 'feedback_date',
  156. ],
  157. 'c_forum_post' => [
  158. 'post_date',
  159. ],
  160. 'c_forum_thread' => [
  161. 'thread_date',
  162. 'thread_close_date',
  163. ],
  164. 'c_forum_thread_qualify' => [
  165. 'qualify_time',
  166. ],
  167. 'c_forum_thread_qualify_log' => [
  168. 'qualify_time',
  169. ],
  170. 'c_lp' => [
  171. 'created_on',
  172. 'modified_on',
  173. ],
  174. 'c_notebook' => [
  175. 'creation_date',
  176. 'update_date',
  177. ],
  178. 'c_online_connected' => [
  179. 'last_connection',
  180. ],
  181. 'c_survey' => [
  182. 'creation_date',
  183. ],
  184. 'c_survey_invitation' => [
  185. 'invitation_date',
  186. 'reminder_date',
  187. ],
  188. 'c_userinfo_content' => [
  189. 'edition_time'
  190. ],
  191. 'c_wiki_discuss' => [
  192. 'dtime',
  193. ],
  194. ];
  195. // Needed to update 0000-00-00 00:00:00 values
  196. $this->addSql('SET sql_mode = ""');
  197. // In case this one didn't work, also try this
  198. $this->addSql('SET SESSION sql_mode = ""');
  199. // The whole point of this version is to ensure that all tricky (or most)
  200. // tricky datetime fields are null if = 0000-00-00 00:00:00, because
  201. // this value is not tolerated in NO_ZERO_DATE mode nor to convert
  202. // the table to InnoDB, and we want all tables to be converted to
  203. // InnoDB (that's the point of the following migration)
  204. // To try and avoid errors to the maximum, we first convert the fields
  205. // to a non-DATETIME type, then change the value of zero-valued times
  206. // to NULL, then change the field back to DATETIME
  207. foreach ($data as $table => $fields) {
  208. foreach ($fields as $field) {
  209. error_log("$table . $field");
  210. $this->addSql("ALTER TABLE $table CHANGE $field $field char(19)");
  211. $this->addSql("UPDATE $table SET $field = NULL WHERE $field = '0000-00-00 00:00:00'");
  212. $this->addSql("UPDATE $table SET $field = NULL WHERE $field = '0000-00-00 23:59:59'");
  213. $this->addSql("ALTER TABLE $table CHANGE $field $field DATETIME");
  214. }
  215. }
  216. // Same with DATE instead of DATETIME
  217. $data = [
  218. 'c_announcement' => [
  219. 'end_date',
  220. ],
  221. ];
  222. foreach ($data as $table => $fields) {
  223. foreach ($fields as $field) {
  224. error_log("$table . $field");
  225. $this->addSql("ALTER TABLE $table CHANGE $field $field char(10)");
  226. $this->addSql("UPDATE $table SET $field = NULL WHERE $field = '0000-00-00'");
  227. $this->addSql("ALTER TABLE $table CHANGE $field $field DATE");
  228. }
  229. }
  230. }
  231. public function down(Schema $schema)
  232. {
  233. }
  234. }