upgrade_2-1_postgresql.sql 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  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. ---{
  471. upgrade_query("
  472. ALTER TABLE {$db_prefix}log_topics
  473. ADD COLUMN unwatched int NOT NULL DEFAULT '0'");
  474. UPDATE {$db_prefix}log_topics
  475. SET unwatched = 0;
  476. INSERT INTO {$db_prefix}settings
  477. (variable, value)
  478. VALUES
  479. ('enable_unwatch', 0);
  480. ---}
  481. ---#
  482. ---# Fixing column name change...
  483. ---{
  484. upgrade_query("
  485. ALTER TABLE {$db_prefix}log_topics
  486. RENAME disregarded TO unwatched");
  487. ---}
  488. ---#
  489. /******************************************************************************/
  490. --- Name changes
  491. /******************************************************************************/
  492. ---# Altering the membergroup stars to icons
  493. ---{
  494. upgrade_query("
  495. ALTER TABLE {$db_prefix}membergroups
  496. RENAME stars TO icons");
  497. ---}
  498. ---#
  499. ---# Renaming default theme...
  500. UPDATE {$db_prefix}themes
  501. SET value = 'SMF Default Theme - Curve2'
  502. WHERE value LIKE 'SMF Default Theme%';
  503. ---#
  504. ---# Adding the enableThemes setting.
  505. INSERT INTO {$db_prefix}settings
  506. (variable, value)
  507. VALUES
  508. ('enableThemes', '1');
  509. ---#
  510. ---# Setting "default" as the default...
  511. UPDATE {$db_prefix}settings
  512. SET value = '1'
  513. WHERE variable = 'theme_guests';
  514. UPDATE {$db_prefix}boards
  515. SET id_theme = 0;
  516. UPDATE {$db_prefix}members
  517. SET id_theme = 0;
  518. ---#
  519. /******************************************************************************/
  520. --- Cleaning up after old themes...
  521. /******************************************************************************/
  522. ---# Checking for "core" and removing it if necessary...
  523. ---{
  524. // Do they have "core" installed?
  525. if (file_exists($GLOBALS['boarddir'] . '/Themes/core'))
  526. {
  527. $core_dir = $GLOBALS['boarddir'] . '/Themes/core';
  528. $theme_request = upgrade_query("
  529. SELECT id_theme
  530. FROM {$db_prefix}themes
  531. WHERE variable = 'theme_dir'
  532. AND value ='$core_dir'");
  533. // Don't do anything if this theme is already uninstalled
  534. if ($smcFunc['db_num_rows']($theme_request) == 1)
  535. {
  536. list($id_theme) = $smcFunc['db_fetch_row']($theme_request, 0);
  537. $smcFunc['db_free_result']($theme_request);
  538. $known_themes = explode(', ', $modSettings['knownThemes']);
  539. // Remove this value...
  540. $known_themes = array_diff($known_themes, array($id_theme));
  541. // Change back to a string...
  542. $known_themes = implode(', ', $known_themes);
  543. // Update the database
  544. upgrade_query("
  545. UPDATE {$db_prefix}settings
  546. SET value = '$known_themes'
  547. WHERE variable = 'knownThemes'");
  548. // Delete any info about this theme
  549. upgrade_query("
  550. DELETE FROM {$db_prefix}themes
  551. WHERE id_theme = $id_theme");
  552. }
  553. }
  554. ---}
  555. ---#
  556. /******************************************************************************/
  557. --- Adding support for drafts
  558. /******************************************************************************/
  559. ---# Creating drafts table.
  560. CREATE SEQUENCE {$db_prefix}user_drafts_seq;
  561. CREATE TABLE {$db_prefix}user_drafts (
  562. id_draft int NOT NULL default nextval('{$db_prefix}user_drafts_seq'),
  563. id_topic int NOT NULL default '0',
  564. id_board smallint NOT NULL default '0',
  565. id_reply int NOT NULL default '0',
  566. type smallint NOT NULL default '0',
  567. poster_time int NOT NULL default '0',
  568. id_member int NOT NULL default '0',
  569. subject varchar(255) NOT NULL default '',
  570. smileys_enabled smallint NOT NULL default '1',
  571. body text NOT NULL,
  572. icon varchar(16) NOT NULL default 'xx',
  573. locked smallint NOT NULL default '0',
  574. is_sticky smallint NOT NULL default '0',
  575. to_list varchar(255) NOT NULL default '',
  576. PRIMARY KEY (id_draft)
  577. );
  578. CREATE UNIQUE INDEX {$db_prefix}user_drafts_id_member ON {$db_prefix}user_drafts (id_member, id_draft, type);
  579. ---#
  580. ---# Adding draft permissions...
  581. ---{
  582. // We cannot do this twice
  583. if (@$modSettings['smfVersion'] < '2.1')
  584. {
  585. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  586. $request = upgrade_query("
  587. SELECT id_group, id_board, add_deny, permission
  588. FROM {$db_prefix}board_permissions
  589. WHERE permission = 'post_unapproved_topics'");
  590. $inserts = array();
  591. while ($row = $smcFunc['db_fetch_assoc']($request))
  592. {
  593. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  594. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  595. }
  596. $smcFunc['db_free_result']($request);
  597. if (!empty($inserts))
  598. {
  599. foreach ($inserts AS $insert)
  600. {
  601. upgrade_query("
  602. INSERT INTO {$db_prefix}board_permissions
  603. (id_group, id_board, permission, add_deny)
  604. VALUES
  605. " . $insert);
  606. }
  607. }
  608. // Next we find people who can send PMs, and assume they can save pm_drafts as well
  609. $request = upgrade_query("
  610. SELECT id_group, add_deny, permission
  611. FROM {$db_prefix}permissions
  612. WHERE permission = 'pm_send'");
  613. $inserts = array();
  614. while ($row = $smcFunc['db_fetch_assoc']($request))
  615. {
  616. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  617. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  618. }
  619. $smcFunc['db_free_result']($request);
  620. if (!empty($inserts))
  621. {
  622. foreach ($inserts AS $insert)
  623. {
  624. upgrade_query("
  625. INSERT INTO {$db_prefix}permissions
  626. (id_group, permission, add_deny)
  627. VALUES
  628. " . $insert);
  629. }
  630. }
  631. }
  632. ---}
  633. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_autosave_enabled', '1');
  634. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_show_saved_enabled', '1');
  635. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_keep_days', '7');
  636. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_autosave_enabled', '1');
  637. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_show_saved_enabled', '1');
  638. ---#
  639. /******************************************************************************/
  640. --- Adding support for likes
  641. /******************************************************************************/
  642. ---# Creating likes table.
  643. CREATE TABLE {$db_prefix}user_likes (
  644. id_member int NOT NULL default '0',
  645. content_type char(6) default '',
  646. content_id int NOT NULL default '0',
  647. like_time int NOT NULL default '0',
  648. PRIMARY KEY (content_id, content_type, id_member)
  649. );
  650. CREATE INDEX {$db_prefix}user_likes_content ON {$db_prefix}user_likes (content_id, content_type);
  651. CREATE INDEX {$db_prefix}user_likes_liker ON {$db_prefix}user_likes (id_member);
  652. ---#
  653. ---# Adding count to the messages table.
  654. ALTER TABLE {$db_prefix}messages
  655. ADD COLUMN likes smallint NOT NULL default '0';
  656. ---#
  657. /******************************************************************************/
  658. --- Adding support for group-based board moderation
  659. /******************************************************************************/
  660. ---# Creating moderator_groups table
  661. CREATE TABLE {$db_prefix}moderator_groups (
  662. id_board smallint NOT NULL default '0',
  663. id_group smallint NOT NULL default '0',
  664. PRIMARY KEY (id_board, id_group)
  665. );
  666. ---#
  667. /******************************************************************************/
  668. --- Cleaning up integration hooks
  669. /******************************************************************************/
  670. ---#
  671. DELETE FROM {$db_prefix}settings
  672. WHERE variable LIKE 'integrate_%';
  673. ---#
  674. /******************************************************************************/
  675. --- Cleaning up old settings
  676. /******************************************************************************/
  677. ---# Updating the default time format
  678. ---{
  679. if (!empty($modSettings['time_format']))
  680. {
  681. // First, use the shortened form of the month in the date.
  682. $time_format = str_replace('%B', '%b', $modSettings['time_format']);
  683. // Second, shorten the time to stop including seconds.
  684. $time_format = str_replace(':%S', '', $time_format);
  685. // Then, update the database.
  686. $smcFunc['db_query']('', '
  687. UPDATE {db_prefix}settings
  688. SET value = {string:new_format}
  689. WHERE variable = {literal:time_format}',
  690. array(
  691. 'new_format' => $time_format,
  692. )
  693. );
  694. }
  695. ---}
  696. ---#
  697. ---# Fixing a deprecated option.
  698. UPDATE {$db_prefix}settings
  699. SET value = 'option_css_resize'
  700. WHERE variable = 'avatar_action_too_large'
  701. AND (value = 'option_html_resize' OR value = 'option_js_resize');
  702. ---#
  703. ---# Cleaning up the old Core Features page.
  704. ---{
  705. // First get the original value
  706. $request = $smcFunc['db_query']('', '
  707. SELECT value
  708. FROM {db_prefix}settings
  709. WHERE variable = {literal:admin_features}');
  710. if ($smcFunc['db_num_rows']($request) > 0 && $row = $smcFunc['db_fetch_assoc']($request))
  711. {
  712. // Some of these *should* already be set but you never know.
  713. $new_settings = array();
  714. $admin_features = explode(',', $row['value']);
  715. // Now, let's just recap something.
  716. // cd = calendar, should also have set cal_enabled already
  717. // cp = custom profile fields, which already has several fields that cover tracking
  718. // k = karma, should also have set karmaMode already
  719. // ps = paid subs, should also have set paid_enabled already
  720. // rg = reports generation, which is now permanently on
  721. // sp = spider tracking, should also have set spider_mode already
  722. // w = warning system, which will be covered with warning_settings
  723. // The rest we have to deal with manually.
  724. // Moderation log - modlog_enabled itself should be set but we have others now
  725. if (in_array('ml', $admin_features))
  726. {
  727. $new_settings[] = array('adminlog_enabled', '1');
  728. $new_settings[] = array('userlog_enabled', '1');
  729. }
  730. // Post moderation
  731. if (in_array('pm', $admin_features))
  732. {
  733. $new_settings[] = array('postmod_active', '1');
  734. }
  735. // And now actually apply it.
  736. if (!empty($new_settings))
  737. {
  738. $smcFunc['db_insert']('replace',
  739. '{db_prefix}settings',
  740. array('variable' => 'string', 'value' => 'string'),
  741. $new_settings,
  742. array('variable')
  743. );
  744. }
  745. }
  746. $smcFunc['db_free_result']($request);
  747. ---}
  748. ---#
  749. ---# Cleaning up old settings.
  750. DELETE FROM {$db_prefix}settings
  751. WHERE variable IN ('enableStickyTopics', 'guest_hideContacts', 'notify_new_registration', 'attachmentEncryptFilenames', 'hotTopicPosts', 'hotTopicVeryPosts', 'fixLongWords', 'admin_features', 'topbottomEnable', 'simpleSearch');
  752. ---#
  753. ---# Cleaning up old theme settings.
  754. DELETE FROM {$db_prefix}themes
  755. WHERE variable IN ('show_board_desc', 'no_new_reply_warning', 'display_quick_reply', 'show_mark_read', 'show_member_bar', 'linktree_link');
  756. ---#
  757. /******************************************************************************/
  758. --- Updating files that fetched from simplemachines.org
  759. /******************************************************************************/
  760. ---# We no longer call on several files.
  761. DELETE FROM {$db_prefix}admin_info_files
  762. WHERE filename IN ('latest-packages.js', 'latest-support.js', 'latest-themes.js')
  763. AND path = '/smf/';
  764. ---#
  765. ---# But we do need new files.
  766. ---{
  767. $smcFunc['db_insert']('',
  768. '{db_prefix}admin_info_files',
  769. array('filename' => 'string', 'path' => 'string', 'parameters' => 'string', 'data' => 'string', 'filetype' => 'string'),
  770. array('latest-versions.txt', '/smf/', 'version=%3$s', '', 'text/plain'),
  771. array('id_file')
  772. );
  773. ---}
  774. ---#
  775. /******************************************************************************/
  776. --- Upgrading "verification questions" feature
  777. /******************************************************************************/
  778. ---# Creating qanda table
  779. CREATE SEQUENCE {$db_prefix}qanda_seq;
  780. CREATE TABLE {$db_prefix}qanda (
  781. id_question smallint NOT NULL default nextval('{$db_prefix}qanda_seq'),
  782. lngfile varchar(255) NOT NULL default '',
  783. question varchar(255) NOT NULL default '',
  784. answers text NOT NULL,
  785. PRIMARY KEY (id_question),
  786. KEY lngfile (lngfile)
  787. );
  788. ---#
  789. ---# Moving questions and answers to the new table
  790. ---{
  791. $questions = array();
  792. $get_questions = upgrade_query("
  793. SELECT body AS question, recipient_name AS answer
  794. FROM {$db_prefix}log_comments
  795. WHERE comment_type = 'ver_test'");
  796. while ($row = $smcFunc['db_fetch_assoc']($get_questions))
  797. $questions[] = array($language, $row['question'], serialize(array($row['answer'])));
  798. $smcFunc['db_free_result']($get_questions);
  799. if (!empty($questions))
  800. {
  801. $smcFunc['db_insert']('',
  802. '{db_prefix}qanda',
  803. array('lngfile' => 'string', 'question' => 'string', 'answers' => 'string'),
  804. $questions,
  805. array('id_question')
  806. );
  807. // Delete the questions from log_comments now
  808. upgrade_query("
  809. DELETE FROM {$db_prefix}log_comments
  810. WHERE comment_type = 'ver_test'
  811. ");
  812. }
  813. ---}
  814. ---#
  815. /******************************************************************************/
  816. --- Fixing log_online table
  817. /******************************************************************************/
  818. ---# Changing ip to bigint
  819. ALTER TABLE {$db_prefix}log_online ALTER ip TYPE bigint;
  820. ---#
  821. /******************************************************************************/
  822. --- Marking packages as uninstalled...
  823. /******************************************************************************/
  824. ---# Updating log_packages
  825. UPDATE {$db_prefix}log_packages
  826. SET install_state = 0;
  827. ---#
  828. /******************************************************************************/
  829. --- Updating profile permissions...
  830. /******************************************************************************/
  831. ---# Removing the old "view your own profile" permission
  832. DELETE FROM {$db_prefix}permissions
  833. WHERE permission = 'profile_view_own';
  834. ---#
  835. ---# Updating the old "view any profile" permission
  836. UPDATE {$db_prefix}permissions
  837. SET permission = 'profile_view'
  838. WHERE permission = 'profile_view_any';
  839. ---#
  840. ---# Removing the old notification permissions
  841. DELETE FROM {$db_prefix}board_permissions
  842. WHERE permission = 'mark_notify' OR permission = 'mark_any_notify';
  843. ---#
  844. ---# Removing the send-topic permission
  845. DELETE FROM {$db_prefix}board_permissions
  846. WHERE permission = 'send_topic';
  847. ---#
  848. ---# Adding "profile_password_own"
  849. ---{
  850. $inserts = array();
  851. $request = upgrade_query("
  852. SELECT id_group, add_deny
  853. FROM {$db_prefix}permissions
  854. WHERE permission = 'profile_identity_own'");
  855. while ($row = $smcFunc['db_fetch_assoc']($request))
  856. {
  857. $inserts[] = "($row[id_group], 'profile_password_own', $row[add_deny])";
  858. }
  859. $smcFunc['db_free_result']($request);
  860. if (!empty($inserts))
  861. {
  862. foreach ($inserts as $insert)
  863. {
  864. upgrade_query("
  865. INSERT INTO {$db_prefix}permissions
  866. (id_group, permission, add_deny)
  867. VALUES
  868. " . $insert);
  869. }
  870. }
  871. ---}
  872. ---#
  873. ---# Adding other profile permissions
  874. ---{
  875. $inserts = array();
  876. $request = upgrade_query("
  877. SELECT id_group, add_deny
  878. FROM {$db_prefix}permissions
  879. WHERE permission = 'profile_extra_own'");
  880. while ($row = $smcFunc['db_fetch_assoc']($request))
  881. {
  882. $inserts[] = "($row[id_group], 'profile_blurb_own', $row[add_deny])";
  883. $inserts[] = "($row[id_group], 'profile_displayed_name_own', $row[add_deny])";
  884. $inserts[] = "($row[id_group], 'profile_forum_own', $row[add_deny])";
  885. $inserts[] = "($row[id_group], 'profile_other_own', $row[add_deny])";
  886. $inserts[] = "($row[id_group], 'profile_signature_own', $row[add_deny])";
  887. }
  888. $smcFunc['db_free_result']($request);
  889. if (!empty($inserts))
  890. {
  891. foreach ($inserts as $insert)
  892. {
  893. upgrade_query("
  894. INSERT INTO {$db_prefix}permissions
  895. (id_group, permission, add_deny)
  896. VALUES
  897. " . $insert
  898. );
  899. }
  900. }
  901. ---}
  902. ---#
  903. /******************************************************************************/
  904. --- Upgrading PM labels...
  905. /******************************************************************************/
  906. ---# Creating pm_labels sequence...
  907. CREATE SEQUENCE {$db_prefix}pm_labels_sequence;
  908. ---#
  909. ---# Adding pm_labels table...
  910. CREATE TABLE {$db_prefix}pm_labels (
  911. id_label int NOT NULL default nextval('{$db_prefix}pm_labels_seq'),
  912. id_member int NOT NULL default '0',
  913. name varchar(30) NOT NULL default '',
  914. PRIMARY KEY (id_label)
  915. );
  916. ---#
  917. ---# Adding pm_labeled_messages table...
  918. CREATE TABLE {$db_prefix}pm_labeled_messages (
  919. id_label int NOT NULL default '0',
  920. id_pm int NOT NULL default '0',
  921. PRIMARY KEY (id_label, id_pm)
  922. );
  923. ---#
  924. ---# Adding "in_inbox" column to pm_recipients
  925. ALTER TABLE {$db_prefix}pm_recipients
  926. ADD COLUMN in_inbox smallint NOT NULL default '1';
  927. ---#
  928. ---# Moving label info to new tables and updating rules...
  929. ---{
  930. // First see if we still have a message_labels column
  931. $results = $smcFunc['db_list_columns']('{db_prefix}members', false);
  932. if (in_array('message_labels', $results))
  933. {
  934. // They've still got it, so pull the label info
  935. $get_labels = $smcFunc['db_query']('', '
  936. SELECT id_member, message_labels
  937. FROM {db_prefix}members
  938. WHERE message_labels != {string:blank}',
  939. array(
  940. 'blank' => '',
  941. )
  942. );
  943. $inserts = array();
  944. $label_info = array();
  945. while ($row = $smcFunc['db_fetch_assoc']($get_labels))
  946. {
  947. // Stick this in an array
  948. $labels = explode(',', $row['message_labels']);
  949. // Build some inserts
  950. foreach ($labels AS $index => $label)
  951. {
  952. // Keep track of the index of this label - we'll need that in a bit...
  953. $label_info[$row['id_member']][$label] = $index;
  954. $inserts[] = array($row['id_member'], $label);
  955. }
  956. }
  957. $smcFunc['db_free_result']($get_labels);
  958. if (!empty($inserts))
  959. {
  960. $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
  961. // Clear this out for our next query below
  962. $inserts = array();
  963. }
  964. // This is the easy part - update the inbox stuff
  965. $smcFunc['db_query']('', '
  966. UPDATE {db_prefix}pm_recipients
  967. SET in_inbox = {int:in_inbox}
  968. WHERE FIND_IN_SET({int:minus_one}, labels)',
  969. array(
  970. 'in_inbox' => 1,
  971. 'minus_one' => -1,
  972. )
  973. );
  974. // Now we go pull the new IDs for each label
  975. $get_new_label_ids = $smcFunc['db_query']('', '
  976. SELECT *
  977. FROM {db_prefix}pm_labels',
  978. array(
  979. )
  980. );
  981. $label_info_2 = array();
  982. while ($label_row = $smcFunc['db_fetch_assoc']($get_new_label_ids))
  983. {
  984. // Map the old index values to the new ID values...
  985. $old_index = $label_info[$row['id_member']][$row['label_name']];
  986. $label_info_2[$row['id_member']][$old_index] = $row['id_label'];
  987. }
  988. $smcFunc['db_free_result']($get_new_label_ids);
  989. // Pull label info from pm_recipients
  990. // Ignore any that are only in the inbox
  991. $get_pm_labels = $smcFunc['db_query']('', '
  992. SELECT id_pm, id_member, labels
  993. FROM {db_prefix}pm_recipients
  994. WHERE deleted = {int:not_deleted}
  995. AND labels != {string:minus_one}',
  996. array(
  997. 'not_deleted' => 0,
  998. 'minus_one' => -1,
  999. )
  1000. );
  1001. while ($row = $smcFunc['db_fetch_assoc']($get_pm_labels))
  1002. {
  1003. $labels = explode(',', $row['labels']);
  1004. foreach ($labels as $a_label)
  1005. {
  1006. if ($a_label == '-1')
  1007. continue;
  1008. $new_label_info = $label_info_2[$row['id_member']][$a_label];
  1009. $inserts[] = array($row['id_pm'], $new_label_info);
  1010. }
  1011. }
  1012. $smcFunc['db_free_result']($get_pm_labels);
  1013. // Insert the new data
  1014. if (!empty($inserts))
  1015. {
  1016. $smcFunc['db_insert']('', '{db_prefix}pm_labeled_messages', array('id_pm' => 'int', 'id_label' => 'int'), $inserts, array());
  1017. }
  1018. // Final step of this ridiculously massive process
  1019. $get_pm_rules = $smcFunc['db_query']('', '
  1020. SELECT id_member, id_rule, actions
  1021. FROM {db_prefix}pm_rules',
  1022. array(
  1023. ),
  1024. );
  1025. // Go through the rules, unserialize the actions, then figure out if there's anything we can use
  1026. while ($row = $smcFunc['db_fetch_assoc']($get_pm_rules))
  1027. {
  1028. // Turn this into an array...
  1029. $actions = unserialize($row['actions']);
  1030. // Loop through the actions and see if we're applying a label anywhere
  1031. foreach ($actions as $index => $action)
  1032. {
  1033. if ($action['t'] == 'lab')
  1034. {
  1035. // Update the value of this label...
  1036. $actions[$index]['v'] = $label_info_2[$row['id_member']][$action['v']];
  1037. }
  1038. }
  1039. // Put this back into a string
  1040. $actions = serialize($actions);
  1041. $smcFunc['db_query']('', '
  1042. UPDATE {db_prefix}pm_rules
  1043. SET actions = {string:actions}
  1044. WHERE id_rule = {int:id_rule}',
  1045. array(
  1046. 'actions' => $actions,
  1047. 'id_rule' => $row['id_rule'],
  1048. )
  1049. );
  1050. }
  1051. $smcFunc['db_free_result']($get_pm_rules);
  1052. // Lastly, we drop the old columns
  1053. $smcFunc['db_remove_column']('{db_prefix}members', 'message_labels');
  1054. $smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
  1055. }
  1056. }
  1057. /******************************************************************************/
  1058. --- Adding support for edit reasons
  1059. /******************************************************************************/
  1060. ---# Adding "modified_reason" column to messages
  1061. ALTER TABLE {$db_prefix}messages
  1062. ADD COLUMN modified_reason varchar(255) NOT NULL default '';
  1063. ---#
  1064. /******************************************************************************/
  1065. --- Cleaning up guest permissions
  1066. /******************************************************************************/
  1067. ---# Removing permissions guests can no longer have...
  1068. ---{
  1069. $illegal_board_permissions = array(
  1070. 'announce_topic',
  1071. 'delete_any',
  1072. 'lock_any',
  1073. 'make_sticky',
  1074. 'merge_any',
  1075. 'modify_any',
  1076. 'modify_replies',
  1077. 'move_any',
  1078. 'poll_add_any',
  1079. 'poll_edit_any',
  1080. 'poll_lock_any',
  1081. 'poll_remove_any',
  1082. 'remove_any',
  1083. 'report_any',
  1084. 'split_any'
  1085. );
  1086. $illegal_permissions = array('calendar_edit_any', 'moderate_board', 'moderate_forum', 'send_email_to_members');
  1087. $smcFunc['db_query']('', '
  1088. DELETE FROM {db_prefix}board_permissions
  1089. WHERE id_group = {int:guests}
  1090. AND permission IN ({array_string:illegal_board_perms})',
  1091. array(
  1092. 'guests' => -1,
  1093. 'illegal_board_perms' => $illegal_board_permissions,
  1094. )
  1095. );
  1096. $smcFunc['db_query']('', '
  1097. DELETE FROM {db_prefix}permissions
  1098. WHERE id_group = {int:guests}
  1099. AND permission IN ({array_string:illegal_perms})',
  1100. array(
  1101. 'guests' => -1,
  1102. 'illegal_perms' => $illegal_permissions,
  1103. )
  1104. );
  1105. ---}
  1106. ---#
  1107. /******************************************************************************/
  1108. --- Adding mail queue settings
  1109. /******************************************************************************/
  1110. ---#
  1111. ---{
  1112. if (empty($modSettings['mail_limit']))
  1113. {
  1114. $smcFunc['db_insert']('replace',
  1115. '{db_prefix}settings',
  1116. array('variable' => 'string-255', 'value' => 'string'),
  1117. array(
  1118. array('mail_limit', '5'),
  1119. array('mail_quantity', '5'),
  1120. ),
  1121. array('variable')
  1122. );
  1123. }
  1124. ---}
  1125. ---#