upgrade_2-1_postgresql.sql 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  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 mediumint 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 = mysql_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 unsigned 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. CHANGE msn skype varchar(255) NOT NULL DEFAULT '';
  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. upgrade_query("
  291. ALTER TABLE {$db_prefix}categories
  292. ADD COLUMN description text NOT NULL;");
  293. ---}
  294. ---#
  295. /******************************************************************************/
  296. --- Adding support for alerts
  297. /******************************************************************************/
  298. ---# Adding the count to the members table...
  299. ALTER TABLE {$db_prefix}members
  300. ADD COLUMN alerts int NOT NULL default '0';
  301. ---#
  302. ---# Adding the new table for alerts.
  303. CREATE SEQUENCE {$db_prefix}user_alerts_seq;
  304. CREATE TABLE {$db_prefix}user_alerts (
  305. id_alert int default nextval('{$db_prefix}user_alerts_seq'),
  306. alert_time int NOT NULL default '0',
  307. id_member int NOT NULL default '0',
  308. id_member_started int NOT NULL default '0',
  309. member_name varchar(255) NOT NULL default '',
  310. content_type varchar(255) NOT NULL default '',
  311. content_id int NOT NULL default '0',
  312. content_action varchar(255) NOT NULL default '',
  313. is_read smallint NOT NULL default '0',
  314. extra text NOT NULL,
  315. PRIMARY KEY (id_alert)
  316. );
  317. CREATE INDEX {$db_prefix}user_alerts_id_member ON {$db_prefix}user_alerts (id_member);
  318. CREATE INDEX {$db_prefix}user_alerts_alert_time ON {$db_prefix}user_alerts (alert_time);
  319. ---#
  320. /******************************************************************************/
  321. --- Adding support for topic unwatch
  322. /******************************************************************************/
  323. ---# Adding new columns to log_topics...
  324. ---{
  325. upgrade_query("
  326. ALTER TABLE {$db_prefix}log_topics
  327. ADD COLUMN unwatched int NOT NULL DEFAULT '0'");
  328. UPDATE {$db_prefix}log_topics
  329. SET unwatched = 0;
  330. INSERT INTO {$db_prefix}settings
  331. (variable, value)
  332. VALUES
  333. ('enable_unwatch', 0);
  334. ---}
  335. ---#
  336. ---# Fixing column name change...
  337. ---{
  338. upgrade_query("
  339. ALTER TABLE {$db_prefix}log_topics
  340. CHANGE COLUMN disregarded unwatched tinyint(3) NOT NULL DEFAULT '0';");
  341. ---}
  342. ---#
  343. /******************************************************************************/
  344. --- Name changes
  345. /******************************************************************************/
  346. ---# Altering the membergroup stars to icons
  347. ---{
  348. upgrade_query("
  349. ALTER TABLE {$db_prefix}membergroups
  350. CHANGE `stars` `icons` varchar(255) NOT NULL DEFAULT ''");
  351. ---}
  352. ---#
  353. ---# Renaming default theme...
  354. UPDATE {$db_prefix}themes
  355. SET value = 'SMF Default Theme - Curve2'
  356. WHERE value LIKE 'SMF Default Theme%';
  357. ---#
  358. /******************************************************************************/
  359. --- Cleaning up after old themes...
  360. /******************************************************************************/
  361. ---# Checking for "core" and removing it if necessary...
  362. ---{
  363. // Do they have "core" installed?
  364. if (file_exists($GLOBALS['boarddir'] . '/Themes/core'))
  365. {
  366. $core_dir = $GLOBALS['boarddir'] . '/Themes/core';
  367. $theme_request = upgrade_query("
  368. SELECT id_theme
  369. FROM {$db_prefix}themes
  370. WHERE variable = 'theme_dir'
  371. AND value ='$core_dir'");
  372. // Don't do anything if this theme is already uninstalled
  373. if ($smcFunc['db_num_rows']($theme_request) == 1)
  374. {
  375. list($id_theme) = $smcFunc['db_fetch_row']($theme_request, 0);
  376. $smcFunc['db_free_result']($theme_request);
  377. $known_themes = explode(', ', $modSettings['knownThemes']);
  378. // Remove this value...
  379. $known_themes = array_diff($known_themes, array($id_theme));
  380. // Change back to a string...
  381. $known_themes = implode(', ', $known_themes);
  382. // Update the database
  383. upgrade_query("
  384. UPDATE {$db_prefix}settings
  385. SET value = '$known_themes'
  386. WHERE variable = 'knownThemes'");
  387. // Delete any info about this theme
  388. upgrade_query("
  389. DELETE FROM {$db_prefix}themes
  390. WHERE id_theme = $id_theme");
  391. // Set any members or boards using this theme to the default
  392. upgrade_query("
  393. UPDATE {$db_prefix}members
  394. SET id_theme = 0
  395. WHERE id_theme = $id_theme");
  396. upgrade_query("
  397. UPDATE {$db_prefix}boards
  398. SET id_theme = 0
  399. WHERE id_theme = $id_theme");
  400. if ($modSettings['theme_guests'] == $id_theme)
  401. {
  402. upgrade_query("
  403. UPDATE {$db_prefix}settings
  404. SET value = 0
  405. WHERE variable = 'theme_guests'");
  406. }
  407. }
  408. }
  409. ---}
  410. ---#
  411. /******************************************************************************/
  412. --- Adding support for drafts
  413. /******************************************************************************/
  414. ---# Creating drafts table.
  415. CREATE TABLE {$db_prefix}user_drafts (
  416. id_draft int NOT NULL auto_increment,
  417. id_topic int NOT NULL default '0',
  418. id_board smallint NOT NULL default '0',
  419. id_reply int NOT NULL default '0',
  420. type smallint NOT NULL default '0',
  421. poster_time int NOT NULL default '0',
  422. id_member int NOT NULL default '0',
  423. subject varchar(255) NOT NULL default '',
  424. smileys_enabled smallint NOT NULL default '1',
  425. body text NOT NULL,
  426. icon varchar(16) NOT NULL default 'xx',
  427. locked smallint NOT NULL default '0',
  428. is_sticky smallint NOT NULL default '0',
  429. to_list varchar(255) NOT NULL default '',
  430. PRIMARY KEY (id_draft)
  431. );
  432. CREATE UNIQUE INDEX {$db_prefix}user_drafts_id_member ON {$db_prefix}user_drafts (id_member, id_draft, type);
  433. ---#
  434. ---# Adding draft permissions...
  435. ---{
  436. // We cannot do this twice
  437. if (@$modSettings['smfVersion'] < '2.1')
  438. {
  439. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  440. $request = upgrade_query("
  441. SELECT id_group, id_board, add_deny, permission
  442. FROM {$db_prefix}board_permissions
  443. WHERE permission = 'post_unapproved_topics'");
  444. $inserts = array();
  445. while ($row = $smcFunc['db_fetch_assoc']($request))
  446. {
  447. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  448. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  449. }
  450. $smcFunc['db_free_result']($request);
  451. if (!empty($inserts))
  452. {
  453. foreach ($inserts AS $insert)
  454. {
  455. upgrade_query("
  456. INSERT INTO {$db_prefix}board_permissions
  457. (id_group, id_board, permission, add_deny)
  458. VALUES
  459. " . $insert);
  460. }
  461. }
  462. // Next we find people who can send PMs, and assume they can save pm_drafts as well
  463. $request = upgrade_query("
  464. SELECT id_group, add_deny, permission
  465. FROM {$db_prefix}permissions
  466. WHERE permission = 'pm_send'");
  467. $inserts = array();
  468. while ($row = $smcFunc['db_fetch_assoc']($request))
  469. {
  470. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  471. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  472. }
  473. $smcFunc['db_free_result']($request);
  474. if (!empty($inserts))
  475. {
  476. foreach ($inserts AS $insert)
  477. {
  478. upgrade_query("
  479. INSERT INTO {$db_prefix}permissions
  480. (id_group, permission, add_deny)
  481. VALUES
  482. " . $insert);
  483. }
  484. }
  485. }
  486. ---}
  487. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_autosave_enabled', '1');
  488. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_show_saved_enabled', '1');
  489. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_keep_days', '7');
  490. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_autosave_enabled', '1');
  491. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_show_saved_enabled', '1');
  492. ---#
  493. /******************************************************************************/
  494. --- Adding support for likes
  495. /******************************************************************************/
  496. ---# Creating likes table.
  497. CREATE TABLE IF NOT EXISTS {$db_prefix}user_likes (
  498. id_member int NOT NULL default '0',
  499. content_type char(6) default '',
  500. content_id int NOT NULL default '0',
  501. like_time int NOT NULL default '0',
  502. PRIMARY KEY (content_id, content_type, id_member)
  503. );
  504. CREATE INDEX {$db_prefix}user_likes_content ON {$db_prefix}user_likes (content_id, content_type);
  505. CREATE INDEX {$db_prefix}user_likes_liker ON {$db_prefix}user_likes (id_member);
  506. ---#
  507. ---# Adding count to the messages table.
  508. ALTER TABLE {$db_prefix}messages
  509. ADD COLUMN likes smallint NOT NULL default '0';
  510. ---#
  511. /******************************************************************************/
  512. --- Adding support for group-based board moderation
  513. /******************************************************************************/
  514. ---# Creating moderator_groups table
  515. CREATE TABLE IF NOT EXISTS {$db_prefix}moderator_groups (
  516. id_board smallint NOT NULL default '0',
  517. id_group smallint NOT NULL default '0',
  518. PRIMARY KEY (id_board, id_group)
  519. );
  520. ---#
  521. /******************************************************************************/
  522. --- Cleaning up integration hooks
  523. /******************************************************************************/
  524. ---#
  525. DELETE FROM {$db_prefix}settings
  526. WHERE variable LIKE 'integrate_%';
  527. ---#
  528. /******************************************************************************/
  529. --- Cleaning up old settings
  530. /******************************************************************************/
  531. ---# Showing contact details to guests should never happen.
  532. DELETE FROM {$db_prefix}settings
  533. WHERE variable IN ('enableStickyTopics', 'guest_hideContacts');
  534. ---#
  535. /******************************************************************************/
  536. --- Removing old Simple Machines files we do not need to fetch any more
  537. /******************************************************************************/
  538. ---# We no longer call on the latest packages list.
  539. DELETE FROM {$db_prefix}admin_info_files
  540. WHERE filename = 'latest-packages.js'
  541. AND path = '/smf/';
  542. ---#
  543. /******************************************************************************/
  544. --- Upgrading "verification questions" feature
  545. /******************************************************************************/
  546. ---# Creating qanda table
  547. CREATE TABLE {$db_prefix}qanda (
  548. id_question smallint(5) unsigned NOT NULL auto_increment,
  549. lngfile varchar(255) NOT NULL default '',
  550. question varchar(255) NOT NULL default '',
  551. answers text NOT NULL,
  552. PRIMARY KEY (id_question),
  553. KEY lngfile (lngfile)
  554. );
  555. ---#
  556. ---# Moving questions and answers to the new table
  557. ---{
  558. $questions = array();
  559. $get_questions = upgrade_query("
  560. SELECT body AS question, recipient_name AS answer
  561. FROM {$db_prefix}log_comments
  562. WHERE comment_type = 'ver_test'");
  563. while ($row = $smcFunc['db_fetch_assoc']($get_questions))
  564. $questions[] = array($language, $row['question'], serialize(array($row['answer'])));
  565. $smcFunc['db_free_result']($get_questions);
  566. if (!empty($questions))
  567. {
  568. $smcFunc['db_insert']('',
  569. '{db_prefix}qanda',
  570. array('lngfile' => 'string', 'question' => 'string', 'answers' => 'string'),
  571. $questions,
  572. array('id_question')
  573. );
  574. // Delete the questions from log_comments now
  575. upgrade_query("
  576. DELETE FROM {$db_prefix}log_comments
  577. WHERE comment_type = 'ver_test'
  578. ");
  579. }
  580. ---}
  581. ---#
  582. /******************************************************************************/
  583. --- Fixing log_online table
  584. /******************************************************************************/
  585. ---# Changing ip to bigint
  586. ALTER TABLE {$db_prefix}log_online ALTER ip TYPE bigint;
  587. ---#
  588. /******************************************************************************/
  589. --- Marking packages as uninstalled...
  590. /******************************************************************************/
  591. ---# Updating log_packages
  592. UPDATE {$db_prefix}log_packages
  593. SET install_state = 0;
  594. ---#
  595. /******************************************************************************/
  596. --- Updating profile permissions...
  597. /******************************************************************************/
  598. ---# Removing the old "view your own profile" permission
  599. DELETE FROM {$db_prefix}permissions
  600. WHERE permission = 'profile_view_own';
  601. ---#
  602. ---# Updating the old "view any profile" permission
  603. UPDATE {$db_prefix}permissions
  604. SET permission = 'profile_view'
  605. WHERE permission = 'profile_view_any';
  606. ---#
  607. ---# Removing the old notification permissions
  608. DELETE FROM {$db_prefix}board_permissions
  609. WHERE permission = 'mark_notify' OR permission = 'mark_any_notify';
  610. ---#
  611. ---# Adding "profile_password_own"
  612. ---{
  613. $inserts = array();
  614. $request = upgrade_query("
  615. SELECT id_group, add_deny
  616. FROM {$db_prefix}permissions
  617. WHERE permission = 'profile_identity_own'");
  618. while ($row = $smcFunc['db_fetch_assoc']($request))
  619. {
  620. $inserts[] = "($row[id_group], 'profile_password_own', $row[add_deny])";
  621. }
  622. $smcFunc['db_free_result']($request);
  623. if (!empty($inserts))
  624. {
  625. foreach ($inserts as $insert)
  626. {
  627. upgrade_query("
  628. INSERT INTO {$db_prefix}permissions
  629. (id_group, permission, add_deny)
  630. VALUES
  631. " . $insert);
  632. }
  633. }
  634. ---}
  635. ---#
  636. ---# Adding other profile permissions
  637. ---{
  638. $inserts = array();
  639. $request = upgrade_query("
  640. SELECT id_group, add_deny
  641. FROM {$db_prefix}permissions
  642. WHERE permission = 'profile_extra_own'");
  643. while ($row = $smcFunc['db_fetch_assoc']($request))
  644. {
  645. $inserts[] = "($row[id_group], 'profile_blurb_own', $row[add_deny])";
  646. $inserts[] = "($row[id_group], 'profile_displayed_name_own', $row[add_deny])";
  647. $inserts[] = "($row[id_group], 'profile_forum_own', $row[add_deny])";
  648. $inserts[] = "($row[id_group], 'profile_other_own', $row[add_deny])";
  649. $inserts[] = "($row[id_group], 'profile_signature_own', $row[add_deny])";
  650. }
  651. $smcFunc['db_free_result']($request);
  652. if (!empty($inserts))
  653. {
  654. foreach ($inserts as $insert)
  655. {
  656. upgrade_query("
  657. INSERT INTO {$db_prefix}permissions
  658. (id_group, permission, add_deny)
  659. VALUES
  660. " . $insert
  661. );
  662. }
  663. }
  664. ---}
  665. ---#
  666. /******************************************************************************/
  667. --- Upgrading PM labels...
  668. /******************************************************************************/
  669. ---# Creating pm_labels sequence...
  670. CREATE SEQUENCE {$db_prefix}pm_labels_sequence;
  671. ---#
  672. ---# Adding pm_labels table...
  673. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labels (
  674. id_label int NOT NULL default nextval('{$db_prefix}pm_labels_seq'),
  675. id_member int NOT NULL default '0',
  676. name varchar(30) NOT NULL default '',
  677. PRIMARY KEY (id_label)
  678. );
  679. ---#
  680. ---# Adding pm_labeled_messages table...
  681. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labeled_messages (
  682. id_label int NOT NULL default '0',
  683. id_pm int NOT NULL default '0',
  684. PRIMARY KEY (id_label, id_pm)
  685. );
  686. ---#
  687. ---# Adding "in_inbox" column to pm_recipients
  688. ALTER TABLE {$db_prefix}pm_recipients
  689. ADD COLUMN in_inbox smallint NOT NULL default '1';
  690. ---#
  691. ---# Moving label info to new tables and updating rules...
  692. ---{
  693. // First see if we still have a message_labels column
  694. $results = $smcFunc['db_list_columns']('{db_prefix}members', false);
  695. if (in_array('message_labels', $results))
  696. {
  697. // They've still got it, so pull the label info
  698. $get_labels = $smcFunc['db_query']('', '
  699. SELECT id_member, message_labels
  700. FROM {db_prefix}members
  701. WHERE message_labels != {string:blank}',
  702. array(
  703. 'blank' => '',
  704. )
  705. );
  706. $inserts = array();
  707. $label_info = array();
  708. while ($row = $smcFunc['db_fetch_assoc']($get_labels))
  709. {
  710. // Stick this in an array
  711. $labels = explode(',', $row['message_labels']);
  712. // Build some inserts
  713. foreach ($labels AS $index => $label)
  714. {
  715. // Keep track of the index of this label - we'll need that in a bit...
  716. $label_info[$row['id_member']][$label] = $index;
  717. $inserts[] = array($row['id_member'], $label);
  718. }
  719. }
  720. $smcFunc['db_free_result']($get_labels);
  721. if (!empty($inserts))
  722. {
  723. $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
  724. // Clear this out for our next query below
  725. $inserts = array();
  726. }
  727. // This is the easy part - update the inbox stuff
  728. $smcFunc['db_query']('', '
  729. UPDATE {db_prefix}pm_recipients
  730. SET in_inbox = {int:in_inbox}
  731. WHERE FIND_IN_SET({int:minus_one}, labels)',
  732. array(
  733. 'in_inbox' => 1,
  734. 'minus_one' => -1,
  735. )
  736. );
  737. // Now we go pull the new IDs for each label
  738. $get_new_label_ids = $smcFunc['db_query']('', '
  739. SELECT *
  740. FROM {db_prefix}pm_labels',
  741. array(
  742. )
  743. );
  744. $label_info_2 = array();
  745. while ($label_row = $smcFunc['db_fetch_assoc']($get_new_label_ids))
  746. {
  747. // Map the old index values to the new ID values...
  748. $old_index = $label_info[$row['id_member']][$row['label_name']];
  749. $label_info_2[$row['id_member']][$old_index] = $row['id_label'];
  750. }
  751. $smcFunc['db_free_result']($get_new_label_ids);
  752. // Pull label info from pm_recipients
  753. // Ignore any that are only in the inbox
  754. $get_pm_labels = $smcFunc['db_query']('', '
  755. SELECT id_pm, id_member, labels
  756. FROM {db_prefix}pm_recipients
  757. WHERE deleted = {int:not_deleted}
  758. AND labels != {string:minus_one}',
  759. array(
  760. 'not_deleted' => 0,
  761. 'minus_one' => -1,
  762. )
  763. );
  764. while ($row = $smcFunc['db_fetch_assoc']($get_pm_labels))
  765. {
  766. $labels = explode(',', $row['labels']);
  767. foreach ($labels as $a_label)
  768. {
  769. if ($a_label == '-1')
  770. continue;
  771. $new_label_info = $label_info_2[$row['id_member']][$a_label];
  772. $inserts[] = array($row['id_pm'], $new_label_info);
  773. }
  774. }
  775. $smcFunc['db_free_result']($get_pm_labels);
  776. // Insert the new data
  777. if (!empty($inserts))
  778. {
  779. $smcFunc['db_insert']('', '{db_prefix}pm_labeled_messages', array('id_pm' => 'int', 'id_label' => 'int'), $inserts, array());
  780. }
  781. // Final step of this ridiculously massive process
  782. $get_pm_rules = $smcFunc['db_query']('', '
  783. SELECT id_member, id_rule, actions
  784. FROM {db_prefix}pm_rules',
  785. array(
  786. ),
  787. );
  788. // Go through the rules, unserialize the actions, then figure out if there's anything we can use
  789. while ($row = $smcFunc['db_fetch_assoc']($get_pm_rules))
  790. {
  791. // Turn this into an array...
  792. $actions = unserialize($row['actions']);
  793. // Loop through the actions and see if we're applying a label anywhere
  794. foreach ($actions as $index => $action)
  795. {
  796. if ($action['t'] == 'lab')
  797. {
  798. // Update the value of this label...
  799. $actions[$index]['v'] = $label_info_2[$row['id_member']][$action['v']];
  800. }
  801. }
  802. // Put this back into a string
  803. $actions = serialize($actions);
  804. $smcFunc['db_query']('', '
  805. UPDATE {db_prefix}pm_rules
  806. SET actions = {string:actions}
  807. WHERE id_rule = {int:id_rule}',
  808. array(
  809. 'actions' => $actions,
  810. 'id_rule' => $row['id_rule'],
  811. )
  812. );
  813. }
  814. $smcFunc['db_free_result']($get_pm_rules);
  815. // Lastly, we drop the old columns
  816. $smcFunc['db_remove_column']('{db_prefix}members', 'message_labels');
  817. $smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
  818. }
  819. }
  820. /******************************************************************************/
  821. --- Adding support for edit reasons
  822. /******************************************************************************/
  823. ---# Adding "modified_reason" column to messages
  824. ALTER TABLE {$db_prefix}messages
  825. ADD COLUMN modified_reason varchar(255) NOT NULL default '';
  826. ---#
  827. /******************************************************************************/
  828. --- Cleaning up guest permissions
  829. /******************************************************************************/
  830. ---# Removing permissions guests can no longer have...
  831. ---{
  832. $illegal_board_permissions = array(
  833. 'announce_topic',
  834. 'delete_any',
  835. 'lock_any',
  836. 'make_sticky',
  837. 'merge_any',
  838. 'modify_any',
  839. 'modify_replies',
  840. 'move_any',
  841. 'poll_add_any',
  842. 'poll_edit_any',
  843. 'poll_lock_any',
  844. 'poll_remove_any',
  845. 'remove_any',
  846. 'report_any',
  847. 'split_any'
  848. );
  849. $illegal_permissions = array('calendar_edit_any', 'moderate_board', 'moderate_forum', 'send_email_to_members');
  850. $smcFunc['db_query']('', '
  851. DELETE FROM {db_prefix}board_permissions
  852. WHERE id_group = {int:guests}
  853. AND permission IN ({array_string:illegal_board_perms})',
  854. array(
  855. 'guests' => -1,
  856. 'illegal_board_perms' => $illegal_board_permissions,
  857. )
  858. );
  859. $smcFunc['db_query']('', '
  860. DELETE FROM {db_prefix}permissions
  861. WHERE id_group = {int:guests}
  862. AND permission IN ({array_string:illegal_perms})',
  863. array(
  864. 'guests' => -1,
  865. 'illegal_perms' => $illegal_permissions,
  866. )
  867. );
  868. ---}
  869. ---#