upgrade_2-1_sqlite.sql 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 integer NOT NULL auto_increment,
  8. id_member integer NOT NULL,
  9. time integer 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. );
  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. ---# Adding back proper support for UTF8
  28. ---{
  29. global $sourcedir;
  30. require_once($sourcedir . '/Subs-Admin.php');
  31. updateSettingsFile(array('db_character_set' => 'utf8'));
  32. upgrade_query("
  33. INSERT INTO {$db_prefix}settings
  34. (variable, value)
  35. VALUES
  36. ('global_character_set', 'UTF-8')");
  37. ---}
  38. ---#
  39. /******************************************************************************/
  40. --- Updating legacy attachments...
  41. /******************************************************************************/
  42. ---# Converting legacy attachments.
  43. ---{
  44. $request = upgrade_query("
  45. SELECT MAX(id_attach)
  46. FROM {$db_prefix}attachments");
  47. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  48. $smcFunc['db_free_result']($request);
  49. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  50. $step_progress['name'] = 'Converting legacy attachments';
  51. $step_progress['current'] = $_GET['a'];
  52. // We may be using multiple attachment directories.
  53. if (!empty($modSettings['currentAttachmentUploadDir']) && !is_array($modSettings['attachmentUploadDir']))
  54. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  55. $is_done = false;
  56. while (!$is_done)
  57. {
  58. nextSubStep($substep);
  59. $request = upgrade_query("
  60. SELECT id_attach, id_folder, filename, file_hash
  61. FROM {$db_prefix}attachments
  62. WHERE file_hash = ''
  63. LIMIT $_GET[a], 100");
  64. // Finished?
  65. if ($smcFunc['db_num_rows']($request) == 0)
  66. $is_done = true;
  67. while ($row = $smcFunc['db_fetch_assoc']($request))
  68. {
  69. // The current folder.
  70. $current_folder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$row['id_folder']] : $modSettings['attachmentUploadDir'];
  71. // The old location of the file.
  72. $old_location = getLegacyAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder']);
  73. // The new file name.
  74. $file_hash = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], true);
  75. // And we try to move it.
  76. rename($old_location, $current_folder . '/' . $row['id_attach'] . '_' . $file_hash);
  77. // Only update thif if it was successful.
  78. if (file_exists($current_folder . '/' . $row['id_attach'] . '_' . $file_hash) && !file_exists($old_location))
  79. upgrade_query("
  80. UPDATE {$db_prefix}attachments
  81. SET file_hash = '$file_hash'
  82. WHERE id_attach = $row[id_attach]");
  83. }
  84. $smcFunc['db_free_result']($request);
  85. $_GET['a'] += 100;
  86. $step_progress['current'] = $_GET['a'];
  87. }
  88. unset($_GET['a']);
  89. ---}
  90. ---#
  91. /******************************************************************************/
  92. --- Adding support for IPv6...
  93. /******************************************************************************/
  94. ---# Adding new columns to ban items...
  95. ALTER TABLE {$db_prefix}ban_items
  96. ADD COLUMN ip_low5 smallint(255) unsigned NOT NULL DEFAULT '0',
  97. ADD COLUMN ip_high5 smallint(255) unsigned NOT NULL DEFAULT '0',
  98. ADD COLUMN ip_low6 smallint(255) unsigned NOT NULL DEFAULT '0',
  99. ADD COLUMN ip_high6 smallint(255) unsigned NOT NULL DEFAULT '0',
  100. ADD COLUMN ip_low7 smallint(255) unsigned NOT NULL DEFAULT '0',
  101. ADD COLUMN ip_high7 smallint(255) unsigned NOT NULL DEFAULT '0',
  102. ADD COLUMN ip_low8 smallint(255) unsigned NOT NULL DEFAULT '0',
  103. ADD COLUMN ip_high8 smallint(255) unsigned NOT NULL DEFAULT '0';
  104. ---#
  105. ---# Changing existing columns to ban items...
  106. ALTER TABLE {$db_prefix}ban_items
  107. CHANGE ip_low1 ip_low1 smallint(255) unsigned NOT NULL DEFAULT '0',
  108. CHANGE ip_high1 ip_high1 smallint(255) unsigned NOT NULL DEFAULT '0',
  109. CHANGE ip_low2 ip_low2 smallint(255) unsigned NOT NULL DEFAULT '0',
  110. CHANGE ip_high2 ip_high2 smallint(255) unsigned NOT NULL DEFAULT '0',
  111. CHANGE ip_low3 ip_low3 smallint(255) unsigned NOT NULL DEFAULT '0',
  112. CHANGE ip_high3 ip_high3 smallint(255) unsigned NOT NULL DEFAULT '0',
  113. CHANGE ip_low4 ip_low4 smallint(255) unsigned NOT NULL DEFAULT '0',
  114. CHANGE ip_high4 ip_high4 smallint(255) unsigned NOT NULL DEFAULT '0';
  115. ---#
  116. /******************************************************************************/
  117. --- Adding support for <credits> tag in package manager
  118. /******************************************************************************/
  119. ---# Adding new columns to log_packages ..
  120. ALTER TABLE {$db_prefix}log_packages
  121. ADD COLUMN credits varchar(255) NOT NULL DEFAULT '';
  122. ---#
  123. /******************************************************************************/
  124. --- Adding more space for session ids
  125. /******************************************************************************/
  126. ---# Altering the session_id columns...
  127. ALTER TABLE {$db_prefix}log_online
  128. CHANGE `session` `session` varchar(64) NOT NULL DEFAULT '';
  129. ALTER TABLE {$db_prefix}log_errors
  130. CHANGE `session` `session` char(64) NOT NULL default ' ';
  131. ALTER TABLE {$db_prefix}sessions
  132. CHANGE `session_id` `session_id` char(64) NOT NULL;
  133. ---#
  134. /******************************************************************************/
  135. --- Adding new columns for MOVED topic updates
  136. /******************************************************************************/
  137. ---# Adding new custom fields columns.
  138. ---{
  139. $smcFunc['db_alter_table']('{db_prefix}topics', array(
  140. 'add' => array(
  141. 'redirect_expires' => array(
  142. 'name' => 'redirect_expires',
  143. 'null' => false,
  144. 'default' => '0',
  145. 'type' => 'int',
  146. 'auto' => false,
  147. ),
  148. )
  149. ));
  150. $smcFunc['db_alter_table']('{db_prefix}topics', array(
  151. 'add' => array(
  152. 'id_redirect_topic' => array(
  153. 'name' => 'id_redirect_topic',
  154. 'null' => false,
  155. 'default' => '0',
  156. 'type' => 'int',
  157. 'auto' => false,
  158. ),
  159. )
  160. ));
  161. ---}
  162. ---#
  163. /******************************************************************************/
  164. --- Adding new scheduled tasks
  165. /******************************************************************************/
  166. ---# Adding new scheduled tasks
  167. INSERT INTO {$db_prefix}scheduled_tasks
  168. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  169. VALUES
  170. (0, 120, 1, 'd', 0, 'remove_temp_attachments');
  171. INSERT INTO {$db_prefix}scheduled_tasks
  172. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  173. VALUES
  174. (0, 180, 1, 'd', 0, 'remove_topic_redirect');
  175. INSERT INTO {$db_prefix}scheduled_tasks
  176. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  177. VALUES
  178. (0, 240, 1, 'd', 0, 'remove_old_drafts');
  179. ---#
  180. /******************************************************************************/
  181. --- Adding support for deny boards access
  182. /******************************************************************************/
  183. ---# Adding new columns to boards...
  184. ---{
  185. $smcFunc['db_alter_table']('{db_prefix}boards', array(
  186. 'add' => array(
  187. 'deny_member_groups' => array(
  188. 'name' => 'deny_member_groups',
  189. 'null' => false,
  190. 'default' => '',
  191. 'type' => varchar,
  192. 'size' => 255,
  193. 'auto' => false,
  194. ),
  195. )
  196. ));
  197. ---}
  198. ---#
  199. /******************************************************************************/
  200. --- Name changes
  201. /******************************************************************************/
  202. ---# Altering the membergroup stars to icons
  203. ---{
  204. upgrade_query("
  205. ALTER TABLE {$db_prefix}membergroups
  206. CHANGE `stars` `icons` varchar(255) NOT NULL DEFAULT ''");
  207. ---}
  208. ---#
  209. /******************************************************************************/
  210. --- Adding support for drafts
  211. /******************************************************************************/
  212. ---# Creating drafts table.
  213. CREATE TABLE {$db_prefix}user_drafts (
  214. id_draft int unsigned NOT NULL auto_increment,
  215. id_topic int unsigned NOT NULL default '0',
  216. id_board smallint unsigned NOT NULL default '0',
  217. id_reply int unsigned NOT NULL default '0',
  218. type smallint NOT NULL default '0',
  219. poster_time int unsigned NOT NULL default '0',
  220. id_member int unsigned NOT NULL default '0',
  221. subject varchar(255) NOT NULL default '',
  222. smileys_enabled smallint NOT NULL default '1',
  223. body text NOT NULL,
  224. icon varchar(16) NOT NULL default 'xx',
  225. locked smallint NOT NULL default '0',
  226. is_sticky smallint NOT NULL default '0',
  227. to_list varchar(255) NOT NULL default '',
  228. outbox smallint NOT NULL default '0',
  229. PRIMARY KEY (id_draft)
  230. );
  231. ---#
  232. ---# Adding draft permissions...
  233. ---{
  234. // We cannot do this twice
  235. if (@$modSettings['smfVersion'] < '2.1')
  236. {
  237. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  238. $request = upgrade_query("
  239. SELECT id_group, id_board, add_deny, permission
  240. FROM {$db_prefix}board_permissions
  241. WHERE permission = 'post_unapproved_topics'");
  242. $inserts = array();
  243. while ($row = mysql_fetch_assoc($request))
  244. {
  245. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  246. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  247. }
  248. mysql_free_result($request);
  249. if (!empty($inserts))
  250. upgrade_query("
  251. INSERT IGNORE INTO {$db_prefix}board_permissions
  252. (id_group, id_board, permission, add_deny)
  253. VALUES
  254. " . implode(',', $inserts));
  255. // Next we find people who can send PM's, and assume they can save pm_drafts as well
  256. $request = upgrade_query("
  257. SELECT id_group, add_deny, permission
  258. FROM {$db_prefix}permissions
  259. WHERE permission = 'pm_send'");
  260. $inserts = array();
  261. while ($row = mysql_fetch_assoc($request))
  262. {
  263. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  264. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  265. }
  266. mysql_free_result($request);
  267. if (!empty($inserts))
  268. upgrade_query("
  269. INSERT IGNORE INTO {$db_prefix}permissions
  270. (id_group, permission, add_deny)
  271. VALUES
  272. " . implode(',', $inserts));
  273. }
  274. ---}
  275. ---#