upgrade_2-1_mysql.sql 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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. ---# Copying the current "allow users to disable word censor" setting...
  28. ---{
  29. if (!isset($modSettings['allow_no_censored']))
  30. {
  31. $request = upgrade_query("
  32. SELECT value
  33. FROM {$db_prefix}themes
  34. WHERE variable='allow_no_censored'
  35. AND id_theme = 1 OR id_theme = '$modSettings[theme_default]'
  36. ");
  37. // Is it set for either "default" or the one they've set as default?
  38. while ($row = $smcFunc['db_fetch_assoc']($request))
  39. {
  40. if ($row['value'] == 1)
  41. {
  42. upgrade_query("
  43. INSERT INTO {$db_prefix}settings
  44. VALUES ('allow_no_censored', 1)
  45. ");
  46. // Don't do this twice...
  47. break;
  48. }
  49. }
  50. }
  51. ---}
  52. ---#
  53. ---# Adding new "topic_move_any" setting
  54. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('topic_move_any', '1');
  55. ---#
  56. /******************************************************************************/
  57. --- Updating legacy attachments...
  58. /******************************************************************************/
  59. ---# Converting legacy attachments.
  60. ---{
  61. // Need to know a few things first.
  62. $custom_av_dir = !empty($modSettings['custom_avatar_dir']) ? $modSettings['custom_avatar_dir'] : $GLOBALS['boarddir'] .'/custom_avatar';
  63. // This little fellow has to cooperate...
  64. if (!is_writable($custom_av_dir))
  65. @chmod($custom_av_dir, 0777);
  66. $request = upgrade_query("
  67. SELECT MAX(id_attach)
  68. FROM {$db_prefix}attachments");
  69. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  70. $smcFunc['db_free_result']($request);
  71. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  72. $step_progress['name'] = 'Converting legacy attachments';
  73. $step_progress['current'] = $_GET['a'];
  74. // We may be using multiple attachment directories.
  75. if (!empty($modSettings['currentAttachmentUploadDir']) && !is_array($modSettings['attachmentUploadDir']))
  76. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  77. $is_done = false;
  78. while (!$is_done)
  79. {
  80. nextSubStep($substep);
  81. $fileHash = '';
  82. $request = upgrade_query("
  83. SELECT id_attach, id_folder, filename, file_hash
  84. FROM {$db_prefix}attachments
  85. WHERE attachment_type != 1
  86. LIMIT $_GET[a], 100");
  87. // Finished?
  88. if ($smcFunc['db_num_rows']($request) == 0)
  89. $is_done = true;
  90. while ($row = $smcFunc['db_fetch_assoc']($request))
  91. {
  92. // The current folder.
  93. $currentFolder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$row['id_folder']] : $modSettings['attachmentUploadDir'];
  94. // Old School?
  95. if (empty($row['file_hash']))
  96. {
  97. // Remove international characters (windows-1252)
  98. // These lines should never be needed again. Still, behave.
  99. if (empty($db_character_set) || $db_character_set != 'utf8')
  100. {
  101. $row['filename'] = strtr($row['filename'],
  102. "\x8a\x8e\x9a\x9e\x9f\xc0\xc1\xc2\xc3\xc4\xc5\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xe0\xe1\xe2\xe3\xe4\xe5\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xff",
  103. 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
  104. $row['filename'] = strtr($row['filename'], array("\xde" => 'TH', "\xfe" =>
  105. 'th', "\xd0" => 'DH', "\xf0" => 'dh', "\xdf" => 'ss', "\x8c" => 'OE',
  106. "\x9c" => 'oe', "\xc6" => 'AE', "\xe6" => 'ae', "\xb5" => 'u'));
  107. }
  108. // Sorry, no spaces, dots, or anything else but letters allowed.
  109. $row['filename'] = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $row['filename']);
  110. // Create a nice hash.
  111. $fileHash = sha1(md5($row['filename'] . time()) . mt_rand());
  112. // The old file, we need to know if the filename was encrypted or not.
  113. if (file_exists($currentFolder . '/' . $row['id_attach']. '_' . strtr($row['filename'], '.', '_') . md5($row['filename'])))
  114. $oldFile = $currentFolder . '/' . $row['id_attach']. '_' . strtr($row['filename'], '.', '_') . md5($row['filename']);
  115. else if (file_exists($currentFolder . '/' . $row['filename']));
  116. $oldFile = $currentFolder . '/' . $row['filename'];
  117. // Build the new file.
  118. $newFile = $currentFolder . '/' . $row['id_attach'] . '_' . $fileHash .'.dat';
  119. }
  120. // Just rename the file.
  121. else
  122. {
  123. $oldFile = $currentFolder . '/' . $row['id_attach'] . '_' . $row['file_hash'];
  124. $newFile = $currentFolder . '/' . $row['id_attach'] . '_' . $row['file_hash'] .'.dat';
  125. }
  126. // Check if the av is an attachment
  127. if ($row['id_member'] != 0)
  128. if (rename($oldFile, $custom_av_dir . '/' . $row['filename']))
  129. upgrade_query("
  130. UPDATE {$db_prefix}attachments
  131. SET file_hash = '', attachment_type = 1
  132. WHERE id_attach = $row[id_attach]");
  133. // Just a regular attachment.
  134. else
  135. rename($oldFile, $newFile);
  136. // Only update this if it was successful and the file was using the old system.
  137. if (empty($row['file_hash']) && !empty($fileHash) && file_exists($newFile) && !file_exists($oldFile))
  138. upgrade_query("
  139. UPDATE {$db_prefix}attachments
  140. SET file_hash = '$fileHash'
  141. WHERE id_attach = $row[id_attach]");
  142. }
  143. $smcFunc['db_free_result']($request);
  144. $_GET['a'] += 100;
  145. $step_progress['current'] = $_GET['a'];
  146. }
  147. unset($_GET['a']);
  148. ---}
  149. ---#
  150. /******************************************************************************/
  151. --- Adding support for IPv6...
  152. /******************************************************************************/
  153. ---# Adding new columns to ban items...
  154. ALTER TABLE {$db_prefix}ban_items
  155. ADD COLUMN ip_low5 smallint(255) unsigned NOT NULL DEFAULT '0',
  156. ADD COLUMN ip_high5 smallint(255) unsigned NOT NULL DEFAULT '0',
  157. ADD COLUMN ip_low6 smallint(255) unsigned NOT NULL DEFAULT '0',
  158. ADD COLUMN ip_high6 smallint(255) unsigned NOT NULL DEFAULT '0',
  159. ADD COLUMN ip_low7 smallint(255) unsigned NOT NULL DEFAULT '0',
  160. ADD COLUMN ip_high7 smallint(255) unsigned NOT NULL DEFAULT '0',
  161. ADD COLUMN ip_low8 smallint(255) unsigned NOT NULL DEFAULT '0',
  162. ADD COLUMN ip_high8 smallint(255) unsigned NOT NULL DEFAULT '0';
  163. ---#
  164. ---# Changing existing columns to ban items...
  165. ALTER TABLE {$db_prefix}ban_items
  166. CHANGE ip_low1 ip_low1 smallint(255) unsigned NOT NULL DEFAULT '0',
  167. CHANGE ip_high1 ip_high1 smallint(255) unsigned NOT NULL DEFAULT '0',
  168. CHANGE ip_low2 ip_low2 smallint(255) unsigned NOT NULL DEFAULT '0',
  169. CHANGE ip_high2 ip_high2 smallint(255) unsigned NOT NULL DEFAULT '0',
  170. CHANGE ip_low3 ip_low3 smallint(255) unsigned NOT NULL DEFAULT '0',
  171. CHANGE ip_high3 ip_high3 smallint(255) unsigned NOT NULL DEFAULT '0',
  172. CHANGE ip_low4 ip_low4 smallint(255) unsigned NOT NULL DEFAULT '0',
  173. CHANGE ip_high4 ip_high4 smallint(255) unsigned NOT NULL DEFAULT '0';
  174. ---#
  175. /******************************************************************************/
  176. --- Adding support for <credits> tag in package manager
  177. /******************************************************************************/
  178. ---# Adding new columns to log_packages ..
  179. ALTER TABLE {$db_prefix}log_packages
  180. ADD COLUMN credits varchar(255) NOT NULL DEFAULT '';
  181. ---#
  182. /******************************************************************************/
  183. --- Adding more space for session ids
  184. /******************************************************************************/
  185. ---# Altering the session_id columns...
  186. ALTER TABLE {$db_prefix}log_online
  187. CHANGE `session` `session` varchar(64) NOT NULL DEFAULT '';
  188. ALTER TABLE {$db_prefix}log_errors
  189. CHANGE `session` `session` char(64) NOT NULL default ' ';
  190. ALTER TABLE {$db_prefix}sessions
  191. CHANGE `session_id` `session_id` char(64) NOT NULL;
  192. ---#
  193. /******************************************************************************/
  194. --- Adding support for MOVED topics enhancements
  195. /******************************************************************************/
  196. ---# Adding new columns to topics ..
  197. ALTER TABLE {$db_prefix}topics
  198. ADD COLUMN redirect_expires int(10) unsigned NOT NULL default '0',
  199. ADD COLUMN id_redirect_topic mediumint(8) unsigned NOT NULL default '0';
  200. ---#
  201. /******************************************************************************/
  202. --- Adding new scheduled tasks
  203. /******************************************************************************/
  204. ---# Adding new scheduled tasks
  205. INSERT INTO {$db_prefix}scheduled_tasks
  206. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  207. VALUES
  208. (0, 120, 1, 'd', 0, 'remove_temp_attachments');
  209. INSERT INTO {$db_prefix}scheduled_tasks
  210. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  211. VALUES
  212. (0, 180, 1, 'd', 0, 'remove_topic_redirect');
  213. INSERT INTO {$db_prefix}scheduled_tasks
  214. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  215. VALUES
  216. (0, 240, 1, 'd', 0, 'remove_old_drafts');
  217. ---#
  218. /******************************************************************************/
  219. ---- Adding background tasks support
  220. /******************************************************************************/
  221. ---# Adding the new table
  222. CREATE TABLE IF NOT EXISTS {$db_prefix}background_tasks (
  223. id_task int(10) unsigned NOT NULL auto_increment,
  224. task_file varchar(255) NOT NULL default '',
  225. task_class varchar(255) NOT NULL default '',
  226. task_data mediumtext NOT NULL,
  227. claimed_time int(10) unsigned NOT NULL default '0',
  228. PRIMARY KEY (id_task)
  229. ) ENGINE=MyISAM;
  230. ---#
  231. /******************************************************************************/
  232. ---- Replacing MSN with Skype
  233. /******************************************************************************/
  234. ---# Modifying the "msn" column...
  235. ALTER TABLE {$db_prefix}members
  236. CHANGE msn skype varchar(255) NOT NULL DEFAULT '';
  237. ---#
  238. /******************************************************************************/
  239. --- Adding support for deny boards access
  240. /******************************************************************************/
  241. ---# Adding new columns to boards...
  242. ALTER TABLE {$db_prefix}boards
  243. ADD COLUMN deny_member_groups varchar(255) NOT NULL DEFAULT '';
  244. ---#
  245. /******************************************************************************/
  246. --- Adding support for category descriptions
  247. /******************************************************************************/
  248. ---# Adding new columns to categories...
  249. ALTER TABLE {$db_prefix}categories
  250. ADD COLUMN description text NOT NULL;
  251. ---#
  252. /******************************************************************************/
  253. --- Adding support for alerts
  254. /******************************************************************************/
  255. ---# Adding the count to the members table...
  256. ALTER TABLE {$db_prefix}members
  257. ADD COLUMN alerts int(10) unsigned NOT NULL default '0';
  258. ---#
  259. ---# Adding the new table for alerts.
  260. CREATE TABLE IF NOT EXISTS {$db_prefix}user_alerts (
  261. id_alert int(10) unsigned NOT NULL auto_increment,
  262. alert_time int(10) unsigned NOT NULL default '0',
  263. id_member mediumint(10) unsigned NOT NULL default '0',
  264. id_member_started mediumint(10) unsigned NOT NULL default '0',
  265. member_name varchar(255) NOT NULL default '',
  266. content_type varchar(255) NOT NULL default '',
  267. content_id int(10) unsigned NOT NULL default '0',
  268. content_action varchar(255) NOT NULL default '',
  269. is_read tinyint(3) unsigned NOT NULL default '0',
  270. extra text NOT NULL,
  271. PRIMARY KEY (id_alert),
  272. KEY id_member (id_member),
  273. KEY alert_time (alert_time)
  274. ) ENGINE=MyISAM;
  275. ---#
  276. ---# Adding alert preferences.
  277. CREATE TABLE IF NOT EXISTS {$db_prefix}user_alerts_prefs (
  278. id_member mediumint(8) unsigned NOT NULL default '0',
  279. alert_pref varchar(32) NOT NULL default '',
  280. alert_value tinyint(3) NOT NULL default '0',
  281. PRIMARY KEY (id_member, alert_pref)
  282. ) ENGINE=MyISAM;
  283. INSERT INTO {$db_prefix}user_alerts_prefs
  284. (id_member, alert_pref, alert_value)
  285. VALUES (0, 'member_group_request', 1),
  286. (0, 'member_register', 1),
  287. (0, 'msg_like', 1),
  288. (0, 'msg_report', 1),
  289. (0, 'msg_report_reply', 1);
  290. ---#
  291. /******************************************************************************/
  292. --- Adding support for topic unwatch
  293. /******************************************************************************/
  294. ---# Adding new columns to boards...
  295. ALTER TABLE {$db_prefix}log_topics
  296. ADD COLUMN unwatched tinyint(3) NOT NULL DEFAULT '0';
  297. UPDATE {$db_prefix}log_topics
  298. SET unwatched = 0;
  299. INSERT INTO {$db_prefix}settings
  300. (variable, value)
  301. VALUES
  302. ('enable_unwatch', 0);
  303. ---#
  304. ---# Fixing column name change...
  305. ALTER TABLE {$db_prefix}log_topics
  306. CHANGE COLUMN disregarded unwatched tinyint(3) NOT NULL DEFAULT '0';
  307. ---#
  308. /******************************************************************************/
  309. --- Fixing mail queue for long messages
  310. /******************************************************************************/
  311. ---# Altering mil_queue table...
  312. ALTER TABLE {$db_prefix}mail_queue
  313. CHANGE body body mediumtext NOT NULL;
  314. ---#
  315. /******************************************************************************/
  316. --- Name changes
  317. /******************************************************************************/
  318. ---# Altering the membergroup stars to icons
  319. ALTER TABLE {$db_prefix}membergroups
  320. CHANGE `stars` `icons` varchar(255) NOT NULL DEFAULT '';
  321. ---#
  322. ---# Renaming default theme...
  323. UPDATE {$db_prefix}themes
  324. SET value = 'SMF Default Theme - Curve2'
  325. WHERE value LIKE 'SMF Default Theme%';
  326. ---#
  327. ---# Adding the enableThemes setting.
  328. INSERT INTO {$db_prefix}settings
  329. (variable, value)
  330. VALUES
  331. ('enableThemes', '1');
  332. ---#
  333. ---# Setting "default" as the default...
  334. UPDATE {$db_prefix}settings
  335. SET value = '1'
  336. WHERE variable = 'theme_guests';
  337. UPDATE {$db_prefix}boards
  338. SET id_theme = 0;
  339. UPDATE {$db_prefix}members
  340. SET id_theme = 0;
  341. ---#
  342. /******************************************************************************/
  343. --- Cleaning up after old themes...
  344. /******************************************************************************/
  345. ---# Checking for "core" and removing it if necessary...
  346. ---{
  347. // Do they have "core" installed?
  348. if (file_exists($GLOBALS['boarddir'] . '/Themes/core'))
  349. {
  350. $core_dir = $GLOBALS['boarddir'] . '/Themes/core';
  351. $theme_request = upgrade_query("
  352. SELECT id_theme
  353. FROM {$db_prefix}themes
  354. WHERE variable = 'theme_dir'
  355. AND value ='$core_dir'");
  356. // Don't do anything if this theme is already uninstalled
  357. if ($smcFunc['db_num_rows']($theme_request) == 1)
  358. {
  359. // Only one row, so no loop needed
  360. $row = $smcFunc['db_fetch_array']($theme_request);
  361. $id_theme = $row[0];
  362. $smcFunc['db_free_result']($theme_request);
  363. $known_themes = explode(', ', $modSettings['knownThemes']);
  364. // Remove this value...
  365. $known_themes = array_diff($known_themes, array($id_theme));
  366. // Change back to a string...
  367. $known_themes = implode(', ', $known_themes);
  368. // Update the database
  369. upgrade_query("
  370. REPLACE INTO {$db_prefix}settings (variable, value)
  371. VALUES ('knownThemes', '$known_themes')");
  372. // Delete any info about this theme
  373. upgrade_query("
  374. DELETE FROM {$db_prefix}themes
  375. WHERE id_theme = $id_theme");
  376. }
  377. }
  378. ---}
  379. ---#
  380. /******************************************************************************/
  381. --- Adding support for drafts
  382. /******************************************************************************/
  383. ---# Creating draft table
  384. CREATE TABLE IF NOT EXISTS {$db_prefix}user_drafts (
  385. id_draft int(10) unsigned NOT NULL auto_increment,
  386. id_topic mediumint(8) unsigned NOT NULL default '0',
  387. id_board smallint(5) unsigned NOT NULL default '0',
  388. id_reply int(10) unsigned NOT NULL default '0',
  389. type tinyint(4) NOT NULL default '0',
  390. poster_time int(10) unsigned NOT NULL default '0',
  391. id_member mediumint(8) unsigned NOT NULL default '0',
  392. subject varchar(255) NOT NULL default '',
  393. smileys_enabled tinyint(4) NOT NULL default '1',
  394. body mediumtext NOT NULL,
  395. icon varchar(16) NOT NULL default 'xx',
  396. locked tinyint(4) NOT NULL default '0',
  397. is_sticky tinyint(4) NOT NULL default '0',
  398. to_list varchar(255) NOT NULL default '',
  399. PRIMARY KEY id_draft(id_draft),
  400. UNIQUE id_member (id_member, id_draft, type)
  401. ) ENGINE=MyISAM{$db_collation};
  402. ---#
  403. ---# Adding draft permissions...
  404. ---{
  405. // We cannot do this twice
  406. if (@$modSettings['smfVersion'] < '2.1')
  407. {
  408. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  409. $request = upgrade_query("
  410. SELECT id_group, id_board, add_deny, permission
  411. FROM {$db_prefix}board_permissions
  412. WHERE permission = 'post_unapproved_topics'");
  413. $inserts = array();
  414. while ($row = $smcFunc['db_fetch_assoc']($request))
  415. {
  416. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  417. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  418. }
  419. $smcFunc['db_free_result']($request);
  420. if (!empty($inserts))
  421. upgrade_query("
  422. INSERT IGNORE INTO {$db_prefix}board_permissions
  423. (id_group, id_board, permission, add_deny)
  424. VALUES
  425. " . implode(',', $inserts));
  426. // Next we find people who can send PMs, and assume they can save pm_drafts as well
  427. $request = upgrade_query("
  428. SELECT id_group, add_deny, permission
  429. FROM {$db_prefix}permissions
  430. WHERE permission = 'pm_send'");
  431. $inserts = array();
  432. while ($row = $smcFunc['db_fetch_assoc']($request))
  433. {
  434. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  435. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  436. }
  437. $smcFunc['db_free_result']($request);
  438. if (!empty($inserts))
  439. upgrade_query("
  440. INSERT IGNORE INTO {$db_prefix}permissions
  441. (id_group, permission, add_deny)
  442. VALUES
  443. " . implode(',', $inserts));
  444. }
  445. ---}
  446. INSERT INTO {$db_prefix}settings
  447. (variable, value)
  448. VALUES
  449. ('drafts_autosave_enabled', '1'),
  450. ('drafts_show_saved_enabled', '1'),
  451. ('drafts_keep_days', '7');
  452. INSERT INTO {$db_prefix}themes
  453. (id_theme, variable, value)
  454. VALUES
  455. ('1', 'drafts_autosave_enabled', '1'),
  456. ('1', 'drafts_show_saved_enabled', '1');
  457. ---#
  458. /******************************************************************************/
  459. --- Adding support for likes
  460. /******************************************************************************/
  461. ---# Creating likes table.
  462. CREATE TABLE IF NOT EXISTS {$db_prefix}user_likes (
  463. id_member mediumint(8) unsigned NOT NULL default '0',
  464. content_type char(6) default '',
  465. content_id int(10) unsigned NOT NULL default '0',
  466. like_time int(10) unsigned NOT NULL default '0',
  467. PRIMARY KEY (content_id, content_type, id_member),
  468. INDEX content (content_id, content_type),
  469. INDEX liker (id_member)
  470. ) ENGINE=MyISAM;
  471. ---#
  472. ---# Adding count to the messages table.
  473. ALTER TABLE {$db_prefix}messages
  474. ADD COLUMN likes smallint(5) unsigned NOT NULL DEFAULT '0';
  475. ---#
  476. /******************************************************************************/
  477. --- Adding support for group-based board moderation
  478. /******************************************************************************/
  479. ---# Creating moderator_groups table
  480. CREATE TABLE IF NOT EXISTS {$db_prefix}moderator_groups (
  481. id_board smallint(5) unsigned NOT NULL default '0',
  482. id_group smallint(5) unsigned NOT NULL default '0',
  483. PRIMARY KEY (id_board, id_group)
  484. ) ENGINE=MyISAM{$db_collation};
  485. ---#
  486. /******************************************************************************/
  487. --- Cleaning up integration hooks
  488. /******************************************************************************/
  489. ---# Deleting integration hooks
  490. DELETE FROM {$db_prefix}settings
  491. WHERE variable LIKE 'integrate_%';
  492. ---#
  493. /******************************************************************************/
  494. --- Cleaning up old settings
  495. /******************************************************************************/
  496. ---# Showing contact details to guests should never happen.
  497. DELETE FROM {$db_prefix}settings
  498. WHERE variable IN ('enableStickyTopics', 'guest_hideContacts', 'notify_new_registration', 'attachmentEncryptFilenames');
  499. ---#
  500. ---# Cleaning up old theme settings.
  501. DELETE FROM {$db_prefix}themes
  502. WHERE variable IN ('show_board_desc', 'no_new_reply_warning');
  503. ---#
  504. /******************************************************************************/
  505. --- Removing old Simple Machines files we do not need to fetch any more
  506. /******************************************************************************/
  507. ---# We no longer call on the latest packages list.
  508. DELETE FROM {$db_prefix}admin_info_files
  509. WHERE filename IN ('latest-packages.js', 'latest-support.js', 'latest-themes.js')
  510. AND path = '/smf/';
  511. ---#
  512. /******************************************************************************/
  513. --- Upgrading "verification questions" feature
  514. /******************************************************************************/
  515. ---# Creating qanda table
  516. CREATE TABLE IF NOT EXISTS {$db_prefix}qanda (
  517. id_question smallint(5) unsigned NOT NULL auto_increment,
  518. lngfile varchar(255) NOT NULL default '',
  519. question varchar(255) NOT NULL default '',
  520. answers text NOT NULL,
  521. PRIMARY KEY (id_question),
  522. KEY lngfile (lngfile)
  523. ) ENGINE=MyISAM{$db_collation};
  524. ---#
  525. ---# Moving questions and answers to the new table
  526. ---{
  527. $questions = array();
  528. $get_questions = upgrade_query("
  529. SELECT body AS question, recipient_name AS answer
  530. FROM {$db_prefix}log_comments
  531. WHERE comment_type = 'ver_test'");
  532. while ($row = $smcFunc['db_fetch_assoc']($get_questions))
  533. $questions[] = array($language, $row['question'], serialize(array($row['answer'])));
  534. $smcFunc['db_free_result']($get_questions);
  535. if (!empty($questions))
  536. {
  537. $smcFunc['db_insert']('',
  538. '{db_prefix}qanda',
  539. array('lngfile' => 'string', 'question' => 'string', 'answers' => 'string'),
  540. $questions,
  541. array('id_question')
  542. );
  543. // Delete the questions from log_comments now
  544. upgrade_query("
  545. DELETE FROM {$db_prefix}log_comments
  546. WHERE comment_type = 'ver_test'
  547. ");
  548. }
  549. ---}
  550. ---#
  551. /******************************************************************************/
  552. --- Marking packages as uninstalled...
  553. /******************************************************************************/
  554. ---# Updating log_packages
  555. UPDATE {$db_prefix}log_packages
  556. SET install_state = 0;
  557. ---#
  558. /******************************************************************************/
  559. --- Updating profile permissions...
  560. /******************************************************************************/
  561. ---# Removing the old "view your own profile" permission
  562. DELETE FROM {$db_prefix}permissions
  563. WHERE permission = 'profile_view_own';
  564. ---#
  565. ---# Updating the old "view any profile" permission
  566. UPDATE {$db_prefix}permissions
  567. SET permission = 'profile_view'
  568. WHERE permission = 'profile_view_any';
  569. ---#
  570. ---# Removing the old notification permissions
  571. DELETE FROM {$db_prefix}board_permissions
  572. WHERE permission = 'mark_notify' OR permission = 'mark_any_notify';
  573. ---#
  574. ---# Adding "profile_password_own"
  575. ---{
  576. $inserts = array();
  577. $request = upgrade_query("
  578. SELECT id_group, add_deny
  579. FROM {$db_prefix}permissions
  580. WHERE permission = 'profile_identity_own'");
  581. while ($row = $smcFunc['db_fetch_assoc']($request))
  582. {
  583. $inserts[] = "($row[id_group], 'profile_password_own', $row[add_deny])";
  584. }
  585. $smcFunc['db_free_result']($request);
  586. if (!empty($inserts))
  587. {
  588. upgrade_query("
  589. INSERT INTO {$db_prefix}permissions
  590. (id_group, permission, add_deny)
  591. VALUES
  592. " . implode(',', $inserts)
  593. );
  594. }
  595. ---}
  596. ---#
  597. ---# Adding other profile permissions
  598. ---{
  599. $inserts = array();
  600. $request = upgrade_query("
  601. SELECT id_group, add_deny
  602. FROM {$db_prefix}permissions
  603. WHERE permission = 'profile_extra_own'");
  604. while ($row = $smcFunc['db_fetch_assoc']($request))
  605. {
  606. $inserts[] = "($row[id_group], 'profile_blurb_own', $row[add_deny])";
  607. $inserts[] = "($row[id_group], 'profile_displayed_name_own', $row[add_deny])";
  608. $inserts[] = "($row[id_group], 'profile_forum_own', $row[add_deny])";
  609. $inserts[] = "($row[id_group], 'profile_other_own', $row[add_deny])";
  610. $inserts[] = "($row[id_group], 'profile_signature_own', $row[add_deny])";
  611. }
  612. $smcFunc['db_free_result']($request);
  613. if (!empty($inserts))
  614. {
  615. upgrade_query("
  616. INSERT INTO {$db_prefix}permissions
  617. (id_group, permission, add_deny)
  618. VALUES
  619. " . implode(',', $inserts)
  620. );
  621. }
  622. ---}
  623. ---#
  624. /******************************************************************************/
  625. --- Upgrading PM labels...
  626. /******************************************************************************/
  627. ---# Adding pm_labels table...
  628. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labels (
  629. id_label int(10) unsigned NOT NULL auto_increment,
  630. id_member mediumint(8) unsigned NOT NULL default '0',
  631. name varchar(30) NOT NULL default '',
  632. PRIMARY KEY (id_label)
  633. ) ENGINE=MyISAM;
  634. ---#
  635. ---# Adding pm_labeled_messages table...
  636. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labeled_messages (
  637. id_label int(10) unsigned NOT NULL default '0',
  638. id_pm int(10) unsigned NOT NULL default '0',
  639. PRIMARY KEY (id_label, id_pm)
  640. ) ENGINE=MyISAM;
  641. ---#
  642. ---# Adding "in_inbox" column to pm_recipients
  643. ALTER TABLE {$db_prefix}pm_recipients
  644. ADD COLUMN in_inbox tinyint(3) NOT NULL default '1';
  645. ---#
  646. ---# Moving label info to new tables and updating rules...
  647. ---{
  648. // First see if we still have a message_labels column
  649. $results = $smcFunc['db_list_columns']('{db_prefix}members');
  650. if (in_array('message_labels', $results))
  651. {
  652. // They've still got it, so pull the label info
  653. $get_labels = $smcFunc['db_query']('', '
  654. SELECT id_member, message_labels
  655. FROM {db_prefix}members
  656. WHERE message_labels != {string:blank}',
  657. array(
  658. 'blank' => '',
  659. )
  660. );
  661. $inserts = array();
  662. $label_info = array();
  663. while ($row = $smcFunc['db_fetch_assoc']($get_labels))
  664. {
  665. // Stick this in an array
  666. $labels = explode(',', $row['message_labels']);
  667. // Build some inserts
  668. foreach ($labels AS $index => $label)
  669. {
  670. // Keep track of the index of this label - we'll need that in a bit...
  671. $label_info[$row['id_member']][$label] = $index;
  672. $inserts[] = array($row['id_member'], $label);
  673. }
  674. }
  675. $smcFunc['db_free_result']($get_labels);
  676. if (!empty($inserts))
  677. {
  678. $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
  679. // Clear this out for our next query below
  680. $inserts = array();
  681. }
  682. // This is the easy part - update the inbox stuff
  683. $smcFunc['db_query']('', '
  684. UPDATE {db_prefix}pm_recipients
  685. SET in_inbox = {int:in_inbox}
  686. WHERE FIND_IN_SET({int:minusone}, labels)',
  687. array(
  688. 'in_inbox' => 1,
  689. 'minusone' => -1,
  690. )
  691. );
  692. // Now we go pull the new IDs for each label
  693. $get_new_label_ids = $smcFunc['db_query']('', '
  694. SELECT *
  695. FROM {db_prefix}pm_labels',
  696. array(
  697. )
  698. );
  699. $label_info_2 = array();
  700. while ($label_row = $smcFunc['db_fetch_assoc']($get_new_label_ids))
  701. {
  702. // Map the old index values to the new ID values...
  703. $old_index = $label_info[$row['id_member']][$row['label_name']];
  704. $label_info_2[$row['id_member']][$old_index] = $row['id_label'];
  705. }
  706. $smcFunc['db_free_result']($get_new_label_ids);
  707. // Pull label info from pm_recipients
  708. // Ignore any that are only in the inbox
  709. $get_pm_labels = $smcFunc['db_query']('', '
  710. SELECT id_pm, id_member, labels
  711. FROM {db_prefix}pm_recipients
  712. WHERE deleted = {int:not_deleted}
  713. AND labels != {string:minus_one}',
  714. array(
  715. 'not_deleted' => 0,
  716. 'minus_one' => -1,
  717. )
  718. );
  719. while ($row = $smcFunc['db_fetch_assoc']($get_pm_labels))
  720. {
  721. $labels = explode(',', $row['labels']);
  722. foreach ($labels as $a_label)
  723. {
  724. if ($a_label == '-1')
  725. continue;
  726. $new_label_info = $label_info_2[$row['id_member']][$a_label];
  727. $inserts[] = array($row['id_pm'], $new_label_info);
  728. }
  729. }
  730. $smcFunc['db_free_result']($get_pm_labels);
  731. // Insert the new data
  732. if (!empty($inserts))
  733. {
  734. $smcFunc['db_insert']('', '{db_prefix}pm_labeled_messages', array('id_pm' => 'int', 'id_label' => 'int'), $inserts, array());
  735. }
  736. // Final step of this ridiculously massive process
  737. $get_pm_rules = $smcFunc['db_query']('', '
  738. SELECT id_member, id_rule, actions
  739. FROM {db_prefix}pm_rules',
  740. array(
  741. )
  742. );
  743. // Go through the rules, unserialize the actions, then figure out if there's anything we can use
  744. while ($row = $smcFunc['db_fetch_assoc']($get_pm_rules))
  745. {
  746. // Turn this into an array...
  747. $actions = unserialize($row['actions']);
  748. // Loop through the actions and see if we're applying a label anywhere
  749. foreach ($actions as $index => $action)
  750. {
  751. if ($action['t'] == 'lab')
  752. {
  753. // Update the value of this label...
  754. $actions[$index]['v'] = $label_info_2[$row['id_member']][$action['v']];
  755. }
  756. }
  757. // Put this back into a string
  758. $actions = serialize($actions);
  759. $smcFunc['db_query']('', '
  760. UPDATE {db_prefix}pm_rules
  761. SET actions = {string:actions}
  762. WHERE id_rule = {int:id_rule}',
  763. array(
  764. 'actions' => $actions,
  765. 'id_rule' => $row['id_rule'],
  766. )
  767. );
  768. }
  769. $smcFunc['db_free_result']($get_pm_rules);
  770. // Lastly, we drop the old columns
  771. $smcFunc['db_remove_column']('{db_prefix}members', 'message_labels');
  772. $smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
  773. }
  774. ---}
  775. ---#
  776. /******************************************************************************/
  777. --- Adding support for edit reasons
  778. /******************************************************************************/
  779. ---# Adding "modified_reason" column to messages
  780. ALTER TABLE {$db_prefix}messages
  781. ADD COLUMN modified_reason varchar(255) NOT NULL;
  782. ---#
  783. /******************************************************************************/
  784. --- Cleaning up guest permissions
  785. /******************************************************************************/
  786. ---# Removing permissions guests can no longer have...
  787. ---{
  788. $illegal_board_permissions = array(
  789. 'announce_topic',
  790. 'delete_any',
  791. 'lock_any',
  792. 'make_sticky',
  793. 'merge_any',
  794. 'modify_any',
  795. 'modify_replies',
  796. 'move_any',
  797. 'poll_add_any',
  798. 'poll_edit_any',
  799. 'poll_lock_any',
  800. 'poll_remove_any',
  801. 'remove_any',
  802. 'report_any',
  803. 'split_any'
  804. );
  805. $illegal_permissions = array('calendar_edit_any', 'moderate_board', 'moderate_forum', 'send_email_to_members');
  806. $smcFunc['db_query']('', '
  807. DELETE FROM {db_prefix}board_permissions
  808. WHERE id_group = {int:guests}
  809. AND permission IN ({array_string:illegal_board_perms})',
  810. array(
  811. 'guests' => -1,
  812. 'illegal_board_perms' => $illegal_board_permissions,
  813. )
  814. );
  815. $smcFunc['db_query']('', '
  816. DELETE FROM {db_prefix}permissions
  817. WHERE id_group = {int:guests}
  818. AND permission IN ({array_string:illegal_perms})',
  819. array(
  820. 'guests' => -1,
  821. 'illegal_perms' => $illegal_permissions,
  822. )
  823. );
  824. ---}
  825. ---#
  826. /******************************************************************************/
  827. --- Adding mail queue settings
  828. /******************************************************************************/
  829. ---#
  830. ---{
  831. if (empty($modSettings['mail_limit']))
  832. {
  833. $smcFunc['db_insert']('replace',
  834. '{db_prefix}settings',
  835. array('variable' => 'string-255', 'value' => 'string'),
  836. array(
  837. array('mail_limit', '5'),
  838. array('mail_quantity', '5'),
  839. ),
  840. array('variable')
  841. );
  842. }
  843. ---}
  844. ---#