upgrade_2-1_mysql.sql 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /* ATTENTION: You don't need to run or use this file! The upgrade.php script does everything for you! */
  2. /******************************************************************************/
  3. --- Adding new settings...
  4. /******************************************************************************/
  5. ---# Adding login history...
  6. CREATE TABLE IF NOT EXISTS {$db_prefix}member_logins (
  7. id_login int(10) NOT NULL auto_increment,
  8. id_member mediumint(8) NOT NULL,
  9. time int(10) NOT NULL,
  10. ip varchar(255) NOT NULL default '',
  11. ip2 varchar(255) NOT NULL default '',
  12. PRIMARY KEY id_login(id_login),
  13. KEY id_member (id_member),
  14. KEY time (time)
  15. ) ENGINE=MyISAM{$db_collation};
  16. ---#
  17. ---# Copying the current package backup setting...
  18. ---{
  19. if (!isset($modSettings['package_make_full_backups']) && isset($modSettings['package_make_backups']))
  20. upgrade_query("
  21. INSERT INTO {$db_prefix}settings
  22. (variable, value)
  23. VALUES
  24. ('package_make_full_backups', '" . $modSettings['package_make_backups'] . "')");
  25. ---}
  26. ---#
  27. /******************************************************************************/
  28. --- Updating legacy attachments...
  29. /******************************************************************************/
  30. ---# Converting legacy attachments.
  31. ---{
  32. $request = upgrade_query("
  33. SELECT MAX(id_attach)
  34. FROM {$db_prefix}attachments");
  35. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  36. $smcFunc['db_free_result']($request);
  37. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  38. $step_progress['name'] = 'Converting legacy attachments';
  39. $step_progress['current'] = $_GET['a'];
  40. // We may be using multiple attachment directories.
  41. if (!empty($modSettings['currentAttachmentUploadDir']) && !is_array($modSettings['attachmentUploadDir']))
  42. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  43. $is_done = false;
  44. while (!$is_done)
  45. {
  46. nextSubStep($substep);
  47. $request = upgrade_query("
  48. SELECT id_attach, id_folder, filename, file_hash
  49. FROM {$db_prefix}attachments
  50. WHERE file_hash = ''
  51. LIMIT $_GET[a], 100");
  52. // Finished?
  53. if ($smcFunc['db_num_rows']($request) == 0)
  54. $is_done = true;
  55. while ($row = $smcFunc['db_fetch_assoc']($request))
  56. {
  57. // The current folder.
  58. $current_folder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$row['id_folder']] : $modSettings['attachmentUploadDir'];
  59. // The old location of the file.
  60. $old_location = getLegacyAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder']);
  61. // The new file name.
  62. $file_hash = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], true);
  63. // And we try to move it.
  64. rename($old_location, $current_folder . '/' . $row['id_attach'] . '_' . $file_hash);
  65. // Only update thif if it was successful.
  66. if (file_exists($current_folder . '/' . $row['id_attach'] . '_' . $file_hash) && !file_exists($old_location))
  67. upgrade_query("
  68. UPDATE {$db_prefix}attachments
  69. SET file_hash = '$file_hash'
  70. WHERE id_attach = $row[id_attach]");
  71. }
  72. $smcFunc['db_free_result']($request);
  73. $_GET['a'] += 100;
  74. $step_progress['current'] = $_GET['a'];
  75. }
  76. unset($_GET['a']);
  77. ---}
  78. ---#
  79. /******************************************************************************/
  80. --- Adding support for IPv6...
  81. /******************************************************************************/
  82. ---# Adding new columns to ban items...
  83. ALTER TABLE {$db_prefix}ban_items
  84. ADD COLUMN ip_low5 smallint(255) unsigned NOT NULL DEFAULT '0',
  85. ADD COLUMN ip_high5 smallint(255) unsigned NOT NULL DEFAULT '0',
  86. ADD COLUMN ip_low6 smallint(255) unsigned NOT NULL DEFAULT '0',
  87. ADD COLUMN ip_high6 smallint(255) unsigned NOT NULL DEFAULT '0',
  88. ADD COLUMN ip_low7 smallint(255) unsigned NOT NULL DEFAULT '0',
  89. ADD COLUMN ip_high7 smallint(255) unsigned NOT NULL DEFAULT '0',
  90. ADD COLUMN ip_low8 smallint(255) unsigned NOT NULL DEFAULT '0',
  91. ADD COLUMN ip_high8 smallint(255) unsigned NOT NULL DEFAULT '0';
  92. ---#
  93. ---# Changing existing columns to ban items...
  94. ALTER TABLE {$db_prefix}ban_items
  95. CHANGE ip_low1 ip_low1 smallint(255) unsigned NOT NULL DEFAULT '0',
  96. CHANGE ip_high1 ip_high1 smallint(255) unsigned NOT NULL DEFAULT '0',
  97. CHANGE ip_low2 ip_low2 smallint(255) unsigned NOT NULL DEFAULT '0',
  98. CHANGE ip_high2 ip_high2 smallint(255) unsigned NOT NULL DEFAULT '0',
  99. CHANGE ip_low3 ip_low3 smallint(255) unsigned NOT NULL DEFAULT '0',
  100. CHANGE ip_high3 ip_high3 smallint(255) unsigned NOT NULL DEFAULT '0',
  101. CHANGE ip_low4 ip_low4 smallint(255) unsigned NOT NULL DEFAULT '0',
  102. CHANGE ip_high4 ip_high4 smallint(255) unsigned NOT NULL DEFAULT '0';
  103. ---#
  104. /******************************************************************************/
  105. --- Adding support for <credits> tag in package manager
  106. /******************************************************************************/
  107. ---# Adding new columns to log_packages ..
  108. ALTER TABLE {$db_prefix}log_packages
  109. ADD COLUMN credits varchar(255) NOT NULL DEFAULT '';
  110. ---#
  111. /******************************************************************************/
  112. --- Adding more space for session ids
  113. /******************************************************************************/
  114. ---# Altering the session_id columns...
  115. ALTER TABLE {$db_prefix}log_online
  116. CHANGE `session` `session` varchar(64) NOT NULL DEFAULT '';
  117. ALTER TABLE {$db_prefix}log_errors
  118. CHANGE `session` `session` char(64) NOT NULL default ' ';
  119. ALTER TABLE {$db_prefix}sessions
  120. CHANGE `session_id` `session_id` char(64) NOT NULL;
  121. ---#
  122. /******************************************************************************/
  123. --- Adding support for MOVED topics enhancements
  124. /******************************************************************************/
  125. ---# Adding new columns to topics ..
  126. ALTER TABLE {$db_prefix}topics
  127. ADD COLUMN redirect_expires int(10) unsigned NOT NULL default '0',
  128. ADD COLUMN id_redirect_topic mediumint(8) unsigned NOT NULL default '0';
  129. ---#
  130. /******************************************************************************/
  131. --- Adding new scheduled tasks
  132. /******************************************************************************/
  133. ---# Adding new scheduled tasks
  134. INSERT INTO {$db_prefix}scheduled_tasks
  135. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  136. VALUES
  137. (0, 120, 1, 'd', 0, 'remove_temp_attachments');
  138. INSERT INTO {$db_prefix}scheduled_tasks
  139. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  140. VALUES
  141. (0, 180, 1, 'd', 0, 'remove_topic_redirect');
  142. INSERT INTO {$db_prefix}scheduled_tasks
  143. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  144. VALUES
  145. (0, 240, 1, 'd', 0, 'remove_old_drafts');
  146. ---#
  147. /******************************************************************************/
  148. ---- Replacing MSN with Skype
  149. /******************************************************************************/
  150. ---# Modifying the "msn" column...
  151. ALTER TABLE {$db_prefix}members
  152. CHANGE msn skype varchar(255) NOT NULL DEFAULT '';
  153. ---#
  154. /******************************************************************************/
  155. --- Adding support for deny boards access
  156. /******************************************************************************/
  157. ---# Adding new columns to boards...
  158. ALTER TABLE {$db_prefix}boards
  159. ADD COLUMN deny_member_groups varchar(255) NOT NULL DEFAULT '';
  160. ---#
  161. /******************************************************************************/
  162. --- Adding support for topic disregard
  163. /******************************************************************************/
  164. ---# Adding new columns to boards...
  165. ALTER TABLE {$db_prefix}log_topics
  166. ADD COLUMN disregarded tinyint(3) NOT NULL DEFAULT '0';
  167. INSERT INTO {$db_prefix}settings
  168. (variable, value)
  169. VALUES
  170. ('enable_disregard', 0);
  171. ---#
  172. /******************************************************************************/
  173. --- Fixing mail queue for long messages
  174. /******************************************************************************/
  175. ---# Altering mil_queue table...
  176. ALTER TABLE {$db_prefix}mail_queue
  177. CHANGE body body mediumtext NOT NULL;
  178. ---#
  179. /******************************************************************************/
  180. --- Name changes
  181. /******************************************************************************/
  182. ---# Altering the membergroup stars to icons
  183. ALTER TABLE {$db_prefix}membergroups
  184. CHANGE `stars` `icons` varchar(255) NOT NULL DEFAULT '';
  185. ---#
  186. /******************************************************************************/
  187. --- Adding support for drafts
  188. /******************************************************************************/
  189. ---# Creating draft table
  190. CREATE TABLE IF NOT EXISTS {$db_prefix}user_drafts (
  191. id_draft int(10) unsigned NOT NULL auto_increment,
  192. id_topic mediumint(8) unsigned NOT NULL default '0',
  193. id_board smallint(5) unsigned NOT NULL default '0',
  194. id_reply int(10) unsigned NOT NULL default '0',
  195. type tinyint(4) NOT NULL default '0',
  196. poster_time int(10) unsigned NOT NULL default '0',
  197. id_member mediumint(8) unsigned NOT NULL default '0',
  198. subject varchar(255) NOT NULL default '',
  199. smileys_enabled tinyint(4) NOT NULL default '1',
  200. body mediumtext NOT NULL,
  201. icon varchar(16) NOT NULL default 'xx',
  202. locked tinyint(4) NOT NULL default '0',
  203. is_sticky tinyint(4) NOT NULL default '0',
  204. to_list varchar(255) NOT NULL default '',
  205. outbox tinyint(4) NOT NULL default '0',
  206. PRIMARY KEY id_draft(id_draft),
  207. UNIQUE id_member (id_member, id_draft, type)
  208. ) ENGINE=MyISAM{$db_collation};
  209. ---#
  210. ---# Adding draft permissions...
  211. ---{
  212. // We cannot do this twice
  213. if (@$modSettings['smfVersion'] < '2.1')
  214. {
  215. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  216. $request = upgrade_query("
  217. SELECT id_group, id_board, add_deny, permission
  218. FROM {$db_prefix}board_permissions
  219. WHERE permission = 'post_unapproved_topics'");
  220. $inserts = array();
  221. while ($row = smf_mysql_fetch_assoc($request))
  222. {
  223. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  224. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  225. }
  226. smf_mysql_free_result($request);
  227. if (!empty($inserts))
  228. upgrade_query("
  229. INSERT IGNORE INTO {$db_prefix}board_permissions
  230. (id_group, id_board, permission, add_deny)
  231. VALUES
  232. " . implode(',', $inserts));
  233. // Next we find people who can send PM's, and assume they can save pm_drafts as well
  234. $request = upgrade_query("
  235. SELECT id_group, add_deny, permission
  236. FROM {$db_prefix}permissions
  237. WHERE permission = 'pm_send'");
  238. $inserts = array();
  239. while ($row = smf_mysql_fetch_assoc($request))
  240. {
  241. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  242. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  243. }
  244. smf_mysql_free_result($request);
  245. if (!empty($inserts))
  246. upgrade_query("
  247. INSERT IGNORE INTO {$db_prefix}permissions
  248. (id_group, permission, add_deny)
  249. VALUES
  250. " . implode(',', $inserts));
  251. }
  252. ---}
  253. ---#
  254. /******************************************************************************/
  255. --- Adding support for group-based board moderation
  256. /******************************************************************************/
  257. ---# Creating moderator_groups table
  258. CREATE TABLE IF NOT EXISTS {$db_prefix}moderator_groups (
  259. id_board smallint(5) unsigned NOT NULL default '0',
  260. id_group smallint(5) unsigned NOT NULL default '0',
  261. PRIMARY KEY (id_board, id_group)
  262. ) ENGINE=MyISAM;