upgrade_2-1_postgresql.sql 32 KB

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