upgrade_2-1_sqlite.sql 43 KB

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