upgrade_2-1_mysql.sql 43 KB

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