upgrade_2-1_postgresql.sql 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. /* ATTENTION: You don't need to run or use this file! The upgrade.php script does everything for you! */
  2. /******************************************************************************/
  3. --- Adding new settings...
  4. /******************************************************************************/
  5. ---# Creating login history sequence.
  6. CREATE SEQUENCE {$db_prefix}member_logins_seq;
  7. ---#
  8. ---# Creating login history table.
  9. CREATE TABLE {$db_prefix}member_logins (
  10. id_login int NOT NULL default nextval('{$db_prefix}member_logins_seq'),
  11. id_member int NOT NULL,
  12. time int NOT NULL,
  13. ip varchar(255) NOT NULL default '',
  14. ip2 varchar(255) NOT NULL default '',
  15. PRIMARY KEY (id_login)
  16. );
  17. ---#
  18. ---# Copying the current package backup setting...
  19. ---{
  20. if (!isset($modSettings['package_make_full_backups']) && isset($modSettings['package_make_backups']))
  21. upgrade_query("
  22. INSERT INTO {$db_prefix}settings
  23. (variable, value)
  24. VALUES
  25. ('package_make_full_backups', '" . $modSettings['package_make_backups'] . "')");
  26. ---}
  27. ---#
  28. ---# Copying the current "allow users to disable word censor" setting...
  29. ---{
  30. if (!isset($modSettings['allow_no_censored']))
  31. {
  32. $request = upgrade_query("
  33. SELECT value
  34. FROM {$db_prefix}themes
  35. WHERE variable='allow_no_censored'
  36. AND id_theme = 1 OR id_theme = '$modSettings[theme_default]'
  37. ");
  38. // Is it set for either "default" or the one they've set as default?
  39. while ($row = $smcFunc['db_fetch_assoc']($request))
  40. {
  41. if ($row['value'] == 1)
  42. {
  43. upgrade_query("
  44. INSERT INTO {$db_prefix}settings
  45. VALUES ('allow_no_censored', 1)
  46. ");
  47. // Don't do this twice...
  48. break;
  49. }
  50. }
  51. }
  52. ---}
  53. ---#
  54. ---# Adding new "topic_move_any" setting
  55. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('topic_move_any', '1');
  56. ---#
  57. /******************************************************************************/
  58. --- Updating legacy attachments...
  59. /******************************************************************************/
  60. ---# Converting legacy attachments.
  61. ---{
  62. // Need to know a few things first.
  63. $custom_av_dir = !empty($modSettings['custom_avatar_dir']) ? $modSettings['custom_avatar_dir'] : $GLOBALS['boarddir'] .'/custom_avatar';
  64. // This little fellow has to cooperate...
  65. if (!is_writable($custom_av_dir))
  66. @chmod($custom_av_dir, 0777);
  67. $request = upgrade_query("
  68. SELECT MAX(id_attach)
  69. FROM {$db_prefix}attachments");
  70. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  71. $smcFunc['db_free_result']($request);
  72. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  73. $step_progress['name'] = 'Converting legacy attachments';
  74. $step_progress['current'] = $_GET['a'];
  75. // We may be using multiple attachment directories.
  76. if (!empty($modSettings['currentAttachmentUploadDir']) && !is_array($modSettings['attachmentUploadDir']))
  77. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  78. $is_done = false;
  79. while (!$is_done)
  80. {
  81. nextSubStep($substep);
  82. $fileHash = '';
  83. $request = upgrade_query("
  84. SELECT id_attach, id_folder, filename, file_hash, mime_type
  85. FROM {$db_prefix}attachments
  86. WHERE attachment_type != 1
  87. LIMIT $_GET[a], 100");
  88. // Finished?
  89. if ($smcFunc['db_num_rows']($request) == 0)
  90. $is_done = true;
  91. while ($row = $smcFunc['db_fetch_assoc']($request))
  92. {
  93. // The current folder.
  94. $currentFolder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$row['id_folder']] : $modSettings['attachmentUploadDir'];
  95. // Old School?
  96. if (empty($row['file_hash']))
  97. {
  98. // Remove international characters (windows-1252)
  99. // These lines should never be needed again. Still, behave.
  100. if (empty($db_character_set) || $db_character_set != 'utf8')
  101. {
  102. $row['filename'] = strtr($row['filename'],
  103. "\x8a\x8e\x9a\x9e\x9f\xc0\xc1\xc2\xc3\xc4\xc5\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xe0\xe1\xe2\xe3\xe4\xe5\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xff",
  104. 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
  105. $row['filename'] = strtr($row['filename'], array("\xde" => 'TH', "\xfe" =>
  106. 'th', "\xd0" => 'DH', "\xf0" => 'dh', "\xdf" => 'ss', "\x8c" => 'OE',
  107. "\x9c" => 'oe', "\xc6" => 'AE', "\xe6" => 'ae', "\xb5" => 'u'));
  108. }
  109. // Sorry, no spaces, dots, or anything else but letters allowed.
  110. $row['filename'] = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $row['filename']);
  111. // Create a nice hash.
  112. $fileHash = sha1(md5($row['filename'] . time()) . mt_rand());
  113. // The old file, we need to know if the filename was encrypted or not.
  114. if (file_exists($currentFolder . '/' . $row['id_attach']. '_' . strtr($row['filename'], '.', '_') . md5($row['filename'])))
  115. $oldFile = $currentFolder . '/' . $row['id_attach']. '_' . strtr($row['filename'], '.', '_') . md5($row['filename']);
  116. else if (file_exists($currentFolder . '/' . $row['filename']));
  117. $oldFile = $currentFolder . '/' . $row['filename'];
  118. // Build the new file.
  119. $newFile = $currentFolder . '/' . $row['id_attach'] . '_' . $fileHash .'.dat';
  120. }
  121. // Just rename the file.
  122. else
  123. {
  124. $oldFile = $currentFolder . '/' . $row['id_attach'] . '_' . $row['file_hash'];
  125. $newFile = $currentFolder . '/' . $row['id_attach'] . '_' . $row['file_hash'] .'.dat';
  126. }
  127. // Check if the av is an attachment
  128. if ($row['id_member'] != 0)
  129. if (rename($oldFile, $custom_av_dir . '/' . $row['filename']))
  130. upgrade_query("
  131. UPDATE {$db_prefix}attachments
  132. SET file_hash = '', attachment_type = 1
  133. WHERE id_attach = $row[id_attach]");
  134. // Just a regular attachment.
  135. else
  136. rename($oldFile, $newFile);
  137. // Only update this if it was successful and the file was using the old system.
  138. if (empty($row['file_hash']) && !empty($fileHash) && file_exists($newFile) && !file_exists($oldFile))
  139. upgrade_query("
  140. UPDATE {$db_prefix}attachments
  141. SET file_hash = '$fileHash'
  142. WHERE id_attach = $row[id_attach]");
  143. // While we're here, do we need to update the mime_type?
  144. if (empty($row['mime_type']) && file_exists($newFile))
  145. {
  146. $size = @getimagesize($newFile);
  147. if (!empty($size['mime']))
  148. $smcFunc['db_query']('', '
  149. UPDATE {db_prefix}attachments
  150. SET mime_type = {string:mime_type}
  151. WHERE id_attach = {int:id_attach}',
  152. array(
  153. 'id_attach' => $row['id_attach'],
  154. 'mime_type' => substr($size['mime'], 0, 20),
  155. )
  156. );
  157. }
  158. }
  159. $smcFunc['db_free_result']($request);
  160. $_GET['a'] += 100;
  161. $step_progress['current'] = $_GET['a'];
  162. }
  163. unset($_GET['a']);
  164. ---}
  165. ---#
  166. ---# Fixing invalid sizes on attachments
  167. ---{
  168. $attachs = array();
  169. // If id_member = 0, then it's not an avatar
  170. // If attachment_type = 0, then it's also not a thumbnail
  171. // Theory says there shouldn't be *that* many of these
  172. $request = $smcFunc['db_query']('', '
  173. SELECT id_attach, mime_type, width, height
  174. FROM {db_prefix}attachments
  175. WHERE id_member = 0
  176. AND attachment_type = 0');
  177. while ($row = $smcFunc['db_fetch_assoc']($request))
  178. {
  179. if (($row['width'] > 0 || $row['height'] > 0) && strpos($row['mime_type'], 'image') !== 0)
  180. $attachs[] = $row['id_attach'];
  181. }
  182. $smcFunc['db_free_result']($request);
  183. if (!empty($attachs))
  184. $smcFunc['db_query']('', '
  185. UPDATE {db_prefix}attachments
  186. SET width = 0,
  187. height = 0
  188. WHERE id_attach IN ({array_int:attachs})',
  189. array(
  190. 'attachs' => $attachs,
  191. )
  192. );
  193. ---}
  194. ---#
  195. /******************************************************************************/
  196. --- Adding support for IPv6...
  197. /******************************************************************************/
  198. ---# Adding new columns to ban items...
  199. ALTER TABLE {$db_prefix}ban_items
  200. ADD COLUMN ip_low5 smallint NOT NULL DEFAULT '0',
  201. ADD COLUMN ip_high5 smallint NOT NULL DEFAULT '0',
  202. ADD COLUMN ip_low6 smallint NOT NULL DEFAULT '0',
  203. ADD COLUMN ip_high6 smallint NOT NULL DEFAULT '0',
  204. ADD COLUMN ip_low7 smallint NOT NULL DEFAULT '0',
  205. ADD COLUMN ip_high7 smallint NOT NULL DEFAULT '0',
  206. ADD COLUMN ip_low8 smallint NOT NULL DEFAULT '0',
  207. ADD COLUMN ip_high8 smallint NOT NULL DEFAULT '0';
  208. ---#
  209. ---# Changing existing columns to ban items...
  210. ---{
  211. upgrade_query("
  212. ALTER TABLE {$db_prefix}ban_items
  213. ALTER COLUMN ip_low1 type smallint,
  214. ALTER COLUMN ip_high1 type smallint,
  215. ALTER COLUMN ip_low2 type smallint,
  216. ALTER COLUMN ip_high2 type smallint,
  217. ALTER COLUMN ip_low3 type smallint,
  218. ALTER COLUMN ip_high3 type smallint,
  219. ALTER COLUMN ip_low4 type smallint,
  220. ALTER COLUMN ip_high4 type smallint;"
  221. );
  222. upgrade_query("
  223. ALTER TABLE {$db_prefix}ban_items
  224. ALTER COLUMN ip_low1 SET DEFAULT '0',
  225. ALTER COLUMN ip_high1 SET DEFAULT '0',
  226. ALTER COLUMN ip_low2 SET DEFAULT '0',
  227. ALTER COLUMN ip_high2 SET DEFAULT '0',
  228. ALTER COLUMN ip_low3 SET DEFAULT '0',
  229. ALTER COLUMN ip_high3 SET DEFAULT '0',
  230. ALTER COLUMN ip_low4 SET DEFAULT '0',
  231. ALTER COLUMN ip_high4 SET DEFAULT '0';"
  232. );
  233. upgrade_query("
  234. ALTER TABLE {$db_prefix}ban_items
  235. ALTER COLUMN ip_low1 SET NOT NULL,
  236. ALTER COLUMN ip_high1 SET NOT NULL,
  237. ALTER COLUMN ip_low2 SET NOT NULL,
  238. ALTER COLUMN ip_high2 SET NOT NULL,
  239. ALTER COLUMN ip_low3 SET NOT NULL,
  240. ALTER COLUMN ip_high3 SET NOT NULL,
  241. ALTER COLUMN ip_low4 SET NOT NULL,
  242. ALTER COLUMN ip_high4 SET NOT NULL;"
  243. );
  244. ---}
  245. ---#
  246. /******************************************************************************/
  247. --- Adding support for logging who fulfils a group request.
  248. /******************************************************************************/
  249. ---# Adding new columns to log_group_requests
  250. ALTER TABLE {$db_prefix}log_group_requests
  251. ADD COLUMN status smallint NOT NULL default '0',
  252. ADD COLUMN id_member_acted int NOT NULL default '0',
  253. ADD COLUMN member_name_acted varchar(255) NOT NULL default '',
  254. ADD COLUMN time_acted int NOT NULL default '0',
  255. ADD COLUMN act_reason text NOT NULL;
  256. ---#
  257. ---# Adjusting the indexes for log_group_requests
  258. DROP INDEX {$db_prefix}log_group_requests_id_member;
  259. CREATE INDEX {$db_prefix}log_group_requests_id_member ON {$db_prefix}log_group_requests (id_member, id_group);
  260. ---#
  261. /******************************************************************************/
  262. --- Adding support for <credits> tag in package manager
  263. /******************************************************************************/
  264. ---# Adding new columns to log_packages ..
  265. ALTER TABLE {$db_prefix}log_packages
  266. ADD COLUMN credits varchar(255) NOT NULL DEFAULT '';
  267. ---#
  268. /******************************************************************************/
  269. --- Adding more space for session ids
  270. /******************************************************************************/
  271. ---# Altering the session_id columns...
  272. ---{
  273. upgrade_query("
  274. ALTER TABLE {$db_prefix}log_online
  275. ALTER COLUMN session type varchar(64);
  276. ALTER TABLE {$db_prefix}log_errors
  277. ALTER COLUMN session type char(64);
  278. ALTER TABLE {$db_prefix}sessions
  279. ALTER COLUMN session_id type char(64);");
  280. upgrade_query("
  281. ALTER TABLE {$db_prefix}log_online
  282. ALTER COLUMN session SET DEFAULT '';
  283. ALTER TABLE {$db_prefix}log_errors
  284. ALTER COLUMN session SET default ' ';");
  285. upgrade_query("
  286. ALTER TABLE {$db_prefix}log_online
  287. ALTER COLUMN session SET NOT NULL;
  288. ALTER TABLE {$db_prefix}log_errors
  289. ALTER COLUMN session SET NOT NULL;
  290. ALTER TABLE {$db_prefix}sessions
  291. ALTER COLUMN session_id SET NOT NULL;");
  292. ---}
  293. ---#
  294. /******************************************************************************/
  295. --- Adding support for MOVED topics enhancements
  296. /******************************************************************************/
  297. ---# Adding new columns to topics table
  298. ---{
  299. upgrade_query("
  300. ALTER TABLE {$db_prefix}topics
  301. ADD COLUMN redirect_expires int NOT NULL DEFAULT '0'");
  302. upgrade_query("
  303. ALTER TABLE {$db_prefix}topics
  304. ADD COLUMN id_redirect_topic int NOT NULL DEFAULT '0'");
  305. ---}
  306. ---#
  307. /******************************************************************************/
  308. --- Adding new scheduled tasks
  309. /******************************************************************************/
  310. ---# Adding new scheduled tasks
  311. INSERT INTO {$db_prefix}scheduled_tasks
  312. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  313. VALUES
  314. (0, 120, 1, 'd', 0, 'remove_temp_attachments');
  315. INSERT INTO {$db_prefix}scheduled_tasks
  316. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  317. VALUES
  318. (0, 180, 1, 'd', 0, 'remove_topic_redirect');
  319. INSERT INTO {$db_prefix}scheduled_tasks
  320. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  321. VALUES
  322. (0, 240, 1, 'd', 0, 'remove_old_drafts');
  323. ---#
  324. /******************************************************************************/
  325. ---- Adding background tasks support
  326. /******************************************************************************/
  327. ---# Adding the sequence
  328. CREATE SEQUENCE {$db_prefix}background_tasks_seq;
  329. ---#
  330. ---# Adding the table
  331. CREATE TABLE {$db_prefix}background_tasks (
  332. id_task int default nextval('{$db_prefix}background_tasks_seq'),
  333. task_file varchar(255) NOT NULL default '',
  334. task_class varchar(255) NOT NULL default '',
  335. task_data text NOT NULL,
  336. claimed_time int NOT NULL default '0',
  337. PRIMARY KEY (id_task)
  338. );
  339. ---#
  340. /******************************************************************************/
  341. ---- Replacing MSN with Skype
  342. /******************************************************************************/
  343. ---# Modifying the "msn" column...
  344. ALTER TABLE {$db_prefix}members
  345. RENAME msn TO skype;
  346. ---#
  347. /******************************************************************************/
  348. --- Adding support for deny boards access
  349. /******************************************************************************/
  350. ---# Adding new columns to boards...
  351. ---{
  352. upgrade_query("
  353. ALTER TABLE {$db_prefix}boards
  354. ADD COLUMN deny_member_groups varchar(255) NOT NULL DEFAULT ''");
  355. ---}
  356. ---#
  357. /******************************************************************************/
  358. --- Updating board access rules
  359. /******************************************************************************/
  360. ---# Updating board access rules
  361. ---{
  362. $member_groups = array(
  363. 'allowed' => array(),
  364. 'denied' => array(),
  365. );
  366. $request = $smcFunc['db_query']('', '
  367. SELECT id_group, add_deny
  368. FROM {db_prefix}permissions
  369. WHERE permission = {string:permission}',
  370. array(
  371. 'permission' => 'manage_boards',
  372. )
  373. );
  374. while ($row = $smcFunc['db_fetch_assoc']($request))
  375. $member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group'];
  376. $smcFunc['db_free_result']($request);
  377. $member_groups = array_diff($member_groups['allowed'], $member_groups['denied']);
  378. if (!empty($member_groups))
  379. {
  380. $count = count($member_groups);
  381. $changes = array();
  382. $request = $smcFunc['db_query']('', '
  383. SELECT id_board, member_groups
  384. FROM {db_prefix}boards');
  385. while ($row = $smcFunc['db_fetch_assoc']($request))
  386. {
  387. $current_groups = explode(',', $row['member_groups']);
  388. if (count(array_intersect($current_groups, $member_groups)) != $count)
  389. {
  390. $new_groups = array_unique(array_merge($current_groups, $member_groups));
  391. $changes[$row['id_board']] = implode(',', $new_groups);
  392. }
  393. }
  394. $smcFunc['db_free_result']($request);
  395. if (!empty($changes))
  396. {
  397. foreach ($changes as $id_board => $member_groups)
  398. $smcFunc['db_query']('', '
  399. UPDATE {db_prefix}boards
  400. SET member_groups = {string:member_groups}
  401. WHERE id_board = {int:id_board}',
  402. array(
  403. 'member_groups' => $member_groups,
  404. 'id_board' => $id_board,
  405. )
  406. );
  407. }
  408. }
  409. ---}
  410. ---#
  411. /******************************************************************************/
  412. --- Adding support for category descriptions
  413. /******************************************************************************/
  414. ---# Adding new columns to categories...
  415. ---{
  416. // Sadly, PostgreSQL whines if we add a NOT NULL column without a default value to an existing table...
  417. upgrade_query("
  418. ALTER TABLE {$db_prefix}categories
  419. ADD COLUMN description text");
  420. upgrade_query("
  421. UPDATE {$db_prefix}categories
  422. SET description = ''");
  423. upgrade_query("
  424. ALTER TABLE {$db_prefix}categories
  425. ALTER COLUMN description SET NOT NULL");
  426. ---}
  427. ---#
  428. /******************************************************************************/
  429. --- Adding support for alerts
  430. /******************************************************************************/
  431. ---# Adding the count to the members table...
  432. ALTER TABLE {$db_prefix}members
  433. ADD COLUMN alerts int NOT NULL default '0';
  434. ---#
  435. ---# Adding the new table for alerts.
  436. CREATE SEQUENCE {$db_prefix}user_alerts_seq;
  437. CREATE TABLE {$db_prefix}user_alerts (
  438. id_alert int default nextval('{$db_prefix}user_alerts_seq'),
  439. alert_time int NOT NULL default '0',
  440. id_member int NOT NULL default '0',
  441. id_member_started int NOT NULL default '0',
  442. member_name varchar(255) NOT NULL default '',
  443. content_type varchar(255) NOT NULL default '',
  444. content_id int NOT NULL default '0',
  445. content_action varchar(255) NOT NULL default '',
  446. is_read int NOT NULL default '0',
  447. extra text NOT NULL,
  448. PRIMARY KEY (id_alert)
  449. );
  450. CREATE INDEX {$db_prefix}user_alerts_id_member ON {$db_prefix}user_alerts (id_member);
  451. CREATE INDEX {$db_prefix}user_alerts_alert_time ON {$db_prefix}user_alerts (alert_time);
  452. ---#
  453. ---# Adding alert preferences.
  454. CREATE TABLE {$db_prefix}user_alerts_prefs (
  455. id_member int NOT NULL default '0',
  456. alert_pref varchar(32) NOT NULL default '',
  457. alert_value smallint NOT NULL default '0',
  458. PRIMARY KEY (id_member, alert_pref)
  459. );
  460. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'member_group_request', 1);
  461. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'member_register', 1);
  462. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_like', 1);
  463. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report', 1);
  464. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report_reply', 1);
  465. ---#
  466. /******************************************************************************/
  467. --- Adding support for topic unwatch
  468. /******************************************************************************/
  469. ---# Adding new columns to log_topics...
  470. ALTER TABLE {$db_prefix}log_topics
  471. ADD COLUMN unwatched int NOT NULL DEFAULT '0';
  472. UPDATE {$db_prefix}log_topics
  473. SET unwatched = 0;
  474. INSERT INTO {$db_prefix}settings
  475. (variable, value)
  476. VALUES
  477. ('enable_unwatch', 0);
  478. ---#
  479. ---# Fixing column name change...
  480. ---{
  481. upgrade_query("
  482. ALTER TABLE {$db_prefix}log_topics
  483. RENAME disregarded TO unwatched");
  484. ---}
  485. ---#
  486. /******************************************************************************/
  487. --- Name changes
  488. /******************************************************************************/
  489. ---# Altering the membergroup stars to icons
  490. ---{
  491. upgrade_query("
  492. ALTER TABLE {$db_prefix}membergroups
  493. RENAME stars TO icons");
  494. ---}
  495. ---#
  496. ---# Renaming default theme...
  497. UPDATE {$db_prefix}themes
  498. SET value = 'SMF Default Theme - Curve2'
  499. WHERE value LIKE 'SMF Default Theme%';
  500. ---#
  501. ---# Adding the enableThemes setting.
  502. INSERT INTO {$db_prefix}settings
  503. (variable, value)
  504. VALUES
  505. ('enableThemes', '1');
  506. ---#
  507. ---# Setting "default" as the default...
  508. UPDATE {$db_prefix}settings
  509. SET value = '1'
  510. WHERE variable = 'theme_guests';
  511. UPDATE {$db_prefix}boards
  512. SET id_theme = 0;
  513. UPDATE {$db_prefix}members
  514. SET id_theme = 0;
  515. ---#
  516. /******************************************************************************/
  517. --- Cleaning up after old themes...
  518. /******************************************************************************/
  519. ---# Checking for "core" and removing it if necessary...
  520. ---{
  521. // Do they have "core" installed?
  522. if (file_exists($GLOBALS['boarddir'] . '/Themes/core'))
  523. {
  524. $core_dir = $GLOBALS['boarddir'] . '/Themes/core';
  525. $theme_request = upgrade_query("
  526. SELECT id_theme
  527. FROM {$db_prefix}themes
  528. WHERE variable = 'theme_dir'
  529. AND value ='$core_dir'");
  530. // Don't do anything if this theme is already uninstalled
  531. if ($smcFunc['db_num_rows']($theme_request) == 1)
  532. {
  533. list($id_theme) = $smcFunc['db_fetch_row']($theme_request, 0);
  534. $smcFunc['db_free_result']($theme_request);
  535. $known_themes = explode(', ', $modSettings['knownThemes']);
  536. // Remove this value...
  537. $known_themes = array_diff($known_themes, array($id_theme));
  538. // Change back to a string...
  539. $known_themes = implode(', ', $known_themes);
  540. // Update the database
  541. upgrade_query("
  542. UPDATE {$db_prefix}settings
  543. SET value = '$known_themes'
  544. WHERE variable = 'knownThemes'");
  545. // Delete any info about this theme
  546. upgrade_query("
  547. DELETE FROM {$db_prefix}themes
  548. WHERE id_theme = $id_theme");
  549. }
  550. }
  551. ---}
  552. ---#
  553. /******************************************************************************/
  554. --- Adding support for drafts
  555. /******************************************************************************/
  556. ---# Creating drafts table.
  557. CREATE SEQUENCE {$db_prefix}user_drafts_seq;
  558. CREATE TABLE {$db_prefix}user_drafts (
  559. id_draft int NOT NULL default nextval('{$db_prefix}user_drafts_seq'),
  560. id_topic int NOT NULL default '0',
  561. id_board smallint NOT NULL default '0',
  562. id_reply int NOT NULL default '0',
  563. type smallint NOT NULL default '0',
  564. poster_time int NOT NULL default '0',
  565. id_member int NOT NULL default '0',
  566. subject varchar(255) NOT NULL default '',
  567. smileys_enabled smallint NOT NULL default '1',
  568. body text NOT NULL,
  569. icon varchar(16) NOT NULL default 'xx',
  570. locked smallint NOT NULL default '0',
  571. is_sticky smallint NOT NULL default '0',
  572. to_list varchar(255) NOT NULL default '',
  573. PRIMARY KEY (id_draft)
  574. );
  575. CREATE UNIQUE INDEX {$db_prefix}user_drafts_id_member ON {$db_prefix}user_drafts (id_member, id_draft, type);
  576. ---#
  577. ---# Adding draft permissions...
  578. ---{
  579. // We cannot do this twice
  580. if (@$modSettings['smfVersion'] < '2.1')
  581. {
  582. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  583. $request = upgrade_query("
  584. SELECT id_group, id_board, add_deny, permission
  585. FROM {$db_prefix}board_permissions
  586. WHERE permission = 'post_unapproved_topics'");
  587. $inserts = array();
  588. while ($row = $smcFunc['db_fetch_assoc']($request))
  589. {
  590. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  591. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  592. }
  593. $smcFunc['db_free_result']($request);
  594. if (!empty($inserts))
  595. {
  596. foreach ($inserts AS $insert)
  597. {
  598. upgrade_query("
  599. INSERT INTO {$db_prefix}board_permissions
  600. (id_group, id_board, permission, add_deny)
  601. VALUES
  602. " . $insert);
  603. }
  604. }
  605. // Next we find people who can send PMs, and assume they can save pm_drafts as well
  606. $request = upgrade_query("
  607. SELECT id_group, add_deny, permission
  608. FROM {$db_prefix}permissions
  609. WHERE permission = 'pm_send'");
  610. $inserts = array();
  611. while ($row = $smcFunc['db_fetch_assoc']($request))
  612. {
  613. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  614. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  615. }
  616. $smcFunc['db_free_result']($request);
  617. if (!empty($inserts))
  618. {
  619. foreach ($inserts AS $insert)
  620. {
  621. upgrade_query("
  622. INSERT INTO {$db_prefix}permissions
  623. (id_group, permission, add_deny)
  624. VALUES
  625. " . $insert);
  626. }
  627. }
  628. }
  629. ---}
  630. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_autosave_enabled', '1');
  631. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_show_saved_enabled', '1');
  632. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_keep_days', '7');
  633. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_autosave_enabled', '1');
  634. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_show_saved_enabled', '1');
  635. ---#
  636. /******************************************************************************/
  637. --- Adding support for likes
  638. /******************************************************************************/
  639. ---# Creating likes table.
  640. CREATE TABLE {$db_prefix}user_likes (
  641. id_member int NOT NULL default '0',
  642. content_type char(6) default '',
  643. content_id int NOT NULL default '0',
  644. like_time int NOT NULL default '0',
  645. PRIMARY KEY (content_id, content_type, id_member)
  646. );
  647. CREATE INDEX {$db_prefix}user_likes_content ON {$db_prefix}user_likes (content_id, content_type);
  648. CREATE INDEX {$db_prefix}user_likes_liker ON {$db_prefix}user_likes (id_member);
  649. ---#
  650. ---# Adding count to the messages table.
  651. ALTER TABLE {$db_prefix}messages
  652. ADD COLUMN likes smallint NOT NULL default '0';
  653. ---#
  654. /******************************************************************************/
  655. --- Adding support for group-based board moderation
  656. /******************************************************************************/
  657. ---# Creating moderator_groups table
  658. CREATE TABLE {$db_prefix}moderator_groups (
  659. id_board smallint NOT NULL default '0',
  660. id_group smallint NOT NULL default '0',
  661. PRIMARY KEY (id_board, id_group)
  662. );
  663. ---#
  664. /******************************************************************************/
  665. --- Cleaning up integration hooks
  666. /******************************************************************************/
  667. ---#
  668. DELETE FROM {$db_prefix}settings
  669. WHERE variable LIKE 'integrate_%';
  670. ---#
  671. /******************************************************************************/
  672. --- Cleaning up old settings
  673. /******************************************************************************/
  674. ---# Updating the default time format
  675. ---{
  676. if (!empty($modSettings['time_format']))
  677. {
  678. // First, use the shortened form of the month in the date.
  679. $time_format = str_replace('%B', '%b', $modSettings['time_format']);
  680. // Second, shorten the time to stop including seconds.
  681. $time_format = str_replace(':%S', '', $time_format);
  682. // Then, update the database.
  683. $smcFunc['db_query']('', '
  684. UPDATE {db_prefix}settings
  685. SET value = {string:new_format}
  686. WHERE variable = {literal:time_format}',
  687. array(
  688. 'new_format' => $time_format,
  689. )
  690. );
  691. }
  692. ---}
  693. ---#
  694. ---# Fixing a deprecated option.
  695. UPDATE {$db_prefix}settings
  696. SET value = 'option_css_resize'
  697. WHERE variable = 'avatar_action_too_large'
  698. AND (value = 'option_html_resize' OR value = 'option_js_resize');
  699. ---#
  700. ---# Cleaning up the old Core Features page.
  701. ---{
  702. // First get the original value
  703. $request = $smcFunc['db_query']('', '
  704. SELECT value
  705. FROM {db_prefix}settings
  706. WHERE variable = {literal:admin_features}');
  707. if ($smcFunc['db_num_rows']($request) > 0 && $row = $smcFunc['db_fetch_assoc']($request))
  708. {
  709. // Some of these *should* already be set but you never know.
  710. $new_settings = array();
  711. $admin_features = explode(',', $row['value']);
  712. // Now, let's just recap something.
  713. // cd = calendar, should also have set cal_enabled already
  714. // cp = custom profile fields, which already has several fields that cover tracking
  715. // k = karma, should also have set karmaMode already
  716. // ps = paid subs, should also have set paid_enabled already
  717. // rg = reports generation, which is now permanently on
  718. // sp = spider tracking, should also have set spider_mode already
  719. // w = warning system, which will be covered with warning_settings
  720. // The rest we have to deal with manually.
  721. // Moderation log - modlog_enabled itself should be set but we have others now
  722. if (in_array('ml', $admin_features))
  723. {
  724. $new_settings[] = array('adminlog_enabled', '1');
  725. $new_settings[] = array('userlog_enabled', '1');
  726. }
  727. // Post moderation
  728. if (in_array('pm', $admin_features))
  729. {
  730. $new_settings[] = array('postmod_active', '1');
  731. }
  732. // And now actually apply it.
  733. if (!empty($new_settings))
  734. {
  735. $smcFunc['db_insert']('replace',
  736. '{db_prefix}settings',
  737. array('variable' => 'string', 'value' => 'string'),
  738. $new_settings,
  739. array('variable')
  740. );
  741. }
  742. }
  743. $smcFunc['db_free_result']($request);
  744. ---}
  745. ---#
  746. ---# Cleaning up old settings.
  747. DELETE FROM {$db_prefix}settings
  748. WHERE variable IN ('enableStickyTopics', 'guest_hideContacts', 'notify_new_registration', 'attachmentEncryptFilenames', 'hotTopicPosts', 'hotTopicVeryPosts', 'fixLongWords', 'admin_features', 'topbottomEnable', 'simpleSearch', 'enableVBStyleLogin');
  749. ---#
  750. ---# Cleaning up old theme settings.
  751. DELETE FROM {$db_prefix}themes
  752. WHERE variable IN ('show_board_desc', 'no_new_reply_warning', 'display_quick_reply', 'show_mark_read', 'show_member_bar', 'linktree_link');
  753. ---#
  754. /******************************************************************************/
  755. --- Updating files that fetched from simplemachines.org
  756. /******************************************************************************/
  757. ---# We no longer call on several files.
  758. DELETE FROM {$db_prefix}admin_info_files
  759. WHERE filename IN ('latest-packages.js', 'latest-support.js', 'latest-themes.js')
  760. AND path = '/smf/';
  761. ---#
  762. ---# But we do need new files.
  763. ---{
  764. $smcFunc['db_insert']('',
  765. '{db_prefix}admin_info_files',
  766. array('filename' => 'string', 'path' => 'string', 'parameters' => 'string', 'data' => 'string', 'filetype' => 'string'),
  767. array('latest-versions.txt', '/smf/', 'version=%3$s', '', 'text/plain'),
  768. array('id_file')
  769. );
  770. ---}
  771. ---#
  772. /******************************************************************************/
  773. --- Upgrading "verification questions" feature
  774. /******************************************************************************/
  775. ---# Creating qanda table
  776. CREATE SEQUENCE {$db_prefix}qanda_seq;
  777. CREATE TABLE {$db_prefix}qanda (
  778. id_question smallint NOT NULL default nextval('{$db_prefix}qanda_seq'),
  779. lngfile varchar(255) NOT NULL default '',
  780. question varchar(255) NOT NULL default '',
  781. answers text NOT NULL,
  782. PRIMARY KEY (id_question),
  783. KEY lngfile (lngfile)
  784. );
  785. ---#
  786. ---# Moving questions and answers to the new table
  787. ---{
  788. $questions = array();
  789. $get_questions = upgrade_query("
  790. SELECT body AS question, recipient_name AS answer
  791. FROM {$db_prefix}log_comments
  792. WHERE comment_type = 'ver_test'");
  793. while ($row = $smcFunc['db_fetch_assoc']($get_questions))
  794. $questions[] = array($language, $row['question'], serialize(array($row['answer'])));
  795. $smcFunc['db_free_result']($get_questions);
  796. if (!empty($questions))
  797. {
  798. $smcFunc['db_insert']('',
  799. '{db_prefix}qanda',
  800. array('lngfile' => 'string', 'question' => 'string', 'answers' => 'string'),
  801. $questions,
  802. array('id_question')
  803. );
  804. // Delete the questions from log_comments now
  805. upgrade_query("
  806. DELETE FROM {$db_prefix}log_comments
  807. WHERE comment_type = 'ver_test'
  808. ");
  809. }
  810. ---}
  811. ---#
  812. /******************************************************************************/
  813. --- Fixing log_online table
  814. /******************************************************************************/
  815. ---# Changing ip to bigint
  816. ALTER TABLE {$db_prefix}log_online ALTER ip TYPE bigint;
  817. ---#
  818. /******************************************************************************/
  819. --- Marking packages as uninstalled...
  820. /******************************************************************************/
  821. ---# Updating log_packages
  822. UPDATE {$db_prefix}log_packages
  823. SET install_state = 0;
  824. ---#
  825. /******************************************************************************/
  826. --- Updating profile permissions...
  827. /******************************************************************************/
  828. ---# Removing the old "view your own profile" permission
  829. DELETE FROM {$db_prefix}permissions
  830. WHERE permission = 'profile_view_own';
  831. ---#
  832. ---# Updating the old "view any profile" permission
  833. UPDATE {$db_prefix}permissions
  834. SET permission = 'profile_view'
  835. WHERE permission = 'profile_view_any';
  836. ---#
  837. ---# Removing the old notification permissions
  838. DELETE FROM {$db_prefix}board_permissions
  839. WHERE permission = 'mark_notify' OR permission = 'mark_any_notify';
  840. ---#
  841. ---# Removing the send-topic permission
  842. DELETE FROM {$db_prefix}board_permissions
  843. WHERE permission = 'send_topic';
  844. ---#
  845. ---# Adding "profile_password_own"
  846. ---{
  847. $inserts = array();
  848. $request = upgrade_query("
  849. SELECT id_group, add_deny
  850. FROM {$db_prefix}permissions
  851. WHERE permission = 'profile_identity_own'");
  852. while ($row = $smcFunc['db_fetch_assoc']($request))
  853. {
  854. $inserts[] = "($row[id_group], 'profile_password_own', $row[add_deny])";
  855. }
  856. $smcFunc['db_free_result']($request);
  857. if (!empty($inserts))
  858. {
  859. foreach ($inserts as $insert)
  860. {
  861. upgrade_query("
  862. INSERT INTO {$db_prefix}permissions
  863. (id_group, permission, add_deny)
  864. VALUES
  865. " . $insert);
  866. }
  867. }
  868. ---}
  869. ---#
  870. ---# Adding other profile permissions
  871. ---{
  872. $inserts = array();
  873. $request = upgrade_query("
  874. SELECT id_group, add_deny
  875. FROM {$db_prefix}permissions
  876. WHERE permission = 'profile_extra_own'");
  877. while ($row = $smcFunc['db_fetch_assoc']($request))
  878. {
  879. $inserts[] = "($row[id_group], 'profile_blurb_own', $row[add_deny])";
  880. $inserts[] = "($row[id_group], 'profile_displayed_name_own', $row[add_deny])";
  881. $inserts[] = "($row[id_group], 'profile_forum_own', $row[add_deny])";
  882. $inserts[] = "($row[id_group], 'profile_other_own', $row[add_deny])";
  883. $inserts[] = "($row[id_group], 'profile_signature_own', $row[add_deny])";
  884. }
  885. $smcFunc['db_free_result']($request);
  886. if (!empty($inserts))
  887. {
  888. foreach ($inserts as $insert)
  889. {
  890. upgrade_query("
  891. INSERT INTO {$db_prefix}permissions
  892. (id_group, permission, add_deny)
  893. VALUES
  894. " . $insert
  895. );
  896. }
  897. }
  898. ---}
  899. ---#
  900. /******************************************************************************/
  901. --- Upgrading PM labels...
  902. /******************************************************************************/
  903. ---# Creating pm_labels sequence...
  904. CREATE SEQUENCE {$db_prefix}pm_labels_seq;
  905. ---#
  906. ---# Adding pm_labels table...
  907. CREATE TABLE {$db_prefix}pm_labels (
  908. id_label int NOT NULL default nextval('{$db_prefix}pm_labels_seq'),
  909. id_member int NOT NULL default '0',
  910. name varchar(30) NOT NULL default '',
  911. PRIMARY KEY (id_label)
  912. );
  913. ---#
  914. ---# Adding pm_labeled_messages table...
  915. CREATE TABLE {$db_prefix}pm_labeled_messages (
  916. id_label int NOT NULL default '0',
  917. id_pm int NOT NULL default '0',
  918. PRIMARY KEY (id_label, id_pm)
  919. );
  920. ---#
  921. ---# Adding "in_inbox" column to pm_recipients
  922. ALTER TABLE {$db_prefix}pm_recipients
  923. ADD COLUMN in_inbox smallint NOT NULL default '1';
  924. ---#
  925. ---# Moving label info to new tables and updating rules...
  926. ---{
  927. // First see if we still have a message_labels column
  928. $results = $smcFunc['db_list_columns']('{db_prefix}members', false);
  929. if (in_array('message_labels', $results))
  930. {
  931. // They've still got it, so pull the label info
  932. $get_labels = $smcFunc['db_query']('', '
  933. SELECT id_member, message_labels
  934. FROM {db_prefix}members
  935. WHERE message_labels != {string:blank}',
  936. array(
  937. 'blank' => '',
  938. )
  939. );
  940. $inserts = array();
  941. $label_info = array();
  942. while ($row = $smcFunc['db_fetch_assoc']($get_labels))
  943. {
  944. // Stick this in an array
  945. $labels = explode(',', $row['message_labels']);
  946. // Build some inserts
  947. foreach ($labels AS $index => $label)
  948. {
  949. // Keep track of the index of this label - we'll need that in a bit...
  950. $label_info[$row['id_member']][$label] = $index;
  951. $inserts[] = array($row['id_member'], $label);
  952. }
  953. }
  954. $smcFunc['db_free_result']($get_labels);
  955. if (!empty($inserts))
  956. {
  957. $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
  958. // Clear this out for our next query below
  959. $inserts = array();
  960. }
  961. // This is the easy part - update the inbox stuff
  962. $smcFunc['db_query']('', '
  963. UPDATE {db_prefix}pm_recipients
  964. SET in_inbox = {int:in_inbox}
  965. WHERE FIND_IN_SET({int:minus_one}, labels) != 0',
  966. array(
  967. 'in_inbox' => 1,
  968. 'minus_one' => -1,
  969. )
  970. );
  971. // Now we go pull the new IDs for each label
  972. $get_new_label_ids = $smcFunc['db_query']('', '
  973. SELECT *
  974. FROM {db_prefix}pm_labels',
  975. array(
  976. )
  977. );
  978. $label_info_2 = array();
  979. while ($label_row = $smcFunc['db_fetch_assoc']($get_new_label_ids))
  980. {
  981. // Map the old index values to the new ID values...
  982. $old_index = $label_info[$row['id_member']][$row['label_name']];
  983. $label_info_2[$row['id_member']][$old_index] = $row['id_label'];
  984. }
  985. $smcFunc['db_free_result']($get_new_label_ids);
  986. // Pull label info from pm_recipients
  987. // Ignore any that are only in the inbox
  988. $get_pm_labels = $smcFunc['db_query']('', '
  989. SELECT id_pm, id_member, labels
  990. FROM {db_prefix}pm_recipients
  991. WHERE deleted = {int:not_deleted}
  992. AND labels != {string:minus_one}',
  993. array(
  994. 'not_deleted' => 0,
  995. 'minus_one' => -1,
  996. )
  997. );
  998. while ($row = $smcFunc['db_fetch_assoc']($get_pm_labels))
  999. {
  1000. $labels = explode(',', $row['labels']);
  1001. foreach ($labels as $a_label)
  1002. {
  1003. if ($a_label == '-1')
  1004. continue;
  1005. $new_label_info = $label_info_2[$row['id_member']][$a_label];
  1006. $inserts[] = array($row['id_pm'], $new_label_info);
  1007. }
  1008. }
  1009. $smcFunc['db_free_result']($get_pm_labels);
  1010. // Insert the new data
  1011. if (!empty($inserts))
  1012. {
  1013. $smcFunc['db_insert']('', '{db_prefix}pm_labeled_messages', array('id_pm' => 'int', 'id_label' => 'int'), $inserts, array());
  1014. }
  1015. // Final step of this ridiculously massive process
  1016. $get_pm_rules = $smcFunc['db_query']('', '
  1017. SELECT id_member, id_rule, actions
  1018. FROM {db_prefix}pm_rules',
  1019. array(
  1020. )
  1021. );
  1022. // Go through the rules, unserialize the actions, then figure out if there's anything we can use
  1023. while ($row = $smcFunc['db_fetch_assoc']($get_pm_rules))
  1024. {
  1025. // Turn this into an array...
  1026. $actions = unserialize($row['actions']);
  1027. // Loop through the actions and see if we're applying a label anywhere
  1028. foreach ($actions as $index => $action)
  1029. {
  1030. if ($action['t'] == 'lab')
  1031. {
  1032. // Update the value of this label...
  1033. $actions[$index]['v'] = $label_info_2[$row['id_member']][$action['v']];
  1034. }
  1035. }
  1036. // Put this back into a string
  1037. $actions = serialize($actions);
  1038. $smcFunc['db_query']('', '
  1039. UPDATE {db_prefix}pm_rules
  1040. SET actions = {string:actions}
  1041. WHERE id_rule = {int:id_rule}',
  1042. array(
  1043. 'actions' => $actions,
  1044. 'id_rule' => $row['id_rule'],
  1045. )
  1046. );
  1047. }
  1048. $smcFunc['db_free_result']($get_pm_rules);
  1049. // Lastly, we drop the old columns
  1050. $smcFunc['db_remove_column']('{db_prefix}members', 'message_labels');
  1051. $smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
  1052. }
  1053. ---}
  1054. ---#
  1055. /******************************************************************************/
  1056. --- Adding support for edit reasons
  1057. /******************************************************************************/
  1058. ---# Adding "modified_reason" column to messages
  1059. ALTER TABLE {$db_prefix}messages
  1060. ADD COLUMN modified_reason varchar(255) NOT NULL default '';
  1061. ---#
  1062. /******************************************************************************/
  1063. --- Cleaning up guest permissions
  1064. /******************************************************************************/
  1065. ---# Removing permissions guests can no longer have...
  1066. ---{
  1067. $illegal_board_permissions = array(
  1068. 'announce_topic',
  1069. 'delete_any',
  1070. 'lock_any',
  1071. 'make_sticky',
  1072. 'merge_any',
  1073. 'modify_any',
  1074. 'modify_replies',
  1075. 'move_any',
  1076. 'poll_add_any',
  1077. 'poll_edit_any',
  1078. 'poll_lock_any',
  1079. 'poll_remove_any',
  1080. 'remove_any',
  1081. 'report_any',
  1082. 'split_any'
  1083. );
  1084. $illegal_permissions = array('calendar_edit_any', 'moderate_board', 'moderate_forum', 'send_email_to_members');
  1085. $smcFunc['db_query']('', '
  1086. DELETE FROM {db_prefix}board_permissions
  1087. WHERE id_group = {int:guests}
  1088. AND permission IN ({array_string:illegal_board_perms})',
  1089. array(
  1090. 'guests' => -1,
  1091. 'illegal_board_perms' => $illegal_board_permissions,
  1092. )
  1093. );
  1094. $smcFunc['db_query']('', '
  1095. DELETE FROM {db_prefix}permissions
  1096. WHERE id_group = {int:guests}
  1097. AND permission IN ({array_string:illegal_perms})',
  1098. array(
  1099. 'guests' => -1,
  1100. 'illegal_perms' => $illegal_permissions,
  1101. )
  1102. );
  1103. ---}
  1104. ---#
  1105. /******************************************************************************/
  1106. --- Adding mail queue settings
  1107. /******************************************************************************/
  1108. ---#
  1109. ---{
  1110. if (empty($modSettings['mail_limit']))
  1111. {
  1112. $smcFunc['db_insert']('replace',
  1113. '{db_prefix}settings',
  1114. array('variable' => 'string-255', 'value' => 'string'),
  1115. array(
  1116. array('mail_limit', '5'),
  1117. array('mail_quantity', '5'),
  1118. ),
  1119. array('variable')
  1120. );
  1121. }
  1122. ---}
  1123. ---#