upgrade_2-1_sqlite.sql 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  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. ---# Adding new field_order column...
  557. ALTER TABLE {$db_prefix}custom_fields
  558. ADD COLUMN field_order smallint NOT NULL default '0';
  559. ---#
  560. ---# Insert fields
  561. 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
  562. ('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),
  563. ('cust_icq', 'ICQ', 'This is your ICQ number.', 'text', 12, '', 2, 'regex~[1-9][0-9]{4,9}~i', 0, 1, 'forumprofile', 0, 1, 0, 0, '', '<a class="icq" href="http://www.icq.com/whitepages/about_me.php?uin={INPUT}" target="_blank" title="ICQ - {INPUT}"><img src="http://status.icq.com/online.gif?img=5&icq={INPUT}" alt="ICQ - {INPUT}" width="18" height="18"></a>', 1),
  564. ('cust_skype', 'Skype', 'Your Skype name', 'text', 50, '', 3, 'email', 0, 1, 'forumprofile', 0, 1, 0, 0, '', '<a class="skype new_win" href="skype:{INPUT}?chat" title="Live - {INPUT}"><img src="{IMAGES_URL}/skype.png" alt="Live - {INPUT}"></a>', 1),
  565. ('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),
  566. ('cust_loca', 'Location', 'Geographic location.', 'text', 50, '', 5, 'email', 0, 1, 'forumprofile', 0, 1, 0, 0, '', '', 1),
  567. ('cust_gender', 'Gender', 'Your gender.', 'text', 50, '', 6, 'email', 0, 1, 'forumprofile', 0, 1, 0, 0, '', '', 1);
  568. ---#
  569. ---# Add an order value to each exiting cust profile field.
  570. ---{
  571. $old_cust_fields = upgrade_query("
  572. SELECT id_field
  573. FROM {$db_prefix}custom_fields");
  574. // We start counting from 7 because we already have the first 6 fields.
  575. $fields_count = 7;
  576. while ($row = mysql_fetch_assoc($old_cust_fields))
  577. {
  578. $fields_count++;
  579. upgrade_query("
  580. UPDATE {$db_prefix}custom_fields
  581. SET field_order = $fields_count,
  582. WHERE id_attach = $row[id_field]");
  583. }
  584. $smcFunc['db_free_result']($old_cust_fields);
  585. ---}
  586. ---#
  587. ---# Converting member values...
  588. ---{
  589. // We cannot do this twice
  590. if (@$modSettings['smfVersion'] < '2.1')
  591. {
  592. $request = upgrade_query("
  593. SELECT id_member, aim, icq, msn, yim, location, gender
  594. FROM {$db_prefix}members");
  595. $inserts = array();
  596. while ($row = mysql_fetch_assoc($request))
  597. {
  598. if (!empty($row[aim]))
  599. $inserts[] = "($row[id_member], -1, 'cust_aolins', $row[aim])";
  600. if (!empty($row[icq]))
  601. $inserts[] = "($row[id_member], -1, 'cust_icq', $row[icq])";
  602. if (!empty($row[msn]))
  603. $inserts[] = "($row[id_member], -1, 'cust_skype', $row[msn])";
  604. if (!empty($row[yim]))
  605. $inserts[] = "($row[id_member], -1, 'cust_yahoo', $row[yim])";
  606. if (!empty($row[location]))
  607. $inserts[] = "($row[id_member], -1, 'cust_loca', $row[location])";
  608. if (!empty($row[gender]))
  609. $inserts[] = "($row[id_member], -1, 'cust_gender', $row[gender])";
  610. }
  611. $smcFunc['db_free_result']($request);
  612. if (!empty($inserts))
  613. upgrade_query("
  614. INSERT INTO {$db_prefix}themes
  615. (id_member, id_theme, variable, value)
  616. VALUES
  617. " . implode(',', $inserts));
  618. }
  619. ---}
  620. ---#
  621. ---# Dropping old fields
  622. ALTER TABLE `{$db_prefix}members`
  623. DROP `icq`,
  624. DROP `aim`,
  625. DROP `yim`,
  626. DROP `msn`,
  627. DROP `location`,
  628. DROP `gender`;
  629. ---#
  630. /******************************************************************************/
  631. --- Adding support for drafts
  632. /******************************************************************************/
  633. ---# Creating drafts table.
  634. CREATE TABLE IF NOT EXISTS {$db_prefix}user_drafts (
  635. id_draft int unsigned NOT NULL auto_increment,
  636. id_topic int unsigned NOT NULL default '0',
  637. id_board smallint unsigned NOT NULL default '0',
  638. id_reply int unsigned NOT NULL default '0',
  639. type smallint NOT NULL default '0',
  640. poster_time int unsigned NOT NULL default '0',
  641. id_member int unsigned NOT NULL default '0',
  642. subject varchar(255) NOT NULL default '',
  643. smileys_enabled smallint NOT NULL default '1',
  644. body text NOT NULL,
  645. icon varchar(16) NOT NULL default 'xx',
  646. locked smallint NOT NULL default '0',
  647. is_sticky smallint NOT NULL default '0',
  648. to_list varchar(255) NOT NULL default '',
  649. PRIMARY KEY (id_draft)
  650. );
  651. CREATE UNIQUE INDEX {$db_prefix}user_drafts_id_member ON {$db_prefix}user_drafts (id_member, id_draft, type);
  652. ---#
  653. ---# Adding draft permissions...
  654. ---{
  655. // We cannot do this twice
  656. if (@$modSettings['smfVersion'] < '2.1')
  657. {
  658. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  659. $request = upgrade_query("
  660. SELECT id_group, id_board, add_deny, permission
  661. FROM {$db_prefix}board_permissions
  662. WHERE permission = 'post_unapproved_topics'");
  663. $inserts = array();
  664. while ($row = $smcFunc['db_fetch_assoc']($request))
  665. {
  666. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  667. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  668. }
  669. $smcFunc['db_free_result']($request);
  670. if (!empty($inserts))
  671. {
  672. foreach ($inserts AS $insert)
  673. {
  674. upgrade_query("
  675. INSERT INTO {$db_prefix}board_permissions
  676. (id_group, id_board, permission, add_deny)
  677. VALUES
  678. " . $insert);
  679. }
  680. }
  681. // Next we find people who can send PMs, and assume they can save pm_drafts as well
  682. $request = upgrade_query("
  683. SELECT id_group, add_deny, permission
  684. FROM {$db_prefix}permissions
  685. WHERE permission = 'pm_send'");
  686. $inserts = array();
  687. while ($row = $smcFunc['db_fetch_assoc']($request))
  688. {
  689. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  690. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  691. }
  692. $smcFunc['db_free_result']($request);
  693. if (!empty($inserts))
  694. {
  695. foreach ($inserts AS $insert)
  696. {
  697. upgrade_query("
  698. INSERT INTO {$db_prefix}permissions
  699. (id_group, permission, add_deny)
  700. VALUES
  701. " . $insert);
  702. }
  703. }
  704. }
  705. ---}
  706. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_autosave_enabled', '1');
  707. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_show_saved_enabled', '1');
  708. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_keep_days', '7');
  709. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_autosave_enabled', '1');
  710. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_show_saved_enabled', '1');
  711. ---#
  712. /******************************************************************************/
  713. --- Adding support for likes
  714. /******************************************************************************/
  715. ---# Creating likes table.
  716. CREATE TABLE IF NOT EXISTS {$db_prefix}user_likes (
  717. id_member int NOT NULL default '0',
  718. content_type char(6) default '',
  719. content_id int NOT NULL default '0',
  720. like_time int NOT NULL default '0',
  721. PRIMARY KEY (content_id, content_type, id_member)
  722. );
  723. CREATE INDEX {$db_prefix}user_likes_content ON {$db_prefix}user_likes (content_id, content_type);
  724. CREATE INDEX {$db_prefix}user_likes_liker ON {$db_prefix}user_likes (id_member);
  725. ---#
  726. ---# Adding count to the messages table.
  727. ALTER TABLE {$db_prefix}messages
  728. ADD COLUMN likes smallint NOT NULL default '0';
  729. ---#
  730. /******************************************************************************/
  731. --- Adding support for group-based board moderation
  732. /******************************************************************************/
  733. ---# Creating moderator_groups table
  734. CREATE TABLE IF NOT EXISTS {$db_prefix}moderator_groups (
  735. id_board smallint NOT NULL default '0',
  736. id_group smallint NOT NULL default '0',
  737. PRIMARY KEY (id_board, id_group)
  738. );
  739. ---#
  740. /******************************************************************************/
  741. --- Cleaning up integration hooks
  742. /******************************************************************************/
  743. ---#
  744. DELETE FROM {$db_prefix}settings
  745. WHERE variable LIKE 'integrate_%';
  746. ---#
  747. /******************************************************************************/
  748. --- Cleaning up old settings
  749. /******************************************************************************/
  750. ---# Updating the default time format
  751. ---{
  752. if (!empty($modSettings['time_format']))
  753. {
  754. // First, use the shortened form of the month in the date.
  755. $time_format = str_replace('%B', '%b', $modSettings['time_format']);
  756. // Second, shorten the time to stop including seconds.
  757. $time_format = str_replace(':%S', '', $time_format);
  758. // Then, update the database.
  759. $smcFunc['db_query']('', '
  760. UPDATE {db_prefix}settings
  761. SET value = {string:new_format}
  762. WHERE variable = {literal:time_format}',
  763. array(
  764. 'new_format' => $time_format,
  765. )
  766. );
  767. }
  768. ---}
  769. ---#
  770. ---# Fixing a deprecated option.
  771. UPDATE {$db_prefix}settings
  772. SET value = 'option_css_resize'
  773. WHERE variable = 'avatar_action_too_large'
  774. AND (value = 'option_html_resize' OR value = 'option_js_resize');
  775. ---#
  776. ---# Cleaning up the old Core Features page.
  777. ---{
  778. // First get the original value
  779. $request = $smcFunc['db_query']('', '
  780. SELECT value
  781. FROM {db_prefix}settings
  782. WHERE variable = {literal:admin_features}');
  783. if ($smcFunc['db_num_rows']($request) > 0 && $row = $smcFunc['db_fetch_assoc']($request))
  784. {
  785. // Some of these *should* already be set but you never know.
  786. $new_settings = array();
  787. $admin_features = explode(',', $row['value']);
  788. // Now, let's just recap something.
  789. // cd = calendar, should also have set cal_enabled already
  790. // cp = custom profile fields, which already has several fields that cover tracking
  791. // k = karma, should also have set karmaMode already
  792. // ps = paid subs, should also have set paid_enabled already
  793. // rg = reports generation, which is now permanently on
  794. // sp = spider tracking, should also have set spider_mode already
  795. // w = warning system, which will be covered with warning_settings
  796. // The rest we have to deal with manually.
  797. // Moderation log - modlog_enabled itself should be set but we have others now
  798. if (in_array('ml', $admin_features))
  799. {
  800. $new_settings[] = array('adminlog_enabled', '1');
  801. $new_settings[] = array('userlog_enabled', '1');
  802. }
  803. // Post moderation
  804. if (in_array('pm', $admin_features))
  805. {
  806. $new_settings[] = array('postmod_active', '1');
  807. }
  808. // And now actually apply it.
  809. if (!empty($new_settings))
  810. {
  811. $smcFunc['db_insert']('replace',
  812. '{db_prefix}settings',
  813. array('variable' => 'string', 'value' => 'string'),
  814. $new_settings,
  815. array('variable')
  816. );
  817. }
  818. }
  819. $smcFunc['db_free_result']($request);
  820. ---}
  821. ---#
  822. ---# Cleaning up old settings.
  823. DELETE FROM {$db_prefix}settings
  824. WHERE variable IN ('enableStickyTopics', 'guest_hideContacts', 'notify_new_registration', 'attachmentEncryptFilenames', 'hotTopicPosts', 'hotTopicVeryPosts', 'fixLongWords', 'admin_features', 'topbottomEnable', 'simpleSearch', 'enableVBStyleLogin');
  825. ---#
  826. ---# Cleaning up old theme settings.
  827. DELETE FROM {$db_prefix}themes
  828. WHERE variable IN ('show_board_desc', 'no_new_reply_warning', 'display_quick_reply', 'show_mark_read', 'show_member_bar', 'linktree_link');
  829. ---#
  830. /******************************************************************************/
  831. --- Updating files that fetched from simplemachines.org
  832. /******************************************************************************/
  833. ---# We no longer call on several files.
  834. DELETE FROM {$db_prefix}admin_info_files
  835. WHERE filename IN ('latest-packages.js', 'latest-support.js', 'latest-themes.js')
  836. AND path = '/smf/';
  837. ---#
  838. ---# But we do need new files.
  839. ---{
  840. $smcFunc['db_insert']('',
  841. '{db_prefix}admin_info_files',
  842. array('filename' => 'string', 'path' => 'string', 'parameters' => 'string', 'data' => 'string', 'filetype' => 'string'),
  843. array('latest-versions.txt', '/smf/', 'version=%3$s', '', 'text/plain'),
  844. array('id_file')
  845. );
  846. ---}
  847. ---#
  848. /******************************************************************************/
  849. --- Upgrading "verification questions" feature
  850. /******************************************************************************/
  851. ---# Creating qanda table
  852. CREATE TABLE IF NOT EXISTS {$db_prefix}qanda (
  853. id_question smallint(5) unsigned NOT NULL auto_increment,
  854. lngfile varchar(255) NOT NULL default '',
  855. question varchar(255) NOT NULL default '',
  856. answers text NOT NULL,
  857. PRIMARY KEY (id_question),
  858. KEY lngfile (lngfile)
  859. );
  860. ---#
  861. ---# Moving questions and answers to the new table
  862. ---{
  863. $questions = array();
  864. $get_questions = upgrade_query("
  865. SELECT body AS question, recipient_name AS answer
  866. FROM {$db_prefix}log_comments
  867. WHERE comment_type = 'ver_test'");
  868. while ($row = $smcFunc['db_fetch_assoc']($get_questions))
  869. $questions[] = array($language, $row['question'], serialize(array($row['answer'])));
  870. $smcFunc['db_free_result']($get_questions);
  871. if (!empty($questions))
  872. {
  873. $smcFunc['db_insert']('',
  874. '{db_prefix}qanda',
  875. array('lngfile' => 'string', 'question' => 'string', 'answers' => 'string'),
  876. $questions,
  877. array('id_question')
  878. );
  879. // Delete the questions from log_comments now
  880. upgrade_query("
  881. DELETE FROM {$db_prefix}log_comments
  882. WHERE comment_type = 'ver_test'
  883. ");
  884. }
  885. ---}
  886. ---#
  887. /******************************************************************************/
  888. --- Marking packages as uninstalled...
  889. /******************************************************************************/
  890. ---# Updating log_packages
  891. UPDATE {$db_prefix}log_packages
  892. SET install_state = 0;
  893. ---#
  894. /******************************************************************************/
  895. --- Updating profile permissions...
  896. /******************************************************************************/
  897. ---# Removing the old "view your own profile" permission
  898. DELETE FROM {$db_prefix}permissions
  899. WHERE permission = 'profile_view_own';
  900. ---#
  901. ---# Updating the old "view any profile" permission
  902. UPDATE {$db_prefix}permissions
  903. SET permission = 'profile_view'
  904. WHERE permission = 'profile_view_any';
  905. ---#
  906. ---# Removing the old notification permissions
  907. DELETE FROM {$db_prefix}board_permissions
  908. WHERE permission = 'mark_notify' OR permission = 'mark_any_notify';
  909. ---#
  910. ---# Removing the send-topic permission
  911. DELETE FROM {$db_prefix}board_permissions
  912. WHERE permission = 'send_topic';
  913. ---#
  914. ---# Adding "profile_password_own"
  915. ---{
  916. $inserts = array();
  917. $request = upgrade_query("
  918. SELECT id_group, add_deny
  919. FROM {$db_prefix}permissions
  920. WHERE permission = 'profile_identity_own'");
  921. while ($row = $smcFunc['db_fetch_assoc']($request))
  922. {
  923. $inserts[] = "($row[id_group], 'profile_password_own', $row[add_deny])";
  924. }
  925. $smcFunc['db_free_result']($request);
  926. if (!empty($inserts))
  927. {
  928. foreach ($inserts as $insert)
  929. {
  930. upgrade_query("
  931. INSERT INTO {$db_prefix}permissions
  932. (id_group, permission, add_deny)
  933. VALUES
  934. " . $insert);
  935. }
  936. }
  937. ---}
  938. ---#
  939. ---# Adding other profile permissions
  940. ---{
  941. $inserts = array();
  942. $request = upgrade_query("
  943. SELECT id_group, add_deny
  944. FROM {$db_prefix}permissions
  945. WHERE permission = 'profile_extra_own'");
  946. while ($row = $smcFunc['db_fetch_assoc']($request))
  947. {
  948. $inserts[] = "($row[id_group], 'profile_blurb_own', $row[add_deny])";
  949. $inserts[] = "($row[id_group], 'profile_displayed_name_own', $row[add_deny])";
  950. $inserts[] = "($row[id_group], 'profile_forum_own', $row[add_deny])";
  951. $inserts[] = "($row[id_group], 'profile_other_own', $row[add_deny])";
  952. $inserts[] = "($row[id_group], 'profile_signature_own', $row[add_deny])";
  953. }
  954. $smcFunc['db_free_result']($request);
  955. if (!empty($inserts))
  956. {
  957. foreach ($inserts as $insert)
  958. {
  959. upgrade_query("
  960. INSERT INTO {$db_prefix}permissions
  961. (id_group, permission, add_deny)
  962. VALUES
  963. " . $insert);
  964. }
  965. }
  966. ---}
  967. ---#
  968. /******************************************************************************/
  969. --- Upgrading PM labels...
  970. /******************************************************************************/
  971. ---# Adding pm_labels table...
  972. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labels (
  973. id_label integer primary key,
  974. id_member int NOT NULL default '0',
  975. name varchar(30) NOT NULL default '',
  976. );
  977. ---#
  978. ---# Adding pm_labeled_messages table...
  979. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labeled_messages (
  980. id_label int NOT NULL default '0',
  981. id_pm int NOT NULL default '0',
  982. PRIMARY KEY (id_label, id_pm)
  983. );
  984. ---#
  985. ---# Adding "in_inbox" column to pm_recipients
  986. ALTER TABLE {$db_prefix}pm_recipients
  987. ADD COLUMN in_inbox tinyint(3) NOT NULL default '1';
  988. ---#
  989. ---# Moving label info to new tables and updating rules...
  990. ---{
  991. // First see if we still have a message_labels column
  992. $results = $smcFunc['db_list_columns']('{db_prefix}members');
  993. if (in_array('message_labels', $results))
  994. {
  995. // They've still got it, so pull the label info
  996. $get_labels = $smcFunc['db_query']('', '
  997. SELECT id_member, message_labels
  998. FROM {db_prefix}members
  999. WHERE message_labels != {string:blank}',
  1000. array(
  1001. 'blank' => '',
  1002. )
  1003. );
  1004. $inserts = array();
  1005. $label_info = array();
  1006. while ($row = $smcFunc['db_fetch_assoc']($get_labels))
  1007. {
  1008. // Stick this in an array
  1009. $labels = explode(',', $row['message_labels']);
  1010. // Build some inserts
  1011. foreach ($labels AS $index => $label)
  1012. {
  1013. // Keep track of the index of this label - we'll need that in a bit...
  1014. $label_info[$row['id_member']][$label] = $index;
  1015. $inserts[] = array($row['id_member'], $label);
  1016. }
  1017. }
  1018. $smcFunc['db_free_result']($get_labels);
  1019. if (!empty($inserts))
  1020. {
  1021. $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'int'), $inserts, array());
  1022. // Clear this out for our next query below
  1023. $inserts = array();
  1024. }
  1025. // This is the easy part - update the inbox stuff
  1026. $smcFunc['db_query']('', '
  1027. UPDATE {db_prefix}pm_recipients
  1028. SET in_inbox = {int:in_inbox}
  1029. WHERE FIND_IN_SET({int:minus_one}, labels)',
  1030. array(
  1031. 'in_inbox' => 1,
  1032. 'minus_one' => -1,
  1033. )
  1034. );
  1035. // Now we go pull the new IDs for each label
  1036. $get_new_label_ids = $smcFunc['db_query']('', '
  1037. SELECT *
  1038. FROM {db_prefix}pm_labels',
  1039. array(
  1040. )
  1041. );
  1042. $label_info_2 = array();
  1043. while ($label_row = $smcFunc['db_fetch_assoc']($get_new_label_ids))
  1044. {
  1045. // Map the old index values to the new ID values...
  1046. $old_index = $label_info[$row['id_member']][$row['label_name']];
  1047. $label_info_2[$row['id_member']][$old_index] = $row['id_label'];
  1048. }
  1049. $smcFunc['db_free_result']($get_new_label_ids);
  1050. // Pull label info from pm_recipients
  1051. // Ignore any that are only in the inbox
  1052. $get_pm_labels = $smcFunc['db_query']('', '
  1053. SELECT id_pm, id_member, labels
  1054. FROM {db_prefix}pm_recipients
  1055. WHERE deleted = {int:not_deleted}
  1056. AND labels != {string:minus_one}',
  1057. array(
  1058. 'not_deleted' => 0,
  1059. 'minus_one' => -1,
  1060. )
  1061. );
  1062. while ($row = $smcFunc['db_fetch_assoc']($get_pm_labels))
  1063. {
  1064. $labels = explode(',', $row['labels']);
  1065. foreach ($labels as $a_label)
  1066. {
  1067. if ($a_label == '-1')
  1068. continue;
  1069. $new_label_info = $label_info_2[$row['id_member']][$a_label];
  1070. $inserts[] = array($row['id_pm'], $new_label_info);
  1071. }
  1072. }
  1073. $smcFunc['db_free_result']($get_pm_labels);
  1074. // Insert the new data
  1075. if (!empty($inserts))
  1076. {
  1077. $smcFunc['db_insert']('', '{db_prefix}pm_labeled_messages', array('id_pm', 'id_label'), $inserts, array());
  1078. }
  1079. // Final step of this ridiculously massive process
  1080. $get_pm_rules = $smcFunc['db_query']('', '
  1081. SELECT id_member, id_rule, actions
  1082. FROM {db_prefix}pm_rules',
  1083. array(
  1084. ),
  1085. );
  1086. // Go through the rules, unserialize the actions, then figure out if there's anything we can use
  1087. while ($row = $smcFunc['db_fetch_assoc']($get_pm_rules))
  1088. {
  1089. // Turn this into an array...
  1090. $actions = unserialize($row['actions']);
  1091. // Loop through the actions and see if we're applying a label anywhere
  1092. foreach ($actions as $index => $action)
  1093. {
  1094. if ($action['t'] == 'lab')
  1095. {
  1096. // Update the value of this label...
  1097. $actions[$index]['v'] = $label_info_2[$row['id_member']][$action['v']];
  1098. }
  1099. }
  1100. // Put this back into a string
  1101. $actions = serialize($actions);
  1102. $smcFunc['db_query']('', '
  1103. UPDATE {db_prefix}pm_rules
  1104. SET actions = {string:actions}
  1105. WHERE id_rule = {int:id_rule}',
  1106. array(
  1107. 'actions' => $actions,
  1108. 'id_rule' => $row['id_rule'],
  1109. )
  1110. );
  1111. }
  1112. $smcFunc['db_free_result']($get_pm_rules);
  1113. // Lastly, we drop the old columns
  1114. $smcFunc['db_remove_column']('{db_prefix}members', 'message_labels');
  1115. $smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
  1116. }
  1117. }
  1118. ******************************************************************************/
  1119. --- Adding support for edit reasons
  1120. /******************************************************************************/
  1121. ---# Adding "modified_reason" column to messages
  1122. ALTER TABLE {$db_prefix}messages
  1123. ADD COLUMN modified_reason varchar(255) NOT NULL default '';
  1124. ---#
  1125. /******************************************************************************/
  1126. --- Cleaning up guest permissions
  1127. /******************************************************************************/
  1128. ---# Removing permissions guests can no longer have...
  1129. ---{
  1130. $illegal_board_permissions = array(
  1131. 'announce_topic',
  1132. 'delete_any',
  1133. 'lock_any',
  1134. 'make_sticky',
  1135. 'merge_any',
  1136. 'modify_any',
  1137. 'modify_replies',
  1138. 'move_any',
  1139. 'poll_add_any',
  1140. 'poll_edit_any',
  1141. 'poll_lock_any',
  1142. 'poll_remove_any',
  1143. 'remove_any',
  1144. 'report_any',
  1145. 'split_any'
  1146. );
  1147. $illegal_permissions = array('calendar_edit_any', 'moderate_board', 'moderate_forum', 'send_email_to_members');
  1148. $smcFunc['db_query']('', '
  1149. DELETE FROM {db_prefix}board_permissions
  1150. WHERE id_group = {int:guests}
  1151. AND permission IN ({array_string:illegal_board_perms})',
  1152. array(
  1153. 'guests' => -1,
  1154. 'illegal_board_perms' => $illegal_board_permissions,
  1155. )
  1156. );
  1157. $smcFunc['db_query']('', '
  1158. DELETE FROM {db_prefix}permissions
  1159. WHERE id_group = {int:guests}
  1160. AND permission IN ({array_string:illegal_perms})',
  1161. array(
  1162. 'guests' => -1,
  1163. 'illegal_perms' => $illegal_permissions,
  1164. )
  1165. );
  1166. ---}
  1167. ---#
  1168. /******************************************************************************/
  1169. --- Adding mail queue settings
  1170. /******************************************************************************/
  1171. ---#
  1172. ---{
  1173. if (empty($modSettings['mail_limit']))
  1174. {
  1175. $smcFunc['db_insert']('replace',
  1176. '{db_prefix}settings',
  1177. array('variable' => 'string-255', 'value' => 'string'),
  1178. array(
  1179. array('mail_limit', '5'),
  1180. array('mail_quantity', '5'),
  1181. ),
  1182. array('variable')
  1183. );
  1184. }
  1185. ---}
  1186. ---#