upgrade_2-1_postgresql.sql 43 KB

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