upgrade_2-1_mysql.sql 41 KB

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