upgrade_2-1_sqlite.sql 42 KB

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