upgrade_2-1_sqlite.sql 41 KB

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