upgrade_2-1_mysql.sql 41 KB

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