upgrade_2-1_mysql.sql 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  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
  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. }
  143. $smcFunc['db_free_result']($request);
  144. $_GET['a'] += 100;
  145. $step_progress['current'] = $_GET['a'];
  146. }
  147. unset($_GET['a']);
  148. ---}
  149. ---#
  150. /******************************************************************************/
  151. --- Adding support for IPv6...
  152. /******************************************************************************/
  153. ---# Adding new columns to ban items...
  154. ALTER TABLE {$db_prefix}ban_items
  155. ADD COLUMN ip_low5 smallint(255) unsigned NOT NULL DEFAULT '0',
  156. ADD COLUMN ip_high5 smallint(255) unsigned NOT NULL DEFAULT '0',
  157. ADD COLUMN ip_low6 smallint(255) unsigned NOT NULL DEFAULT '0',
  158. ADD COLUMN ip_high6 smallint(255) unsigned NOT NULL DEFAULT '0',
  159. ADD COLUMN ip_low7 smallint(255) unsigned NOT NULL DEFAULT '0',
  160. ADD COLUMN ip_high7 smallint(255) unsigned NOT NULL DEFAULT '0',
  161. ADD COLUMN ip_low8 smallint(255) unsigned NOT NULL DEFAULT '0',
  162. ADD COLUMN ip_high8 smallint(255) unsigned NOT NULL DEFAULT '0';
  163. ---#
  164. ---# Changing existing columns to ban items...
  165. ALTER TABLE {$db_prefix}ban_items
  166. CHANGE ip_low1 ip_low1 smallint(255) unsigned NOT NULL DEFAULT '0',
  167. CHANGE ip_high1 ip_high1 smallint(255) unsigned NOT NULL DEFAULT '0',
  168. CHANGE ip_low2 ip_low2 smallint(255) unsigned NOT NULL DEFAULT '0',
  169. CHANGE ip_high2 ip_high2 smallint(255) unsigned NOT NULL DEFAULT '0',
  170. CHANGE ip_low3 ip_low3 smallint(255) unsigned NOT NULL DEFAULT '0',
  171. CHANGE ip_high3 ip_high3 smallint(255) unsigned NOT NULL DEFAULT '0',
  172. CHANGE ip_low4 ip_low4 smallint(255) unsigned NOT NULL DEFAULT '0',
  173. CHANGE ip_high4 ip_high4 smallint(255) unsigned NOT NULL DEFAULT '0';
  174. ---#
  175. /******************************************************************************/
  176. --- Adding support for logging who fulfils a group request.
  177. /******************************************************************************/
  178. ---# Adding new columns to log_group_requests
  179. ALTER TABLE {$db_prefix}log_group_requests
  180. ADD COLUMN status tinyint(3) unsigned NOT NULL default '0',
  181. ADD COLUMN id_member_acted mediumint(8) unsigned NOT NULL default '0',
  182. ADD COLUMN member_name_acted varchar(255) NOT NULL default '',
  183. ADD COLUMN time_acted int(10) unsigned NOT NULL default '0',
  184. ADD COLUMN act_reason text NOT NULL;
  185. ---#
  186. ---# Adjusting the indexes for log_group_requests
  187. ALTER TABLE {$db_prefix}log_group_requests
  188. DROP INDEX `id_member`,
  189. ADD INDEX `id_member` (`id_member`, `id_group`);
  190. ---#
  191. /******************************************************************************/
  192. --- Adding support for <credits> tag in package manager
  193. /******************************************************************************/
  194. ---# Adding new columns to log_packages ..
  195. ALTER TABLE {$db_prefix}log_packages
  196. ADD COLUMN credits varchar(255) NOT NULL DEFAULT '';
  197. ---#
  198. /******************************************************************************/
  199. --- Adding more space for session ids
  200. /******************************************************************************/
  201. ---# Altering the session_id columns...
  202. ALTER TABLE {$db_prefix}log_online
  203. CHANGE `session` `session` varchar(64) NOT NULL DEFAULT '';
  204. ALTER TABLE {$db_prefix}log_errors
  205. CHANGE `session` `session` char(64) NOT NULL default ' ';
  206. ALTER TABLE {$db_prefix}sessions
  207. CHANGE `session_id` `session_id` char(64) NOT NULL;
  208. ---#
  209. /******************************************************************************/
  210. --- Adding support for MOVED topics enhancements
  211. /******************************************************************************/
  212. ---# Adding new columns to topics ..
  213. ALTER TABLE {$db_prefix}topics
  214. ADD COLUMN redirect_expires int(10) unsigned NOT NULL default '0',
  215. ADD COLUMN id_redirect_topic mediumint(8) unsigned NOT NULL default '0';
  216. ---#
  217. /******************************************************************************/
  218. --- Adding new scheduled tasks
  219. /******************************************************************************/
  220. ---# Adding new scheduled tasks
  221. INSERT INTO {$db_prefix}scheduled_tasks
  222. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  223. VALUES
  224. (0, 120, 1, 'd', 0, 'remove_temp_attachments');
  225. INSERT INTO {$db_prefix}scheduled_tasks
  226. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  227. VALUES
  228. (0, 180, 1, 'd', 0, 'remove_topic_redirect');
  229. INSERT INTO {$db_prefix}scheduled_tasks
  230. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  231. VALUES
  232. (0, 240, 1, 'd', 0, 'remove_old_drafts');
  233. ---#
  234. /******************************************************************************/
  235. ---- Adding background tasks support
  236. /******************************************************************************/
  237. ---# Adding the new table
  238. CREATE TABLE IF NOT EXISTS {$db_prefix}background_tasks (
  239. id_task int(10) unsigned NOT NULL auto_increment,
  240. task_file varchar(255) NOT NULL default '',
  241. task_class varchar(255) NOT NULL default '',
  242. task_data mediumtext NOT NULL,
  243. claimed_time int(10) unsigned NOT NULL default '0',
  244. PRIMARY KEY (id_task)
  245. ) ENGINE=MyISAM;
  246. ---#
  247. /******************************************************************************/
  248. ---- Replacing MSN with Skype
  249. /******************************************************************************/
  250. ---# Modifying the "msn" column...
  251. ALTER TABLE {$db_prefix}members
  252. CHANGE msn skype varchar(255) NOT NULL DEFAULT '';
  253. ---#
  254. /******************************************************************************/
  255. --- Adding support for deny boards access
  256. /******************************************************************************/
  257. ---# Adding new columns to boards...
  258. ALTER TABLE {$db_prefix}boards
  259. ADD COLUMN deny_member_groups varchar(255) NOT NULL DEFAULT '';
  260. ---#
  261. /******************************************************************************/
  262. --- Updating board access rules
  263. /******************************************************************************/
  264. ---# Updating board access rules
  265. ---{
  266. $member_groups = array(
  267. 'allowed' => array(),
  268. 'denied' => array(),
  269. );
  270. $request = $smcFunc['db_query']('', '
  271. SELECT id_group, add_deny
  272. FROM {db_prefix}permissions
  273. WHERE permission = {string:permission}',
  274. array(
  275. 'permission' => 'manage_boards',
  276. )
  277. );
  278. while ($row = $smcFunc['db_fetch_assoc']($request))
  279. $member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group'];
  280. $smcFunc['db_free_result']($request);
  281. $member_groups = array_diff($member_groups['allowed'], $member_groups['denied']);
  282. if (!empty($member_groups))
  283. {
  284. $count = count($member_groups);
  285. $changes = array();
  286. $request = $smcFunc['db_query']('', '
  287. SELECT id_board, member_groups
  288. FROM {db_prefix}boards');
  289. while ($row = $smcFunc['db_fetch_assoc']($request))
  290. {
  291. $current_groups = explode(',', $row['member_groups']);
  292. if (count(array_intersect($current_groups, $member_groups)) != $count)
  293. {
  294. $new_groups = array_unique(array_merge($current_groups, $member_groups));
  295. $changes[$row['id_board']] = implode(',', $new_groups);
  296. }
  297. }
  298. $smcFunc['db_free_result']($request);
  299. if (!empty($changes))
  300. {
  301. foreach ($changes as $id_board => $member_groups)
  302. $smcFunc['db_query']('', '
  303. UPDATE {db_prefix}boards
  304. SET member_groups = {string:member_groups}
  305. WHERE id_board = {int:id_board}',
  306. array(
  307. 'member_groups' => $member_groups,
  308. 'id_board' => $id_board,
  309. )
  310. );
  311. }
  312. }
  313. ---}
  314. ---#
  315. /******************************************************************************/
  316. --- Adding support for category descriptions
  317. /******************************************************************************/
  318. ---# Adding new columns to categories...
  319. ALTER TABLE {$db_prefix}categories
  320. ADD COLUMN description text NOT NULL;
  321. ---#
  322. /******************************************************************************/
  323. --- Adding support for alerts
  324. /******************************************************************************/
  325. ---# Adding the count to the members table...
  326. ALTER TABLE {$db_prefix}members
  327. ADD COLUMN alerts int(10) unsigned NOT NULL default '0';
  328. ---#
  329. ---# Adding the new table for alerts.
  330. CREATE TABLE IF NOT EXISTS {$db_prefix}user_alerts (
  331. id_alert int(10) unsigned NOT NULL auto_increment,
  332. alert_time int(10) unsigned NOT NULL default '0',
  333. id_member mediumint(10) unsigned NOT NULL default '0',
  334. id_member_started mediumint(10) unsigned NOT NULL default '0',
  335. member_name varchar(255) NOT NULL default '',
  336. content_type varchar(255) NOT NULL default '',
  337. content_id int(10) unsigned NOT NULL default '0',
  338. content_action varchar(255) NOT NULL default '',
  339. is_read tinyint(3) unsigned NOT NULL default '0',
  340. extra text NOT NULL,
  341. PRIMARY KEY (id_alert),
  342. KEY id_member (id_member),
  343. KEY alert_time (alert_time)
  344. ) ENGINE=MyISAM;
  345. ---#
  346. ---# Adding alert preferences.
  347. CREATE TABLE IF NOT EXISTS {$db_prefix}user_alerts_prefs (
  348. id_member mediumint(8) unsigned NOT NULL default '0',
  349. alert_pref varchar(32) NOT NULL default '',
  350. alert_value tinyint(3) NOT NULL default '0',
  351. PRIMARY KEY (id_member, alert_pref)
  352. ) ENGINE=MyISAM;
  353. INSERT INTO {$db_prefix}user_alerts_prefs
  354. (id_member, alert_pref, alert_value)
  355. VALUES (0, 'member_group_request', 1),
  356. (0, 'member_register', 1),
  357. (0, 'msg_like', 1),
  358. (0, 'msg_report', 1),
  359. (0, 'msg_report_reply', 1);
  360. ---#
  361. /******************************************************************************/
  362. --- Adding support for topic unwatch
  363. /******************************************************************************/
  364. ---# Adding new columns to boards...
  365. ALTER TABLE {$db_prefix}log_topics
  366. ADD COLUMN unwatched tinyint(3) NOT NULL DEFAULT '0';
  367. UPDATE {$db_prefix}log_topics
  368. SET unwatched = 0;
  369. INSERT INTO {$db_prefix}settings
  370. (variable, value)
  371. VALUES
  372. ('enable_unwatch', 0);
  373. ---#
  374. ---# Fixing column name change...
  375. ALTER TABLE {$db_prefix}log_topics
  376. CHANGE COLUMN disregarded unwatched tinyint(3) NOT NULL DEFAULT '0';
  377. ---#
  378. /******************************************************************************/
  379. --- Fixing mail queue for long messages
  380. /******************************************************************************/
  381. ---# Altering mil_queue table...
  382. ALTER TABLE {$db_prefix}mail_queue
  383. CHANGE body body mediumtext NOT NULL;
  384. ---#
  385. /******************************************************************************/
  386. --- Name changes
  387. /******************************************************************************/
  388. ---# Altering the membergroup stars to icons
  389. ALTER TABLE {$db_prefix}membergroups
  390. CHANGE `stars` `icons` varchar(255) NOT NULL DEFAULT '';
  391. ---#
  392. ---# Renaming default theme...
  393. UPDATE {$db_prefix}themes
  394. SET value = 'SMF Default Theme - Curve2'
  395. WHERE value LIKE 'SMF Default Theme%';
  396. ---#
  397. ---# Adding the enableThemes setting.
  398. INSERT INTO {$db_prefix}settings
  399. (variable, value)
  400. VALUES
  401. ('enableThemes', '1');
  402. ---#
  403. ---# Setting "default" as the default...
  404. UPDATE {$db_prefix}settings
  405. SET value = '1'
  406. WHERE variable = 'theme_guests';
  407. UPDATE {$db_prefix}boards
  408. SET id_theme = 0;
  409. UPDATE {$db_prefix}members
  410. SET id_theme = 0;
  411. ---#
  412. /******************************************************************************/
  413. --- Cleaning up after old themes...
  414. /******************************************************************************/
  415. ---# Checking for "core" and removing it if necessary...
  416. ---{
  417. // Do they have "core" installed?
  418. if (file_exists($GLOBALS['boarddir'] . '/Themes/core'))
  419. {
  420. $core_dir = $GLOBALS['boarddir'] . '/Themes/core';
  421. $theme_request = upgrade_query("
  422. SELECT id_theme
  423. FROM {$db_prefix}themes
  424. WHERE variable = 'theme_dir'
  425. AND value ='$core_dir'");
  426. // Don't do anything if this theme is already uninstalled
  427. if ($smcFunc['db_num_rows']($theme_request) == 1)
  428. {
  429. // Only one row, so no loop needed
  430. $row = $smcFunc['db_fetch_array']($theme_request);
  431. $id_theme = $row[0];
  432. $smcFunc['db_free_result']($theme_request);
  433. $known_themes = explode(', ', $modSettings['knownThemes']);
  434. // Remove this value...
  435. $known_themes = array_diff($known_themes, array($id_theme));
  436. // Change back to a string...
  437. $known_themes = implode(', ', $known_themes);
  438. // Update the database
  439. upgrade_query("
  440. REPLACE INTO {$db_prefix}settings (variable, value)
  441. VALUES ('knownThemes', '$known_themes')");
  442. // Delete any info about this theme
  443. upgrade_query("
  444. DELETE FROM {$db_prefix}themes
  445. WHERE id_theme = $id_theme");
  446. }
  447. }
  448. ---}
  449. ---#
  450. /******************************************************************************/
  451. --- Adding support for drafts
  452. /******************************************************************************/
  453. ---# Creating draft table
  454. CREATE TABLE IF NOT EXISTS {$db_prefix}user_drafts (
  455. id_draft int(10) unsigned NOT NULL auto_increment,
  456. id_topic mediumint(8) unsigned NOT NULL default '0',
  457. id_board smallint(5) unsigned NOT NULL default '0',
  458. id_reply int(10) unsigned NOT NULL default '0',
  459. type tinyint(4) NOT NULL default '0',
  460. poster_time int(10) unsigned NOT NULL default '0',
  461. id_member mediumint(8) unsigned NOT NULL default '0',
  462. subject varchar(255) NOT NULL default '',
  463. smileys_enabled tinyint(4) NOT NULL default '1',
  464. body mediumtext NOT NULL,
  465. icon varchar(16) NOT NULL default 'xx',
  466. locked tinyint(4) NOT NULL default '0',
  467. is_sticky tinyint(4) NOT NULL default '0',
  468. to_list varchar(255) NOT NULL default '',
  469. PRIMARY KEY id_draft(id_draft),
  470. UNIQUE id_member (id_member, id_draft, type)
  471. ) ENGINE=MyISAM{$db_collation};
  472. ---#
  473. ---# Adding draft permissions...
  474. ---{
  475. // We cannot do this twice
  476. if (@$modSettings['smfVersion'] < '2.1')
  477. {
  478. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  479. $request = upgrade_query("
  480. SELECT id_group, id_board, add_deny, permission
  481. FROM {$db_prefix}board_permissions
  482. WHERE permission = 'post_unapproved_topics'");
  483. $inserts = array();
  484. while ($row = $smcFunc['db_fetch_assoc']($request))
  485. {
  486. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  487. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  488. }
  489. $smcFunc['db_free_result']($request);
  490. if (!empty($inserts))
  491. upgrade_query("
  492. INSERT IGNORE INTO {$db_prefix}board_permissions
  493. (id_group, id_board, permission, add_deny)
  494. VALUES
  495. " . implode(',', $inserts));
  496. // Next we find people who can send PMs, and assume they can save pm_drafts as well
  497. $request = upgrade_query("
  498. SELECT id_group, add_deny, permission
  499. FROM {$db_prefix}permissions
  500. WHERE permission = 'pm_send'");
  501. $inserts = array();
  502. while ($row = $smcFunc['db_fetch_assoc']($request))
  503. {
  504. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  505. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  506. }
  507. $smcFunc['db_free_result']($request);
  508. if (!empty($inserts))
  509. upgrade_query("
  510. INSERT IGNORE INTO {$db_prefix}permissions
  511. (id_group, permission, add_deny)
  512. VALUES
  513. " . implode(',', $inserts));
  514. }
  515. ---}
  516. INSERT INTO {$db_prefix}settings
  517. (variable, value)
  518. VALUES
  519. ('drafts_autosave_enabled', '1'),
  520. ('drafts_show_saved_enabled', '1'),
  521. ('drafts_keep_days', '7');
  522. INSERT INTO {$db_prefix}themes
  523. (id_theme, variable, value)
  524. VALUES
  525. ('1', 'drafts_autosave_enabled', '1'),
  526. ('1', 'drafts_show_saved_enabled', '1');
  527. ---#
  528. /******************************************************************************/
  529. --- Adding support for likes
  530. /******************************************************************************/
  531. ---# Creating likes table.
  532. CREATE TABLE IF NOT EXISTS {$db_prefix}user_likes (
  533. id_member mediumint(8) unsigned NOT NULL default '0',
  534. content_type char(6) default '',
  535. content_id int(10) unsigned NOT NULL default '0',
  536. like_time int(10) unsigned NOT NULL default '0',
  537. PRIMARY KEY (content_id, content_type, id_member),
  538. INDEX content (content_id, content_type),
  539. INDEX liker (id_member)
  540. ) ENGINE=MyISAM;
  541. ---#
  542. ---# Adding count to the messages table.
  543. ALTER TABLE {$db_prefix}messages
  544. ADD COLUMN likes smallint(5) unsigned NOT NULL DEFAULT '0';
  545. ---#
  546. /******************************************************************************/
  547. --- Adding support for group-based board moderation
  548. /******************************************************************************/
  549. ---# Creating moderator_groups table
  550. CREATE TABLE IF NOT EXISTS {$db_prefix}moderator_groups (
  551. id_board smallint(5) unsigned NOT NULL default '0',
  552. id_group smallint(5) unsigned NOT NULL default '0',
  553. PRIMARY KEY (id_board, id_group)
  554. ) ENGINE=MyISAM{$db_collation};
  555. ---#
  556. /******************************************************************************/
  557. --- Cleaning up integration hooks
  558. /******************************************************************************/
  559. ---# Deleting integration hooks
  560. DELETE FROM {$db_prefix}settings
  561. WHERE variable LIKE 'integrate_%';
  562. ---#
  563. /******************************************************************************/
  564. --- Cleaning up old settings
  565. /******************************************************************************/
  566. ---# Updating the default time format
  567. ---{
  568. if (!empty($modSettings['time_format']))
  569. {
  570. // First, use the shortened form of the month in the date.
  571. $time_format = str_replace('%B', '%b', $modSettings['time_format']);
  572. // Second, shorten the time to stop including seconds.
  573. $time_format = str_replace(':%S', '', $time_format);
  574. // Then, update the database.
  575. $smcFunc['db_query']('', '
  576. UPDATE {db_prefix}settings
  577. SET value = {string:new_format}
  578. WHERE variable = {literal:time_format}',
  579. array(
  580. 'new_format' => $time_format,
  581. )
  582. );
  583. }
  584. ---}
  585. ---#
  586. ---# Fixing a deprecated option.
  587. UPDATE {$db_prefix}settings
  588. SET value = 'option_css_resize'
  589. WHERE variable = 'avatar_action_too_large'
  590. AND (value = 'option_html_resize' OR value = 'option_js_resize');
  591. ---#
  592. ---# Cleaning up the old Core Features page.
  593. ---{
  594. // First get the original value
  595. $request = $smcFunc['db_query']('', '
  596. SELECT value
  597. FROM {db_prefix}settings
  598. WHERE variable = {literal:admin_features}');
  599. if ($smcFunc['db_num_rows']($request) > 0 && $row = $smcFunc['db_fetch_assoc']($request))
  600. {
  601. // Some of these *should* already be set but you never know.
  602. $new_settings = array();
  603. $admin_features = explode(',', $row['value']);
  604. // Now, let's just recap something.
  605. // cd = calendar, should also have set cal_enabled already
  606. // cp = custom profile fields, which already has several fields that cover tracking
  607. // k = karma, should also have set karmaMode already
  608. // ps = paid subs, should also have set paid_enabled already
  609. // rg = reports generation, which is now permanently on
  610. // sp = spider tracking, should also have set spider_mode already
  611. // w = warning system, which will be covered with warning_settings
  612. // The rest we have to deal with manually.
  613. // Moderation log - modlog_enabled itself should be set but we have others now
  614. if (in_array('ml', $admin_features))
  615. {
  616. $new_settings[] = array('adminlog_enabled', '1');
  617. $new_settings[] = array('userlog_enabled', '1');
  618. }
  619. // Post moderation
  620. if (in_array('pm', $admin_features))
  621. {
  622. $new_settings[] = array('postmod_active', '1');
  623. }
  624. // And now actually apply it.
  625. if (!empty($new_settings))
  626. {
  627. $smcFunc['db_insert']('replace',
  628. '{db_prefix}settings',
  629. array('variable' => 'string', 'value' => 'string'),
  630. $new_settings,
  631. array('variable')
  632. );
  633. }
  634. }
  635. $smcFunc['db_free_result']($request);
  636. ---}
  637. ---#
  638. ---# Cleaning up old settings.
  639. DELETE FROM {$db_prefix}settings
  640. WHERE variable IN ('enableStickyTopics', 'guest_hideContacts', 'notify_new_registration', 'attachmentEncryptFilenames', 'hotTopicPosts', 'hotTopicVeryPosts', 'fixLongWords', 'admin_features');
  641. ---#
  642. ---# Cleaning up old theme settings.
  643. DELETE FROM {$db_prefix}themes
  644. WHERE variable IN ('show_board_desc', 'no_new_reply_warning', 'display_quick_reply', 'show_mark_read', 'show_member_bar', 'linktree_link');
  645. ---#
  646. /******************************************************************************/
  647. --- Updating files that fetched from simplemachines.org
  648. /******************************************************************************/
  649. ---# We no longer call on several files.
  650. DELETE FROM {$db_prefix}admin_info_files
  651. WHERE filename IN ('latest-packages.js', 'latest-support.js', 'latest-themes.js')
  652. AND path = '/smf/';
  653. ---#
  654. ---# But we do need new files.
  655. ---{
  656. $smcFunc['db_insert']('',
  657. '{db_prefix}admin_info_files',
  658. array('filename' => 'string', 'path' => 'string', 'parameters' => 'string', 'data' => 'string', 'filetype' => 'string'),
  659. array('latest-versions.txt', '/smf/', 'version=%3$s', '', 'text/plain'),
  660. array('id_file')
  661. );
  662. ---}
  663. ---#
  664. /******************************************************************************/
  665. --- Upgrading "verification questions" feature
  666. /******************************************************************************/
  667. ---# Creating qanda table
  668. CREATE TABLE IF NOT EXISTS {$db_prefix}qanda (
  669. id_question smallint(5) unsigned NOT NULL auto_increment,
  670. lngfile varchar(255) NOT NULL default '',
  671. question varchar(255) NOT NULL default '',
  672. answers text NOT NULL,
  673. PRIMARY KEY (id_question),
  674. KEY lngfile (lngfile)
  675. ) ENGINE=MyISAM{$db_collation};
  676. ---#
  677. ---# Moving questions and answers to the new table
  678. ---{
  679. $questions = array();
  680. $get_questions = upgrade_query("
  681. SELECT body AS question, recipient_name AS answer
  682. FROM {$db_prefix}log_comments
  683. WHERE comment_type = 'ver_test'");
  684. while ($row = $smcFunc['db_fetch_assoc']($get_questions))
  685. $questions[] = array($language, $row['question'], serialize(array($row['answer'])));
  686. $smcFunc['db_free_result']($get_questions);
  687. if (!empty($questions))
  688. {
  689. $smcFunc['db_insert']('',
  690. '{db_prefix}qanda',
  691. array('lngfile' => 'string', 'question' => 'string', 'answers' => 'string'),
  692. $questions,
  693. array('id_question')
  694. );
  695. // Delete the questions from log_comments now
  696. upgrade_query("
  697. DELETE FROM {$db_prefix}log_comments
  698. WHERE comment_type = 'ver_test'
  699. ");
  700. }
  701. ---}
  702. ---#
  703. /******************************************************************************/
  704. --- Marking packages as uninstalled...
  705. /******************************************************************************/
  706. ---# Updating log_packages
  707. UPDATE {$db_prefix}log_packages
  708. SET install_state = 0;
  709. ---#
  710. /******************************************************************************/
  711. --- Updating profile permissions...
  712. /******************************************************************************/
  713. ---# Removing the old "view your own profile" permission
  714. DELETE FROM {$db_prefix}permissions
  715. WHERE permission = 'profile_view_own';
  716. ---#
  717. ---# Updating the old "view any profile" permission
  718. UPDATE {$db_prefix}permissions
  719. SET permission = 'profile_view'
  720. WHERE permission = 'profile_view_any';
  721. ---#
  722. ---# Removing the old notification permissions
  723. DELETE FROM {$db_prefix}board_permissions
  724. WHERE permission = 'mark_notify' OR permission = 'mark_any_notify';
  725. ---#
  726. ---# Adding "profile_password_own"
  727. ---{
  728. $inserts = array();
  729. $request = upgrade_query("
  730. SELECT id_group, add_deny
  731. FROM {$db_prefix}permissions
  732. WHERE permission = 'profile_identity_own'");
  733. while ($row = $smcFunc['db_fetch_assoc']($request))
  734. {
  735. $inserts[] = "($row[id_group], 'profile_password_own', $row[add_deny])";
  736. }
  737. $smcFunc['db_free_result']($request);
  738. if (!empty($inserts))
  739. {
  740. upgrade_query("
  741. INSERT INTO {$db_prefix}permissions
  742. (id_group, permission, add_deny)
  743. VALUES
  744. " . implode(',', $inserts)
  745. );
  746. }
  747. ---}
  748. ---#
  749. ---# Adding other profile permissions
  750. ---{
  751. $inserts = array();
  752. $request = upgrade_query("
  753. SELECT id_group, add_deny
  754. FROM {$db_prefix}permissions
  755. WHERE permission = 'profile_extra_own'");
  756. while ($row = $smcFunc['db_fetch_assoc']($request))
  757. {
  758. $inserts[] = "($row[id_group], 'profile_blurb_own', $row[add_deny])";
  759. $inserts[] = "($row[id_group], 'profile_displayed_name_own', $row[add_deny])";
  760. $inserts[] = "($row[id_group], 'profile_forum_own', $row[add_deny])";
  761. $inserts[] = "($row[id_group], 'profile_other_own', $row[add_deny])";
  762. $inserts[] = "($row[id_group], 'profile_signature_own', $row[add_deny])";
  763. }
  764. $smcFunc['db_free_result']($request);
  765. if (!empty($inserts))
  766. {
  767. upgrade_query("
  768. INSERT INTO {$db_prefix}permissions
  769. (id_group, permission, add_deny)
  770. VALUES
  771. " . implode(',', $inserts)
  772. );
  773. }
  774. ---}
  775. ---#
  776. /******************************************************************************/
  777. --- Upgrading PM labels...
  778. /******************************************************************************/
  779. ---# Adding pm_labels table...
  780. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labels (
  781. id_label int(10) unsigned NOT NULL auto_increment,
  782. id_member mediumint(8) unsigned NOT NULL default '0',
  783. name varchar(30) NOT NULL default '',
  784. PRIMARY KEY (id_label)
  785. ) ENGINE=MyISAM;
  786. ---#
  787. ---# Adding pm_labeled_messages table...
  788. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labeled_messages (
  789. id_label int(10) unsigned NOT NULL default '0',
  790. id_pm int(10) unsigned NOT NULL default '0',
  791. PRIMARY KEY (id_label, id_pm)
  792. ) ENGINE=MyISAM;
  793. ---#
  794. ---# Adding "in_inbox" column to pm_recipients
  795. ALTER TABLE {$db_prefix}pm_recipients
  796. ADD COLUMN in_inbox tinyint(3) NOT NULL default '1';
  797. ---#
  798. ---# Moving label info to new tables and updating rules...
  799. ---{
  800. // First see if we still have a message_labels column
  801. $results = $smcFunc['db_list_columns']('{db_prefix}members');
  802. if (in_array('message_labels', $results))
  803. {
  804. // They've still got it, so pull the label info
  805. $get_labels = $smcFunc['db_query']('', '
  806. SELECT id_member, message_labels
  807. FROM {db_prefix}members
  808. WHERE message_labels != {string:blank}',
  809. array(
  810. 'blank' => '',
  811. )
  812. );
  813. $inserts = array();
  814. $label_info = array();
  815. while ($row = $smcFunc['db_fetch_assoc']($get_labels))
  816. {
  817. // Stick this in an array
  818. $labels = explode(',', $row['message_labels']);
  819. // Build some inserts
  820. foreach ($labels AS $index => $label)
  821. {
  822. // Keep track of the index of this label - we'll need that in a bit...
  823. $label_info[$row['id_member']][$label] = $index;
  824. $inserts[] = array($row['id_member'], $label);
  825. }
  826. }
  827. $smcFunc['db_free_result']($get_labels);
  828. if (!empty($inserts))
  829. {
  830. $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
  831. // Clear this out for our next query below
  832. $inserts = array();
  833. }
  834. // This is the easy part - update the inbox stuff
  835. $smcFunc['db_query']('', '
  836. UPDATE {db_prefix}pm_recipients
  837. SET in_inbox = {int:in_inbox}
  838. WHERE FIND_IN_SET({int:minusone}, labels)',
  839. array(
  840. 'in_inbox' => 1,
  841. 'minusone' => -1,
  842. )
  843. );
  844. // Now we go pull the new IDs for each label
  845. $get_new_label_ids = $smcFunc['db_query']('', '
  846. SELECT *
  847. FROM {db_prefix}pm_labels',
  848. array(
  849. )
  850. );
  851. $label_info_2 = array();
  852. while ($label_row = $smcFunc['db_fetch_assoc']($get_new_label_ids))
  853. {
  854. // Map the old index values to the new ID values...
  855. $old_index = $label_info[$row['id_member']][$row['label_name']];
  856. $label_info_2[$row['id_member']][$old_index] = $row['id_label'];
  857. }
  858. $smcFunc['db_free_result']($get_new_label_ids);
  859. // Pull label info from pm_recipients
  860. // Ignore any that are only in the inbox
  861. $get_pm_labels = $smcFunc['db_query']('', '
  862. SELECT id_pm, id_member, labels
  863. FROM {db_prefix}pm_recipients
  864. WHERE deleted = {int:not_deleted}
  865. AND labels != {string:minus_one}',
  866. array(
  867. 'not_deleted' => 0,
  868. 'minus_one' => -1,
  869. )
  870. );
  871. while ($row = $smcFunc['db_fetch_assoc']($get_pm_labels))
  872. {
  873. $labels = explode(',', $row['labels']);
  874. foreach ($labels as $a_label)
  875. {
  876. if ($a_label == '-1')
  877. continue;
  878. $new_label_info = $label_info_2[$row['id_member']][$a_label];
  879. $inserts[] = array($row['id_pm'], $new_label_info);
  880. }
  881. }
  882. $smcFunc['db_free_result']($get_pm_labels);
  883. // Insert the new data
  884. if (!empty($inserts))
  885. {
  886. $smcFunc['db_insert']('', '{db_prefix}pm_labeled_messages', array('id_pm' => 'int', 'id_label' => 'int'), $inserts, array());
  887. }
  888. // Final step of this ridiculously massive process
  889. $get_pm_rules = $smcFunc['db_query']('', '
  890. SELECT id_member, id_rule, actions
  891. FROM {db_prefix}pm_rules',
  892. array(
  893. )
  894. );
  895. // Go through the rules, unserialize the actions, then figure out if there's anything we can use
  896. while ($row = $smcFunc['db_fetch_assoc']($get_pm_rules))
  897. {
  898. // Turn this into an array...
  899. $actions = unserialize($row['actions']);
  900. // Loop through the actions and see if we're applying a label anywhere
  901. foreach ($actions as $index => $action)
  902. {
  903. if ($action['t'] == 'lab')
  904. {
  905. // Update the value of this label...
  906. $actions[$index]['v'] = $label_info_2[$row['id_member']][$action['v']];
  907. }
  908. }
  909. // Put this back into a string
  910. $actions = serialize($actions);
  911. $smcFunc['db_query']('', '
  912. UPDATE {db_prefix}pm_rules
  913. SET actions = {string:actions}
  914. WHERE id_rule = {int:id_rule}',
  915. array(
  916. 'actions' => $actions,
  917. 'id_rule' => $row['id_rule'],
  918. )
  919. );
  920. }
  921. $smcFunc['db_free_result']($get_pm_rules);
  922. // Lastly, we drop the old columns
  923. $smcFunc['db_remove_column']('{db_prefix}members', 'message_labels');
  924. $smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
  925. }
  926. ---}
  927. ---#
  928. /******************************************************************************/
  929. --- Adding support for edit reasons
  930. /******************************************************************************/
  931. ---# Adding "modified_reason" column to messages
  932. ALTER TABLE {$db_prefix}messages
  933. ADD COLUMN modified_reason varchar(255) NOT NULL;
  934. ---#
  935. /******************************************************************************/
  936. --- Cleaning up guest permissions
  937. /******************************************************************************/
  938. ---# Removing permissions guests can no longer have...
  939. ---{
  940. $illegal_board_permissions = array(
  941. 'announce_topic',
  942. 'delete_any',
  943. 'lock_any',
  944. 'make_sticky',
  945. 'merge_any',
  946. 'modify_any',
  947. 'modify_replies',
  948. 'move_any',
  949. 'poll_add_any',
  950. 'poll_edit_any',
  951. 'poll_lock_any',
  952. 'poll_remove_any',
  953. 'remove_any',
  954. 'report_any',
  955. 'split_any'
  956. );
  957. $illegal_permissions = array('calendar_edit_any', 'moderate_board', 'moderate_forum', 'send_email_to_members');
  958. $smcFunc['db_query']('', '
  959. DELETE FROM {db_prefix}board_permissions
  960. WHERE id_group = {int:guests}
  961. AND permission IN ({array_string:illegal_board_perms})',
  962. array(
  963. 'guests' => -1,
  964. 'illegal_board_perms' => $illegal_board_permissions,
  965. )
  966. );
  967. $smcFunc['db_query']('', '
  968. DELETE FROM {db_prefix}permissions
  969. WHERE id_group = {int:guests}
  970. AND permission IN ({array_string:illegal_perms})',
  971. array(
  972. 'guests' => -1,
  973. 'illegal_perms' => $illegal_permissions,
  974. )
  975. );
  976. ---}
  977. ---#
  978. /******************************************************************************/
  979. --- Adding mail queue settings
  980. /******************************************************************************/
  981. ---#
  982. ---{
  983. if (empty($modSettings['mail_limit']))
  984. {
  985. $smcFunc['db_insert']('replace',
  986. '{db_prefix}settings',
  987. array('variable' => 'string-255', 'value' => 'string'),
  988. array(
  989. array('mail_limit', '5'),
  990. array('mail_quantity', '5'),
  991. ),
  992. array('variable')
  993. );
  994. }
  995. ---}
  996. ---#