upgrade_2-1_mysql.sql 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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. ---# Adding login history...
  6. CREATE TABLE IF NOT EXISTS {$db_prefix}member_logins (
  7. id_login int(10) NOT NULL auto_increment,
  8. id_member mediumint(8) NOT NULL,
  9. time int(10) NOT NULL,
  10. ip varchar(255) NOT NULL default '',
  11. ip2 varchar(255) NOT NULL default '',
  12. PRIMARY KEY id_login(id_login),
  13. KEY id_member (id_member),
  14. KEY time (time)
  15. ) ENGINE=MyISAM{$db_collation};
  16. ---#
  17. ---# Copying the current package backup setting...
  18. ---{
  19. if (!isset($modSettings['package_make_full_backups']) && isset($modSettings['package_make_backups']))
  20. upgrade_query("
  21. INSERT INTO {$db_prefix}settings
  22. (variable, value)
  23. VALUES
  24. ('package_make_full_backups', '" . $modSettings['package_make_backups'] . "')");
  25. ---}
  26. ---#
  27. ---# Copying the current "allow users to disable word censor" setting...
  28. ---{
  29. if (!isset($modSettings['allow_no_censored']))
  30. {
  31. $request = upgrade_query("
  32. SELECT value
  33. FROM {$db_prefix}themes
  34. WHERE variable='allow_no_censored'
  35. AND id_theme = 1 OR id_theme = '$modSettings[theme_default]'
  36. ");
  37. // Is it set for either "default" or the one they've set as default?
  38. while ($row = $smcFunc['db_fetch_assoc']($request))
  39. {
  40. if ($row['value'] == 1)
  41. {
  42. upgrade_query("
  43. INSERT INTO {$db_prefix}settings
  44. VALUES ('allow_no_censored', 1)
  45. ");
  46. // Don't do this twice...
  47. break;
  48. }
  49. }
  50. }
  51. ---}
  52. ---#
  53. ---# Adding new "topic_move_any" setting
  54. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('topic_move_any', '1');
  55. ---#
  56. /******************************************************************************/
  57. --- Updating legacy attachments...
  58. /******************************************************************************/
  59. ---# Converting legacy attachments.
  60. ---{
  61. $request = upgrade_query("
  62. SELECT MAX(id_attach)
  63. FROM {$db_prefix}attachments");
  64. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  65. $smcFunc['db_free_result']($request);
  66. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  67. $step_progress['name'] = 'Converting legacy attachments';
  68. $step_progress['current'] = $_GET['a'];
  69. // We may be using multiple attachment directories.
  70. if (!empty($modSettings['currentAttachmentUploadDir']) && !is_array($modSettings['attachmentUploadDir']))
  71. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  72. $is_done = false;
  73. while (!$is_done)
  74. {
  75. nextSubStep($substep);
  76. $request = upgrade_query("
  77. SELECT id_attach, id_folder, filename, file_hash
  78. FROM {$db_prefix}attachments
  79. WHERE file_hash = ''
  80. LIMIT $_GET[a], 100");
  81. // Finished?
  82. if ($smcFunc['db_num_rows']($request) == 0)
  83. $is_done = true;
  84. while ($row = $smcFunc['db_fetch_assoc']($request))
  85. {
  86. // The current folder.
  87. $current_folder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$row['id_folder']] : $modSettings['attachmentUploadDir'];
  88. // The old location of the file.
  89. $old_location = getLegacyAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder']);
  90. // The new file name.
  91. $file_hash = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], true);
  92. // And we try to move it.
  93. rename($old_location, $current_folder . '/' . $row['id_attach'] . '_' . $file_hash);
  94. // Only update thif if it was successful.
  95. if (file_exists($current_folder . '/' . $row['id_attach'] . '_' . $file_hash) && !file_exists($old_location))
  96. upgrade_query("
  97. UPDATE {$db_prefix}attachments
  98. SET file_hash = '$file_hash'
  99. WHERE id_attach = $row[id_attach]");
  100. }
  101. $smcFunc['db_free_result']($request);
  102. $_GET['a'] += 100;
  103. $step_progress['current'] = $_GET['a'];
  104. }
  105. unset($_GET['a']);
  106. ---}
  107. ---#
  108. /******************************************************************************/
  109. --- Adding support for IPv6...
  110. /******************************************************************************/
  111. ---# Adding new columns to ban items...
  112. ALTER TABLE {$db_prefix}ban_items
  113. ADD COLUMN ip_low5 smallint(255) unsigned NOT NULL DEFAULT '0',
  114. ADD COLUMN ip_high5 smallint(255) unsigned NOT NULL DEFAULT '0',
  115. ADD COLUMN ip_low6 smallint(255) unsigned NOT NULL DEFAULT '0',
  116. ADD COLUMN ip_high6 smallint(255) unsigned NOT NULL DEFAULT '0',
  117. ADD COLUMN ip_low7 smallint(255) unsigned NOT NULL DEFAULT '0',
  118. ADD COLUMN ip_high7 smallint(255) unsigned NOT NULL DEFAULT '0',
  119. ADD COLUMN ip_low8 smallint(255) unsigned NOT NULL DEFAULT '0',
  120. ADD COLUMN ip_high8 smallint(255) unsigned NOT NULL DEFAULT '0';
  121. ---#
  122. ---# Changing existing columns to ban items...
  123. ALTER TABLE {$db_prefix}ban_items
  124. CHANGE ip_low1 ip_low1 smallint(255) unsigned NOT NULL DEFAULT '0',
  125. CHANGE ip_high1 ip_high1 smallint(255) unsigned NOT NULL DEFAULT '0',
  126. CHANGE ip_low2 ip_low2 smallint(255) unsigned NOT NULL DEFAULT '0',
  127. CHANGE ip_high2 ip_high2 smallint(255) unsigned NOT NULL DEFAULT '0',
  128. CHANGE ip_low3 ip_low3 smallint(255) unsigned NOT NULL DEFAULT '0',
  129. CHANGE ip_high3 ip_high3 smallint(255) unsigned NOT NULL DEFAULT '0',
  130. CHANGE ip_low4 ip_low4 smallint(255) unsigned NOT NULL DEFAULT '0',
  131. CHANGE ip_high4 ip_high4 smallint(255) unsigned NOT NULL DEFAULT '0';
  132. ---#
  133. /******************************************************************************/
  134. --- Adding support for <credits> tag in package manager
  135. /******************************************************************************/
  136. ---# Adding new columns to log_packages ..
  137. ALTER TABLE {$db_prefix}log_packages
  138. ADD COLUMN credits varchar(255) NOT NULL DEFAULT '';
  139. ---#
  140. /******************************************************************************/
  141. --- Adding more space for session ids
  142. /******************************************************************************/
  143. ---# Altering the session_id columns...
  144. ALTER TABLE {$db_prefix}log_online
  145. CHANGE `session` `session` varchar(64) NOT NULL DEFAULT '';
  146. ALTER TABLE {$db_prefix}log_errors
  147. CHANGE `session` `session` char(64) NOT NULL default ' ';
  148. ALTER TABLE {$db_prefix}sessions
  149. CHANGE `session_id` `session_id` char(64) NOT NULL;
  150. ---#
  151. /******************************************************************************/
  152. --- Adding support for MOVED topics enhancements
  153. /******************************************************************************/
  154. ---# Adding new columns to topics ..
  155. ALTER TABLE {$db_prefix}topics
  156. ADD COLUMN redirect_expires int(10) unsigned NOT NULL default '0',
  157. ADD COLUMN id_redirect_topic mediumint(8) unsigned NOT NULL default '0';
  158. ---#
  159. /******************************************************************************/
  160. --- Adding new scheduled tasks
  161. /******************************************************************************/
  162. ---# Adding new scheduled tasks
  163. INSERT INTO {$db_prefix}scheduled_tasks
  164. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  165. VALUES
  166. (0, 120, 1, 'd', 0, 'remove_temp_attachments');
  167. INSERT INTO {$db_prefix}scheduled_tasks
  168. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  169. VALUES
  170. (0, 180, 1, 'd', 0, 'remove_topic_redirect');
  171. INSERT INTO {$db_prefix}scheduled_tasks
  172. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  173. VALUES
  174. (0, 240, 1, 'd', 0, 'remove_old_drafts');
  175. ---#
  176. /******************************************************************************/
  177. ---- Adding background tasks support
  178. /******************************************************************************/
  179. ---# Adding the new table
  180. CREATE TABLE IF NOT EXISTS {$db_prefix}background_tasks (
  181. id_task int(10) unsigned NOT NULL auto_increment,
  182. task_file varchar(255) NOT NULL default '',
  183. task_class varchar(255) NOT NULL default '',
  184. task_data mediumtext NOT NULL,
  185. claimed_time int(10) unsigned NOT NULL default '0',
  186. PRIMARY KEY (id_task)
  187. ) ENGINE=MyISAM;
  188. ---#
  189. /******************************************************************************/
  190. ---- Replacing MSN with Skype
  191. /******************************************************************************/
  192. ---# Modifying the "msn" column...
  193. ALTER TABLE {$db_prefix}members
  194. CHANGE msn skype varchar(255) NOT NULL DEFAULT '';
  195. ---#
  196. /******************************************************************************/
  197. --- Adding support for deny boards access
  198. /******************************************************************************/
  199. ---# Adding new columns to boards...
  200. ALTER TABLE {$db_prefix}boards
  201. ADD COLUMN deny_member_groups varchar(255) NOT NULL DEFAULT '';
  202. ---#
  203. /******************************************************************************/
  204. --- Adding support for topic unwatch
  205. /******************************************************************************/
  206. ---# Adding new columns to boards...
  207. ALTER TABLE {$db_prefix}log_topics
  208. ADD COLUMN unwatched tinyint(3) NOT NULL DEFAULT '0';
  209. UPDATE {$db_prefix}log_topics
  210. SET unwatched = 0;
  211. INSERT INTO {$db_prefix}settings
  212. (variable, value)
  213. VALUES
  214. ('enable_unwatch', 0);
  215. ---#
  216. ---# Fixing column name change...
  217. ALTER TABLE {$db_prefix}log_topics
  218. CHANGE COLUMN disregarded unwatched tinyint(3) NOT NULL DEFAULT '0';
  219. ---#
  220. /******************************************************************************/
  221. --- Fixing mail queue for long messages
  222. /******************************************************************************/
  223. ---# Altering mil_queue table...
  224. ALTER TABLE {$db_prefix}mail_queue
  225. CHANGE body body mediumtext NOT NULL;
  226. ---#
  227. /******************************************************************************/
  228. --- Name changes
  229. /******************************************************************************/
  230. ---# Altering the membergroup stars to icons
  231. ALTER TABLE {$db_prefix}membergroups
  232. CHANGE `stars` `icons` varchar(255) NOT NULL DEFAULT '';
  233. ---#
  234. ---# Renaming default theme...
  235. UPDATE {$db_prefix}themes
  236. SET value = 'SMF Default Theme - Curve2'
  237. WHERE value LIKE 'SMF Default Theme%';
  238. ---#
  239. /******************************************************************************/
  240. --- Cleaning up after old themes...
  241. /******************************************************************************/
  242. ---# Checking for "core" and removing it if necessary...
  243. ---{
  244. // Do they have "core" installed?
  245. if (file_exists($GLOBALS['boarddir'] . '/Themes/core'))
  246. {
  247. $core_dir = $GLOBALS['boarddir'] . '/Themes/core';
  248. $theme_request = upgrade_query("
  249. SELECT id_theme
  250. FROM {$db_prefix}themes
  251. WHERE variable = 'theme_dir'
  252. AND value ='$core_dir'");
  253. // Don't do anything if this theme is already uninstalled
  254. if ($smcFunc['db_num_rows']($theme_request) == 1)
  255. {
  256. // Only one row, so no loop needed
  257. $row = $smcFunc['db_fetch_array']($theme_request);
  258. $id_theme = $row[0];
  259. $smcFunc['db_free_result']($theme_request);
  260. $known_themes = explode(', ', $modSettings['knownThemes']);
  261. // Remove this value...
  262. $known_themes = array_diff($known_themes, array($id_theme));
  263. // Change back to a string...
  264. $known_themes = implode(', ', $known_themes);
  265. // Update the database
  266. upgrade_query("
  267. REPLACE INTO {$db_prefix}settings (variable, value)
  268. VALUES ('knownThemes', '$known_themes')");
  269. // Delete any info about this theme
  270. upgrade_query("
  271. DELETE FROM {$db_prefix}themes
  272. WHERE id_theme = $id_theme");
  273. // Set any members or boards using this theme to the default
  274. upgrade_query("
  275. UPDATE {$db_prefix}members
  276. SET id_theme = 0
  277. WHERE id_theme = $id_theme");
  278. upgrade_query("
  279. UPDATE {$db_prefix}boards
  280. SET id_theme = 0
  281. WHERE id_theme = $id_theme");
  282. if ($modSettings['theme_guests'] == $id_theme)
  283. {
  284. upgrade_query("
  285. REPLACE INTO {$db_prefix}settings
  286. (variable, value)
  287. VALUES('theme_guests', 0)");
  288. }
  289. }
  290. }
  291. ---}
  292. ---#
  293. /******************************************************************************/
  294. --- Adding support for drafts
  295. /******************************************************************************/
  296. ---# Creating draft table
  297. CREATE TABLE IF NOT EXISTS {$db_prefix}user_drafts (
  298. id_draft int(10) unsigned NOT NULL auto_increment,
  299. id_topic mediumint(8) unsigned NOT NULL default '0',
  300. id_board smallint(5) unsigned NOT NULL default '0',
  301. id_reply int(10) unsigned NOT NULL default '0',
  302. type tinyint(4) NOT NULL default '0',
  303. poster_time int(10) unsigned NOT NULL default '0',
  304. id_member mediumint(8) unsigned NOT NULL default '0',
  305. subject varchar(255) NOT NULL default '',
  306. smileys_enabled tinyint(4) NOT NULL default '1',
  307. body mediumtext NOT NULL,
  308. icon varchar(16) NOT NULL default 'xx',
  309. locked tinyint(4) NOT NULL default '0',
  310. is_sticky tinyint(4) NOT NULL default '0',
  311. to_list varchar(255) NOT NULL default '',
  312. PRIMARY KEY id_draft(id_draft),
  313. UNIQUE id_member (id_member, id_draft, type)
  314. ) ENGINE=MyISAM{$db_collation};
  315. ---#
  316. ---# Adding draft permissions...
  317. ---{
  318. // We cannot do this twice
  319. if (@$modSettings['smfVersion'] < '2.1')
  320. {
  321. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  322. $request = upgrade_query("
  323. SELECT id_group, id_board, add_deny, permission
  324. FROM {$db_prefix}board_permissions
  325. WHERE permission = 'post_unapproved_topics'");
  326. $inserts = array();
  327. while ($row = $smcFunc['db_fetch_assoc']($request))
  328. {
  329. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  330. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  331. }
  332. $smcFunc['db_free_result']($request);
  333. if (!empty($inserts))
  334. upgrade_query("
  335. INSERT IGNORE INTO {$db_prefix}board_permissions
  336. (id_group, id_board, permission, add_deny)
  337. VALUES
  338. " . implode(',', $inserts));
  339. // Next we find people who can send PMs, and assume they can save pm_drafts as well
  340. $request = upgrade_query("
  341. SELECT id_group, add_deny, permission
  342. FROM {$db_prefix}permissions
  343. WHERE permission = 'pm_send'");
  344. $inserts = array();
  345. while ($row = $smcFunc['db_fetch_assoc']($request))
  346. {
  347. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  348. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  349. }
  350. $smcFunc['db_free_result']($request);
  351. if (!empty($inserts))
  352. upgrade_query("
  353. INSERT IGNORE INTO {$db_prefix}permissions
  354. (id_group, permission, add_deny)
  355. VALUES
  356. " . implode(',', $inserts));
  357. }
  358. ---}
  359. INSERT INTO {$db_prefix}settings
  360. (variable, value)
  361. VALUES
  362. ('drafts_autosave_enabled', '1'),
  363. ('drafts_show_saved_enabled', '1'),
  364. ('drafts_keep_days', '7');
  365. INSERT INTO {$db_prefix}themes
  366. (id_theme, variable, value)
  367. VALUES
  368. ('1', 'drafts_autosave_enabled', '1'),
  369. ('1', 'drafts_show_saved_enabled', '1');
  370. ---#
  371. /******************************************************************************/
  372. --- Adding support for likes
  373. /******************************************************************************/
  374. ---# Creating likes table.
  375. CREATE TABLE IF NOT EXISTS {$db_prefix}user_likes (
  376. id_member mediumint(8) unsigned NOT NULL default '0',
  377. content_type char(6) default '',
  378. content_id int(10) unsigned NOT NULL default '0',
  379. like_time int(10) unsigned NOT NULL default '0',
  380. PRIMARY KEY (content_id, content_type, id_member),
  381. INDEX content (content_id, content_type),
  382. INDEX liker (id_member)
  383. ) ENGINE=MyISAM;
  384. ---#
  385. ---# Adding count to the messages table.
  386. ALTER TABLE {$db_prefix}messages
  387. ADD COLUMN likes smallint(5) unsigned NOT NULL DEFAULT '0';
  388. ---#
  389. /******************************************************************************/
  390. --- Adding support for group-based board moderation
  391. /******************************************************************************/
  392. ---# Creating moderator_groups table
  393. CREATE TABLE IF NOT EXISTS {$db_prefix}moderator_groups (
  394. id_board smallint(5) unsigned NOT NULL default '0',
  395. id_group smallint(5) unsigned NOT NULL default '0',
  396. PRIMARY KEY (id_board, id_group)
  397. ) ENGINE=MyISAM{$db_collation};
  398. ---#
  399. /******************************************************************************/
  400. --- Cleaning up integration hooks
  401. /******************************************************************************/
  402. ---# Deleting integration hooks
  403. DELETE FROM {$db_prefix}settings
  404. WHERE variable LIKE 'integrate_%';
  405. ---#
  406. /******************************************************************************/
  407. --- Cleaning up old settings
  408. /******************************************************************************/
  409. ---# Showing contact details to guests should never happen.
  410. DELETE FROM {$db_prefix}settings
  411. WHERE variable IN ('enableStickyTopics', 'guest_hideContacts');
  412. ---#
  413. /******************************************************************************/
  414. --- Removing old Simple Machines files we do not need to fetch any more
  415. /******************************************************************************/
  416. ---# We no longer call on the latest packages list.
  417. DELETE FROM {$db_prefix}admin_info_files
  418. WHERE filename = 'latest-packages.js'
  419. AND path = '/smf/';
  420. ---#
  421. /******************************************************************************/
  422. --- Upgrading "verification questions" feature
  423. /******************************************************************************/
  424. ---# Creating qanda table
  425. CREATE TABLE IF NOT EXISTS {$db_prefix}qanda (
  426. id_question smallint(5) unsigned NOT NULL auto_increment,
  427. lngfile varchar(255) NOT NULL default '',
  428. question varchar(255) NOT NULL default '',
  429. answers text NOT NULL,
  430. PRIMARY KEY (id_question),
  431. KEY lngfile (lngfile)
  432. ) ENGINE=MyISAM{$db_collation};
  433. ---#
  434. ---# Moving questions and answers to the new table
  435. ---{
  436. $questions = array();
  437. $get_questions = upgrade_query("
  438. SELECT body AS question, recipient_name AS answer
  439. FROM {$db_prefix}log_comments
  440. WHERE comment_type = 'ver_test'");
  441. while ($row = $smcFunc['db_fetch_assoc']($get_questions))
  442. $questions[] = array($language, $row['question'], serialize(array($row['answer'])));
  443. $smcFunc['db_free_result']($get_questions);
  444. if (!empty($questions))
  445. {
  446. $smcFunc['db_insert']('',
  447. '{db_prefix}qanda',
  448. array('lngfile' => 'string', 'question' => 'string', 'answers' => 'string'),
  449. $questions,
  450. array('id_question')
  451. );
  452. // Delete the questions from log_comments now
  453. upgrade_query("
  454. DELETE FROM {$db_prefix}log_comments
  455. WHERE comment_type = 'ver_test'
  456. ");
  457. }
  458. ---}
  459. ---#
  460. /******************************************************************************/
  461. --- Marking packages as uninstalled...
  462. /******************************************************************************/
  463. ---# Updating log_packages
  464. UPDATE {$db_prefix}log_packages
  465. SET install_state = 0;
  466. ---#
  467. /******************************************************************************/
  468. --- Updating profile permissions...
  469. /******************************************************************************/
  470. ---# Removing the old "view your own profile" permission
  471. DELETE FROM {$db_prefix}permissions
  472. WHERE permission = 'profile_view_own';
  473. ---#
  474. ---# Updating the old "view any profile" permission
  475. UPDATE {$db_prefix}permissions
  476. SET permission = 'profile_view'
  477. WHERE permission = 'profile_view_any';
  478. ---#
  479. ---# Adding "profile_password_own"
  480. ---{
  481. $inserts = array();
  482. $request = upgrade_query("
  483. SELECT id_group, add_deny
  484. FROM {$db_prefix}permissions
  485. WHERE permission = 'profile_identity_own'");
  486. while ($row = $smcFunc['db_fetch_assoc']($request))
  487. {
  488. $inserts[] = "($row[id_group], 'profile_password_own', $row[add_deny])";
  489. }
  490. $smcFunc['db_free_result']($request);
  491. if (!empty($inserts))
  492. {
  493. upgrade_query("
  494. INSERT INTO {$db_prefix}permissions
  495. (id_group, permission, add_deny)
  496. VALUES
  497. " . implode(',', $inserts)
  498. );
  499. }
  500. ---}
  501. ---#
  502. ---# Adding other profile permissions
  503. ---{
  504. $inserts = array();
  505. $request = upgrade_query("
  506. SELECT id_group, add_deny
  507. FROM {$db_prefix}permissions
  508. WHERE permission = 'profile_extra_own'");
  509. while ($row = $smcFunc['db_fetch_assoc']($request))
  510. {
  511. $inserts[] = "($row[id_group], 'profile_blurb_own', $row[add_deny])";
  512. $inserts[] = "($row[id_group], 'profile_displayed_name_own', $row[add_deny])";
  513. $inserts[] = "($row[id_group], 'profile_forum_own', $row[add_deny])";
  514. $inserts[] = "($row[id_group], 'profile_other_own', $row[add_deny])";
  515. $inserts[] = "($row[id_group], 'profile_signature_own', $row[add_deny])";
  516. }
  517. $smcFunc['db_free_result']($request);
  518. if (!empty($inserts))
  519. {
  520. upgrade_query("
  521. INSERT INTO {$db_prefix}permissions
  522. (id_group, permission, add_deny)
  523. VALUES
  524. " . implode(',', $inserts)
  525. );
  526. }
  527. ---}
  528. ---#
  529. /******************************************************************************/
  530. --- Upgrading PM labels...
  531. /******************************************************************************/
  532. ---# Adding pm_labels table...
  533. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labels (
  534. id_label int(10) unsigned NOT NULL auto_increment,
  535. id_member mediumint(8) unsigned NOT NULL default '0',
  536. name varchar(30) NOT NULL default '',
  537. PRIMARY KEY (id_label)
  538. ) ENGINE=MyISAM;
  539. ---#
  540. ---# Adding pm_labeled_messages table...
  541. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labeled_messages (
  542. id_label int(10) unsigned NOT NULL default '0',
  543. id_pm int(10) unsigned NOT NULL default '0',
  544. PRIMARY KEY (id_label, id_pm)
  545. ) ENGINE=MyISAM;
  546. ---#
  547. ---# Adding "in_inbox" column to pm_recipients
  548. ALTER TABLE {$db_prefix}pm_recipients
  549. ADD COLUMN in_inbox tinyint(3) NOT NULL default '1';
  550. ---#
  551. ---# Moving label info to new tables and updating rules...
  552. ---{
  553. // First see if we still have a message_labels column
  554. $results = $smcFunc['db_list_columns']('{db_prefix}members');
  555. if (in_array('message_labels', $results))
  556. {
  557. // They've still got it, so pull the label info
  558. $get_labels = $smcFunc['db_query']('', '
  559. SELECT id_member, message_labels
  560. FROM {db_prefix}members
  561. WHERE message_labels != {string:blank}',
  562. array(
  563. 'blank' => '',
  564. )
  565. );
  566. $inserts = array();
  567. $label_info = array();
  568. while ($row = $smcFunc['db_fetch_assoc']($get_labels))
  569. {
  570. // Stick this in an array
  571. $labels = explode(',', $row['message_labels']);
  572. // Build some inserts
  573. foreach ($labels AS $index => $label)
  574. {
  575. // Keep track of the index of this label - we'll need that in a bit...
  576. $label_info[$row['id_member']][$label] = $index;
  577. $inserts[] = array($row['id_member'], $label);
  578. }
  579. }
  580. $smcFunc['db_free_result']($get_labels);
  581. if (!empty($inserts))
  582. {
  583. $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
  584. // Clear this out for our next query below
  585. $inserts = array();
  586. }
  587. // This is the easy part - update the inbox stuff
  588. $smcFunc['db_query']('', '
  589. UPDATE {db_prefix}pm_recipients
  590. SET in_inbox = {int:in_inbox}
  591. WHERE FIND_IN_SET({int:minusone}, labels)',
  592. array(
  593. 'in_inbox' => 1,
  594. 'minusone' => -1,
  595. )
  596. );
  597. // Now we go pull the new IDs for each label
  598. $get_new_label_ids = $smcFunc['db_query']('', '
  599. SELECT *
  600. FROM {db_prefix}pm_labels',
  601. array(
  602. )
  603. );
  604. $label_info_2 = array();
  605. while ($label_row = $smcFunc['db_fetch_assoc']($get_new_label_ids))
  606. {
  607. // Map the old index values to the new ID values...
  608. $old_index = $label_info[$row['id_member']][$row['label_name']];
  609. $label_info_2[$row['id_member']][$old_index] = $row['id_label'];
  610. }
  611. $smcFunc['db_free_result']($get_new_label_ids);
  612. // Pull label info from pm_recipients
  613. // Ignore any that are only in the inbox
  614. $get_pm_labels = $smcFunc['db_query']('', '
  615. SELECT id_pm, id_member, labels
  616. FROM {db_prefix}pm_recipients
  617. WHERE deleted = {int:not_deleted}
  618. AND labels != {string:minus_one}',
  619. array(
  620. 'not_deleted' => 0,
  621. 'minus_one' => -1,
  622. )
  623. );
  624. while ($row = $smcFunc['db_fetch_assoc']($get_pm_labels))
  625. {
  626. $labels = explode(',', $row['labels']);
  627. foreach ($labels as $a_label)
  628. {
  629. if ($a_label == '-1')
  630. continue;
  631. $new_label_info = $label_info_2[$row['id_member']][$a_label];
  632. $inserts[] = array($row['id_pm'], $new_label_info);
  633. }
  634. }
  635. $smcFunc['db_free_result']($get_pm_labels);
  636. // Insert the new data
  637. if (!empty($inserts))
  638. {
  639. $smcFunc['db_insert']('', '{db_prefix}pm_labeled_messages', array('id_pm' => 'int', 'id_label' => 'int'), $inserts, array());
  640. }
  641. // Final step of this ridiculously massive process
  642. $get_pm_rules = $smcFunc['db_query']('', '
  643. SELECT id_member, id_rule, actions
  644. FROM {db_prefix}pm_rules',
  645. array(
  646. )
  647. );
  648. // Go through the rules, unserialize the actions, then figure out if there's anything we can use
  649. while ($row = $smcFunc['db_fetch_assoc']($get_pm_rules))
  650. {
  651. // Turn this into an array...
  652. $actions = unserialize($row['actions']);
  653. // Loop through the actions and see if we're applying a label anywhere
  654. foreach ($actions as $index => $action)
  655. {
  656. if ($action['t'] == 'lab')
  657. {
  658. // Update the value of this label...
  659. $actions[$index]['v'] = $label_info_2[$row['id_member']][$action['v']];
  660. }
  661. }
  662. // Put this back into a string
  663. $actions = serialize($actions);
  664. $smcFunc['db_query']('', '
  665. UPDATE {db_prefix}pm_rules
  666. SET actions = {string:actions}
  667. WHERE id_rule = {int:id_rule}',
  668. array(
  669. 'actions' => $actions,
  670. 'id_rule' => $row['id_rule'],
  671. )
  672. );
  673. }
  674. $smcFunc['db_free_result']($get_pm_rules);
  675. // Lastly, we drop the old columns
  676. $smcFunc['db_remove_column']('{db_prefix}members', 'message_labels');
  677. $smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
  678. }
  679. ---}
  680. ---#
  681. /******************************************************************************/
  682. --- Adding support for edit reasons
  683. /******************************************************************************/
  684. ---# Adding "modified_reason" column to messages
  685. ALTER TABLE {$db_prefix}messages
  686. ADD COLUMN modified_reason varchar(255) NOT NULL;
  687. ---#
  688. /******************************************************************************/
  689. --- Cleaning up guest permissions
  690. /******************************************************************************/
  691. ---# Removing permissions guests can no longer have...
  692. ---{
  693. $illegal_board_permissions = array(
  694. 'announce_topic',
  695. 'delete_any',
  696. 'lock_any',
  697. 'make_sticky',
  698. 'merge_any',
  699. 'modify_any',
  700. 'modify_replies',
  701. 'move_any',
  702. 'poll_add_any',
  703. 'poll_edit_any',
  704. 'poll_lock_any',
  705. 'poll_remove_any',
  706. 'remove_any',
  707. 'report_any',
  708. 'split_any'
  709. );
  710. $illegal_permissions = array('calendar_edit_any', 'moderate_board', 'moderate_forum', 'send_email_to_members');
  711. $smcFunc['db_query']('', '
  712. DELETE FROM {db_prefix}board_permissions
  713. WHERE id_group = {int:guests}
  714. AND permission IN ({array_string:illegal_board_perms})',
  715. array(
  716. 'guests' => -1,
  717. 'illegal_board_perms' => $illegal_board_permissions,
  718. )
  719. );
  720. $smcFunc['db_query']('', '
  721. DELETE FROM {db_prefix}permissions
  722. WHERE id_group = {int:guests}
  723. AND permission IN ({array_string:illegal_perms})',
  724. array(
  725. 'guests' => -1,
  726. 'illegal_perms' => $illegal_permissions,
  727. )
  728. );
  729. ---}
  730. ---#