upgrade_2-1_postgresql.sql 33 KB

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