upgrade_2-1_postgresql.sql 30 KB

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