upgrade_2-1_mysql.sql 41 KB

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