upgrade_2-1_mysql.sql 41 KB

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