upgrade_2-1_sqlite.sql 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. /* ATTENTION: You don't need to run or use this file! The upgrade.php script does everything for you! */
  2. /******************************************************************************/
  3. --- Adding new settings...
  4. /******************************************************************************/
  5. ---# Adding login history...
  6. CREATE TABLE IF NOT EXISTS {$db_prefix}member_logins (
  7. id_login integer NOT NULL auto_increment,
  8. id_member integer NOT NULL,
  9. time integer NOT NULL,
  10. ip varchar(255) NOT NULL default '',
  11. ip2 varchar(255) NOT NULL default '',
  12. PRIMARY KEY id_login(id_login)
  13. KEY id_member (id_member)
  14. KEY time (time)
  15. );
  16. ---#
  17. ---# Copying the current package backup setting...
  18. ---{
  19. if (!isset($modSettings['package_make_full_backups']) && isset($modSettings['package_make_backups']))
  20. upgrade_query("
  21. INSERT INTO {$db_prefix}settings
  22. (variable, value)
  23. VALUES
  24. ('package_make_full_backups', '" . $modSettings['package_make_backups'] . "')");
  25. ---}
  26. ---#
  27. ---# Copying the current "allow users to disable word censor" setting...
  28. ---{
  29. if (!isset($modSettings['allow_no_censored']))
  30. {
  31. $request = upgrade_query("
  32. SELECT value
  33. FROM {$db_prefix}settings
  34. WHERE variable='allow_no_censored'
  35. AND id_theme = 1 OR id_theme = '$modSettings[theme_default]'
  36. ");
  37. // Is it set for either "default" or the one they've set as default?
  38. while ($row = $smcFunc['db_fetch_assoc']($request))
  39. {
  40. if ($row['value'] == 1)
  41. {
  42. upgrade_query("
  43. INSERT INTO {$db_prefix}settings
  44. VALUES ('allow_no_censored', 1)
  45. ");
  46. // Don't do this twice...
  47. break;
  48. }
  49. }
  50. }
  51. ---}
  52. ---#
  53. ---# Adding new "topic_move_any" setting
  54. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('topic_move_any', '1');
  55. ---#
  56. /******************************************************************************/
  57. --- Updating legacy attachments...
  58. /******************************************************************************/
  59. ---# Converting legacy attachments.
  60. ---{
  61. // Need to know a few things first.
  62. $custom_av_dir = !empty($modSettings['custom_avatar_dir']) ? $modSettings['custom_avatar_dir'] : $GLOBALS['boarddir'] .'/custom_avatar';
  63. // This little fellow has to cooperate...
  64. if (!is_writable($custom_av_dir))
  65. @chmod($custom_av_dir, 0777);
  66. $request = upgrade_query("
  67. SELECT MAX(id_attach)
  68. FROM {$db_prefix}attachments");
  69. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  70. $smcFunc['db_free_result']($request);
  71. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  72. $step_progress['name'] = 'Converting legacy attachments';
  73. $step_progress['current'] = $_GET['a'];
  74. // We may be using multiple attachment directories.
  75. if (!empty($modSettings['currentAttachmentUploadDir']) && !is_array($modSettings['attachmentUploadDir']))
  76. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  77. $is_done = false;
  78. while (!$is_done)
  79. {
  80. nextSubStep($substep);
  81. $fileHash = '';
  82. $request = upgrade_query("
  83. SELECT id_attach, id_folder, filename, file_hash
  84. FROM {$db_prefix}attachments
  85. WHERE attachment_type != 1
  86. LIMIT $_GET[a], 100");
  87. // Finished?
  88. if ($smcFunc['db_num_rows']($request) == 0)
  89. $is_done = true;
  90. while ($row = $smcFunc['db_fetch_assoc']($request))
  91. {
  92. // The current folder.
  93. $currentFolder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$row['id_folder']] : $modSettings['attachmentUploadDir'];
  94. // Old School?
  95. if (empty($row['file_hash']))
  96. {
  97. // Remove international characters (windows-1252)
  98. // These lines should never be needed again. Still, behave.
  99. if (empty($db_character_set) || $db_character_set != 'utf8')
  100. {
  101. $row['filename'] = strtr($row['filename'],
  102. "\x8a\x8e\x9a\x9e\x9f\xc0\xc1\xc2\xc3\xc4\xc5\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xe0\xe1\xe2\xe3\xe4\xe5\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xff",
  103. 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
  104. $row['filename'] = strtr($row['filename'], array("\xde" => 'TH', "\xfe" =>
  105. 'th', "\xd0" => 'DH', "\xf0" => 'dh', "\xdf" => 'ss', "\x8c" => 'OE',
  106. "\x9c" => 'oe', "\xc6" => 'AE', "\xe6" => 'ae', "\xb5" => 'u'));
  107. }
  108. // Sorry, no spaces, dots, or anything else but letters allowed.
  109. $row['filename'] = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $row['filename']);
  110. // Create a nice hash.
  111. $fileHash = sha1(md5($row['filename'] . time()) . mt_rand());
  112. // The old file, we need to know if the filename was encrypted or not.
  113. if (file_exists($currentFolder . '/' . $row['id_attach']. '_' . strtr($row['filename'], '.', '_') . md5($row['filename'])))
  114. $oldFile = $currentFolder . '/' . $row['id_attach']. '_' . strtr($row['filename'], '.', '_') . md5($row['filename']);
  115. else if (file_exists($currentFolder . '/' . $row['filename']));
  116. $oldFile = $currentFolder . '/' . $row['filename'];
  117. // Build the new file.
  118. $newFile = $currentFolder . '/' . $row['id_attach'] . '_' . $fileHash .'.dat';
  119. }
  120. // Just rename the file.
  121. else
  122. {
  123. $oldFile = $currentFolder . '/' . $row['id_attach'] . '_' . $row['file_hash'];
  124. $newFile = $currentFolder . '/' . $row['id_attach'] . '_' . $row['file_hash'] .'.dat';
  125. }
  126. // Check if the av is an attachment
  127. if ($row['id_member'] != 0)
  128. if (rename($oldFile, $custom_av_dir . '/' . $row['filename']))
  129. upgrade_query("
  130. UPDATE {$db_prefix}attachments
  131. SET file_hash = '', attachment_type = 1
  132. WHERE id_attach = $row[id_attach]");
  133. // Just a regular attachment.
  134. else
  135. rename($oldFile, $newFile);
  136. // Only update this if it was successful and the file was using the old system.
  137. if (empty($row['file_hash']) && !empty($fileHash) && file_exists($newFile) && !file_exists($oldFile))
  138. upgrade_query("
  139. UPDATE {$db_prefix}attachments
  140. SET file_hash = '$fileHash'
  141. WHERE id_attach = $row[id_attach]");
  142. }
  143. $smcFunc['db_free_result']($request);
  144. $_GET['a'] += 100;
  145. $step_progress['current'] = $_GET['a'];
  146. }
  147. unset($_GET['a']);
  148. ---}
  149. ---#
  150. /******************************************************************************/
  151. --- Adding support for IPv6...
  152. /******************************************************************************/
  153. ---# Adding new columns to ban items...
  154. ALTER TABLE {$db_prefix}ban_items
  155. ADD COLUMN ip_low5 smallint(255) unsigned NOT NULL DEFAULT '0',
  156. ADD COLUMN ip_high5 smallint(255) unsigned NOT NULL DEFAULT '0',
  157. ADD COLUMN ip_low6 smallint(255) unsigned NOT NULL DEFAULT '0',
  158. ADD COLUMN ip_high6 smallint(255) unsigned NOT NULL DEFAULT '0',
  159. ADD COLUMN ip_low7 smallint(255) unsigned NOT NULL DEFAULT '0',
  160. ADD COLUMN ip_high7 smallint(255) unsigned NOT NULL DEFAULT '0',
  161. ADD COLUMN ip_low8 smallint(255) unsigned NOT NULL DEFAULT '0',
  162. ADD COLUMN ip_high8 smallint(255) unsigned NOT NULL DEFAULT '0';
  163. ---#
  164. ---# Changing existing columns to ban items...
  165. ALTER TABLE {$db_prefix}ban_items
  166. CHANGE ip_low1 ip_low1 smallint(255) unsigned NOT NULL DEFAULT '0',
  167. CHANGE ip_high1 ip_high1 smallint(255) unsigned NOT NULL DEFAULT '0',
  168. CHANGE ip_low2 ip_low2 smallint(255) unsigned NOT NULL DEFAULT '0',
  169. CHANGE ip_high2 ip_high2 smallint(255) unsigned NOT NULL DEFAULT '0',
  170. CHANGE ip_low3 ip_low3 smallint(255) unsigned NOT NULL DEFAULT '0',
  171. CHANGE ip_high3 ip_high3 smallint(255) unsigned NOT NULL DEFAULT '0',
  172. CHANGE ip_low4 ip_low4 smallint(255) unsigned NOT NULL DEFAULT '0',
  173. CHANGE ip_high4 ip_high4 smallint(255) unsigned NOT NULL DEFAULT '0';
  174. ---#
  175. /******************************************************************************/
  176. --- Adding support for <credits> tag in package manager
  177. /******************************************************************************/
  178. ---# Adding new columns to log_packages ..
  179. ALTER TABLE {$db_prefix}log_packages
  180. ADD COLUMN credits varchar(255) NOT NULL DEFAULT '';
  181. ---#
  182. /******************************************************************************/
  183. --- Adding more space for session ids
  184. /******************************************************************************/
  185. ---# Altering the session_id columns...
  186. ALTER TABLE {$db_prefix}log_online
  187. CHANGE `session` `session` varchar(64) NOT NULL DEFAULT '';
  188. ALTER TABLE {$db_prefix}log_errors
  189. CHANGE `session` `session` char(64) NOT NULL default ' ';
  190. ALTER TABLE {$db_prefix}sessions
  191. CHANGE `session_id` `session_id` char(64) NOT NULL;
  192. ---#
  193. /******************************************************************************/
  194. --- Adding new columns for MOVED topic updates
  195. /******************************************************************************/
  196. ---# Adding new custom fields columns.
  197. ---{
  198. $smcFunc['db_alter_table']('{db_prefix}topics', array(
  199. 'add' => array(
  200. 'redirect_expires' => array(
  201. 'name' => 'redirect_expires',
  202. 'null' => false,
  203. 'default' => '0',
  204. 'type' => 'int',
  205. 'auto' => false,
  206. ),
  207. )
  208. ));
  209. $smcFunc['db_alter_table']('{db_prefix}topics', array(
  210. 'add' => array(
  211. 'id_redirect_topic' => array(
  212. 'name' => 'id_redirect_topic',
  213. 'null' => false,
  214. 'default' => '0',
  215. 'type' => 'int',
  216. 'auto' => false,
  217. ),
  218. )
  219. ));
  220. ---}
  221. ---#
  222. /******************************************************************************/
  223. --- Adding new scheduled tasks
  224. /******************************************************************************/
  225. ---# Adding new scheduled tasks
  226. INSERT INTO {$db_prefix}scheduled_tasks
  227. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  228. VALUES
  229. (0, 120, 1, 'd', 0, 'remove_temp_attachments');
  230. INSERT INTO {$db_prefix}scheduled_tasks
  231. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  232. VALUES
  233. (0, 180, 1, 'd', 0, 'remove_topic_redirect');
  234. INSERT INTO {$db_prefix}scheduled_tasks
  235. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  236. VALUES
  237. (0, 240, 1, 'd', 0, 'remove_old_drafts');
  238. ---#
  239. /******************************************************************************/
  240. ---- Adding background tasks support
  241. /******************************************************************************/
  242. ---# Adding the new table
  243. CREATE TABLE IF NOT EXISTS {$db_prefix}background_tasks (
  244. id_task integer primary key,
  245. task_file varchar(255) NOT NULL default '',
  246. task_class varchar(255) NOT NULL default '',
  247. task_data text NOT NULL,
  248. claimed_time int NOT NULL default '0',
  249. PRIMARY KEY (id_task)
  250. );
  251. ---#
  252. /******************************************************************************/
  253. ---- Replacing MSN with Skype
  254. /******************************************************************************/
  255. ---# Modifying the "msn" column...
  256. ALTER TABLE {$db_prefix}members
  257. CHANGE msn skype varchar(255) NOT NULL DEFAULT '';
  258. ---#
  259. /******************************************************************************/
  260. --- Adding support for deny boards access
  261. /******************************************************************************/
  262. ---# Adding new columns to boards...
  263. ---{
  264. $smcFunc['db_alter_table']('{db_prefix}boards', array(
  265. 'add' => array(
  266. 'deny_member_groups' => array(
  267. 'name' => 'deny_member_groups',
  268. 'null' => false,
  269. 'default' => '',
  270. 'type' => varchar,
  271. 'size' => 255,
  272. 'auto' => false,
  273. ),
  274. )
  275. ));
  276. ---}
  277. ---#
  278. /******************************************************************************/
  279. --- Adding support for category descriptions
  280. /******************************************************************************/
  281. ---# Adding new columns to categories...
  282. ---{
  283. $smcFunc['db_alter_table']('{db_prefix}log_topics', array(
  284. 'add' => array(
  285. 'description' => array(
  286. 'name' => 'description',
  287. 'null' => false,
  288. 'type' => 'text',
  289. 'auto' => false,
  290. ),
  291. )
  292. ));
  293. ---}
  294. ---#
  295. /******************************************************************************/
  296. --- Adding support for alerts
  297. /******************************************************************************/
  298. ---# Adding the count to the members table...
  299. ---{
  300. $smcFunc['db_alter_table']('{db_prefix}members', array(
  301. 'add' => array(
  302. 'alerts' => array(
  303. 'name' => 'ualerts',
  304. 'null' => false,
  305. 'default' => 0,
  306. 'type' => 'int',
  307. 'auto' => false,
  308. ),
  309. )
  310. ));
  311. ---}
  312. ---#
  313. ---# Adding the new table for alerts.
  314. CREATE TABLE IF NOT EXISTS {$db_prefix}user_alerts (
  315. id_alert int primary key,
  316. alert_time int unsigned NOT NULL default '0',
  317. id_member int unsigned NOT NULL default '0',
  318. id_member_started int unsigned NOT NULL default '0',
  319. member_name varchar(255) NOT NULL default '',
  320. content_type varchar(255) NOT NULL default '',
  321. content_id int unsigned NOT NULL default '0',
  322. content_action varchar(255) NOT NULL default '',
  323. is_read smallint unsigned NOT NULL default '0',
  324. extra text NOT NULL,
  325. PRIMARY KEY (id_alert)
  326. );
  327. CREATE INDEX {$db_prefix}user_alerts_id_member ON {$db_prefix}user_alerts (id_member);
  328. CREATE INDEX {$db_prefix}user_alerts_alert_time ON {$db_prefix}user_alerts (alert_time);
  329. ---#
  330. ---# Adding alert preferences.
  331. CREATE TABLE IF NOT EXISTS {$db_prefix}user_alerts_prefs (
  332. id_member int unsigned NOT NULL default '0',
  333. alert_pref varchar(32) NOT NULL default '',
  334. alert_value tinyint(3) NOT NULL default '0',
  335. PRIMARY KEY (id_member, alert_pref)
  336. );
  337. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'member_group_request', 1);
  338. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'member_register', 1);
  339. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_like', 1);
  340. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report', 1);
  341. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report_reply', 1);
  342. ---#
  343. /******************************************************************************/
  344. --- Adding support for topic unwatch
  345. /******************************************************************************/
  346. ---# Adding new columns to log_topics...
  347. ---{
  348. $smcFunc['db_alter_table']('{db_prefix}log_topics', array(
  349. 'add' => array(
  350. 'unwatched' => array(
  351. 'name' => 'unwatched',
  352. 'null' => false,
  353. 'default' => 0,
  354. 'type' => 'int',
  355. 'auto' => false,
  356. ),
  357. )
  358. ));
  359. UPDATE {$db_prefix}log_topics
  360. SET unwatched = 0;
  361. INSERT INTO {$db_prefix}settings
  362. (variable, value)
  363. VALUES
  364. ('enable_unwatch', 0);
  365. ---}
  366. ---#
  367. ---# Fixing column name change...
  368. ---{
  369. $smcFunc['db_alter_table']('{db_prefix}log_topics', array(
  370. 'change' => array(
  371. 'disregarded' => array(
  372. 'name' => 'unwatched',
  373. 'null' => false,
  374. 'default' => 0,
  375. 'type' => 'int',
  376. 'auto' => false,
  377. ),
  378. )
  379. ));
  380. ---}
  381. ---#
  382. /******************************************************************************/
  383. --- Name changes
  384. /******************************************************************************/
  385. ---# Altering the membergroup stars to icons
  386. ---{
  387. upgrade_query("
  388. ALTER TABLE {$db_prefix}membergroups
  389. CHANGE `stars` `icons` varchar(255) NOT NULL DEFAULT ''");
  390. ---}
  391. ---#
  392. ---# Renaming default theme...
  393. UPDATE {$db_prefix}themes
  394. SET value = 'SMF Default Theme - Curve2'
  395. WHERE value LIKE 'SMF Default Theme%';
  396. ---#
  397. ---# Adding the enableThemes setting.
  398. INSERT INTO {$db_prefix}settings
  399. (variable, value)
  400. VALUES
  401. ('enableThemes', '1');
  402. ---#
  403. ---# Setting "default" as the default...
  404. UPDATE {$db_prefix}settings
  405. SET value = '1'
  406. WHERE variable = 'theme_guests';
  407. UPDATE {$db_prefix}boards
  408. SET id_theme = 0;
  409. UPDATE {$db_prefix}members
  410. SET id_theme = 0;
  411. ---#
  412. /******************************************************************************/
  413. --- Cleaning up after old themes...
  414. /******************************************************************************/
  415. ---# Checking for "core" and removing it if necessary...
  416. ---{
  417. // Do they have "core" installed?
  418. if (file_exists($GLOBALS['boarddir'] . '/Themes/core'))
  419. {
  420. $core_dir = $GLOBALS['boarddir'] . '/Themes/core';
  421. $theme_request = upgrade_query("
  422. SELECT id_theme
  423. FROM {$db_prefix}themes
  424. WHERE variable = 'theme_dir'
  425. AND value ='$core_dir'");
  426. // Don't do anything if this theme is already uninstalled
  427. if ($smcFunc['db_num_rows']($theme_request) == 1)
  428. {
  429. list($id_theme) = $smcFunc['db_fetch_row']($theme_request, 0);
  430. $smcFunc['db_free_result']($theme_request);
  431. $known_themes = explode(', ', $modSettings['knownThemes']);
  432. // Remove this value...
  433. $known_themes = array_diff($known_themes, array($id_theme));
  434. // Change back to a string...
  435. $known_themes = implode(', ', $known_themes);
  436. // Update the database
  437. upgrade_query("
  438. UPDATE {$db_prefix}settings
  439. SET value = '$known_themes'
  440. WHERE variable = 'knownThemes'");
  441. // Delete any info about this theme
  442. upgrade_query("
  443. DELETE FROM {$db_prefix}themes
  444. WHERE id_theme = $id_theme");
  445. }
  446. }
  447. /******************************************************************************/
  448. --- Adding support for drafts
  449. /******************************************************************************/
  450. ---# Creating drafts table.
  451. CREATE TABLE IF NOT EXISTS {$db_prefix}user_drafts (
  452. id_draft int unsigned NOT NULL auto_increment,
  453. id_topic int unsigned NOT NULL default '0',
  454. id_board smallint unsigned NOT NULL default '0',
  455. id_reply int unsigned NOT NULL default '0',
  456. type smallint NOT NULL default '0',
  457. poster_time int unsigned NOT NULL default '0',
  458. id_member int unsigned NOT NULL default '0',
  459. subject varchar(255) NOT NULL default '',
  460. smileys_enabled smallint NOT NULL default '1',
  461. body text NOT NULL,
  462. icon varchar(16) NOT NULL default 'xx',
  463. locked smallint NOT NULL default '0',
  464. is_sticky smallint NOT NULL default '0',
  465. to_list varchar(255) NOT NULL default '',
  466. PRIMARY KEY (id_draft)
  467. );
  468. CREATE UNIQUE INDEX {$db_prefix}user_drafts_id_member ON {$db_prefix}user_drafts (id_member, id_draft, type);
  469. ---#
  470. ---# Adding draft permissions...
  471. ---{
  472. // We cannot do this twice
  473. if (@$modSettings['smfVersion'] < '2.1')
  474. {
  475. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  476. $request = upgrade_query("
  477. SELECT id_group, id_board, add_deny, permission
  478. FROM {$db_prefix}board_permissions
  479. WHERE permission = 'post_unapproved_topics'");
  480. $inserts = array();
  481. while ($row = $smcFunc['db_fetch_assoc']($request))
  482. {
  483. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  484. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  485. }
  486. $smcFunc['db_free_result']($request);
  487. if (!empty($inserts))
  488. {
  489. foreach ($inserts AS $insert)
  490. {
  491. upgrade_query("
  492. INSERT INTO {$db_prefix}board_permissions
  493. (id_group, id_board, permission, add_deny)
  494. VALUES
  495. " . $insert);
  496. }
  497. }
  498. // Next we find people who can send PMs, and assume they can save pm_drafts as well
  499. $request = upgrade_query("
  500. SELECT id_group, add_deny, permission
  501. FROM {$db_prefix}permissions
  502. WHERE permission = 'pm_send'");
  503. $inserts = array();
  504. while ($row = $smcFunc['db_fetch_assoc']($request))
  505. {
  506. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  507. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  508. }
  509. $smcFunc['db_free_result']($request);
  510. if (!empty($inserts))
  511. {
  512. foreach ($inserts AS $insert)
  513. {
  514. upgrade_query("
  515. INSERT INTO {$db_prefix}permissions
  516. (id_group, permission, add_deny)
  517. VALUES
  518. " . $insert);
  519. }
  520. }
  521. }
  522. ---}
  523. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_autosave_enabled', '1');
  524. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_show_saved_enabled', '1');
  525. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_keep_days', '7');
  526. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_autosave_enabled', '1');
  527. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_show_saved_enabled', '1');
  528. ---#
  529. /******************************************************************************/
  530. --- Adding support for likes
  531. /******************************************************************************/
  532. ---# Creating likes table.
  533. CREATE TABLE IF NOT EXISTS {$db_prefix}user_likes (
  534. id_member int NOT NULL default '0',
  535. content_type char(6) default '',
  536. content_id int NOT NULL default '0',
  537. like_time int NOT NULL default '0',
  538. PRIMARY KEY (content_id, content_type, id_member)
  539. );
  540. CREATE INDEX {$db_prefix}user_likes_content ON {$db_prefix}user_likes (content_id, content_type);
  541. CREATE INDEX {$db_prefix}user_likes_liker ON {$db_prefix}user_likes (id_member);
  542. ---#
  543. ---# Adding count to the messages table.
  544. ALTER TABLE {$db_prefix}messages
  545. ADD COLUMN likes smallint NOT NULL default '0';
  546. ---#
  547. /******************************************************************************/
  548. --- Adding support for group-based board moderation
  549. /******************************************************************************/
  550. ---# Creating moderator_groups table
  551. CREATE TABLE IF NOT EXISTS {$db_prefix}moderator_groups (
  552. id_board smallint NOT NULL default '0',
  553. id_group smallint NOT NULL default '0',
  554. PRIMARY KEY (id_board, id_group)
  555. );
  556. ---#
  557. /******************************************************************************/
  558. --- Cleaning up integration hooks
  559. /******************************************************************************/
  560. ---#
  561. DELETE FROM {$db_prefix}settings
  562. WHERE variable LIKE 'integrate_%';
  563. ---#
  564. /******************************************************************************/
  565. --- Cleaning up old settings
  566. /******************************************************************************/
  567. ---# Showing contact details to guests should never happen.
  568. DELETE FROM {$db_prefix}settings
  569. WHERE variable IN ('enableStickyTopics', 'guest_hideContacts', 'notify_new_registration', 'attachmentEncryptFilenames');
  570. ---#
  571. ---# Cleaning up old theme settings.
  572. DELETE FROM {$db_prefix}themes
  573. WHERE variable IN ('show_board_desc', 'no_new_reply_warning');
  574. ---#
  575. /******************************************************************************/
  576. --- Removing old Simple Machines files we do not need to fetch any more
  577. /******************************************************************************/
  578. ---# We no longer call on the latest packages list.
  579. DELETE FROM {$db_prefix}admin_info_files
  580. WHERE filename IN ('latest-packages.js', 'latest-support.js', 'latest-themes.js')
  581. AND path = '/smf/';
  582. ---#
  583. /******************************************************************************/
  584. --- Upgrading "verification questions" feature
  585. /******************************************************************************/
  586. ---# Creating qanda table
  587. CREATE TABLE IF NOT EXISTS {$db_prefix}qanda (
  588. id_question smallint(5) unsigned NOT NULL auto_increment,
  589. lngfile varchar(255) NOT NULL default '',
  590. question varchar(255) NOT NULL default '',
  591. answers text NOT NULL,
  592. PRIMARY KEY (id_question),
  593. KEY lngfile (lngfile)
  594. );
  595. ---#
  596. ---# Moving questions and answers to the new table
  597. ---{
  598. $questions = array();
  599. $get_questions = upgrade_query("
  600. SELECT body AS question, recipient_name AS answer
  601. FROM {$db_prefix}log_comments
  602. WHERE comment_type = 'ver_test'");
  603. while ($row = $smcFunc['db_fetch_assoc']($get_questions))
  604. $questions[] = array($language, $row['question'], serialize(array($row['answer'])));
  605. $smcFunc['db_free_result']($get_questions);
  606. if (!empty($questions))
  607. {
  608. $smcFunc['db_insert']('',
  609. '{db_prefix}qanda',
  610. array('lngfile' => 'string', 'question' => 'string', 'answers' => 'string'),
  611. $questions,
  612. array('id_question')
  613. );
  614. // Delete the questions from log_comments now
  615. upgrade_query("
  616. DELETE FROM {$db_prefix}log_comments
  617. WHERE comment_type = 'ver_test'
  618. ");
  619. }
  620. ---}
  621. ---#
  622. /******************************************************************************/
  623. --- Marking packages as uninstalled...
  624. /******************************************************************************/
  625. ---# Updating log_packages
  626. UPDATE {$db_prefix}log_packages
  627. SET install_state = 0;
  628. ---#
  629. /******************************************************************************/
  630. --- Updating profile permissions...
  631. /******************************************************************************/
  632. ---# Removing the old "view your own profile" permission
  633. DELETE FROM {$db_prefix}permissions
  634. WHERE permission = 'profile_view_own';
  635. ---#
  636. ---# Updating the old "view any profile" permission
  637. UPDATE {$db_prefix}permissions
  638. SET permission = 'profile_view'
  639. WHERE permission = 'profile_view_any';
  640. ---#
  641. ---# Removing the old notification permissions
  642. DELETE FROM {$db_prefix}board_permissions
  643. WHERE permission = 'mark_notify' OR permission = 'mark_any_notify';
  644. ---#
  645. ---# Adding "profile_password_own"
  646. ---{
  647. $inserts = array();
  648. $request = upgrade_query("
  649. SELECT id_group, add_deny
  650. FROM {$db_prefix}permissions
  651. WHERE permission = 'profile_identity_own'");
  652. while ($row = $smcFunc['db_fetch_assoc']($request))
  653. {
  654. $inserts[] = "($row[id_group], 'profile_password_own', $row[add_deny])";
  655. }
  656. $smcFunc['db_free_result']($request);
  657. if (!empty($inserts))
  658. {
  659. foreach ($inserts as $insert)
  660. {
  661. upgrade_query("
  662. INSERT INTO {$db_prefix}permissions
  663. (id_group, permission, add_deny)
  664. VALUES
  665. " . $insert);
  666. }
  667. }
  668. ---}
  669. ---#
  670. ---# Adding other profile permissions
  671. ---{
  672. $inserts = array();
  673. $request = upgrade_query("
  674. SELECT id_group, add_deny
  675. FROM {$db_prefix}permissions
  676. WHERE permission = 'profile_extra_own'");
  677. while ($row = $smcFunc['db_fetch_assoc']($request))
  678. {
  679. $inserts[] = "($row[id_group], 'profile_blurb_own', $row[add_deny])";
  680. $inserts[] = "($row[id_group], 'profile_displayed_name_own', $row[add_deny])";
  681. $inserts[] = "($row[id_group], 'profile_forum_own', $row[add_deny])";
  682. $inserts[] = "($row[id_group], 'profile_other_own', $row[add_deny])";
  683. $inserts[] = "($row[id_group], 'profile_signature_own', $row[add_deny])";
  684. }
  685. $smcFunc['db_free_result']($request);
  686. if (!empty($inserts))
  687. {
  688. foreach ($inserts as $insert)
  689. {
  690. upgrade_query("
  691. INSERT INTO {$db_prefix}permissions
  692. (id_group, permission, add_deny)
  693. VALUES
  694. " . $insert);
  695. }
  696. }
  697. ---}
  698. ---#
  699. /******************************************************************************/
  700. --- Upgrading PM labels...
  701. /******************************************************************************/
  702. ---# Adding pm_labels table...
  703. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labels (
  704. id_label integer primary key,
  705. id_member int NOT NULL default '0',
  706. name varchar(30) NOT NULL default '',
  707. );
  708. ---#
  709. ---# Adding pm_labeled_messages table...
  710. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labeled_messages (
  711. id_label int NOT NULL default '0',
  712. id_pm int NOT NULL default '0',
  713. PRIMARY KEY (id_label, id_pm)
  714. );
  715. ---#
  716. ---# Adding "in_inbox" column to pm_recipients
  717. ALTER TABLE {$db_prefix}pm_recipients
  718. ADD COLUMN in_inbox tinyint(3) NOT NULL default '1';
  719. ---#
  720. ---# Moving label info to new tables and updating rules...
  721. ---{
  722. // First see if we still have a message_labels column
  723. $results = $smcFunc['db_list_columns']('{db_prefix}members');
  724. if (in_array('message_labels', $results))
  725. {
  726. // They've still got it, so pull the label info
  727. $get_labels = $smcFunc['db_query']('', '
  728. SELECT id_member, message_labels
  729. FROM {db_prefix}members
  730. WHERE message_labels != {string:blank}',
  731. array(
  732. 'blank' => '',
  733. )
  734. );
  735. $inserts = array();
  736. $label_info = array();
  737. while ($row = $smcFunc['db_fetch_assoc']($get_labels))
  738. {
  739. // Stick this in an array
  740. $labels = explode(',', $row['message_labels']);
  741. // Build some inserts
  742. foreach ($labels AS $index => $label)
  743. {
  744. // Keep track of the index of this label - we'll need that in a bit...
  745. $label_info[$row['id_member']][$label] = $index;
  746. $inserts[] = array($row['id_member'], $label);
  747. }
  748. }
  749. $smcFunc['db_free_result']($get_labels);
  750. if (!empty($inserts))
  751. {
  752. $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'int'), $inserts, array());
  753. // Clear this out for our next query below
  754. $inserts = array();
  755. }
  756. // This is the easy part - update the inbox stuff
  757. $smcFunc['db_query']('', '
  758. UPDATE {db_prefix}pm_recipients
  759. SET in_inbox = {int:in_inbox}
  760. WHERE FIND_IN_SET({int:minus_one}, labels)',
  761. array(
  762. 'in_inbox' => 1,
  763. 'minus_one' => -1,
  764. )
  765. );
  766. // Now we go pull the new IDs for each label
  767. $get_new_label_ids = $smcFunc['db_query']('', '
  768. SELECT *
  769. FROM {db_prefix}pm_labels',
  770. array(
  771. )
  772. );
  773. $label_info_2 = array();
  774. while ($label_row = $smcFunc['db_fetch_assoc']($get_new_label_ids))
  775. {
  776. // Map the old index values to the new ID values...
  777. $old_index = $label_info[$row['id_member']][$row['label_name']];
  778. $label_info_2[$row['id_member']][$old_index] = $row['id_label'];
  779. }
  780. $smcFunc['db_free_result']($get_new_label_ids);
  781. // Pull label info from pm_recipients
  782. // Ignore any that are only in the inbox
  783. $get_pm_labels = $smcFunc['db_query']('', '
  784. SELECT id_pm, id_member, labels
  785. FROM {db_prefix}pm_recipients
  786. WHERE deleted = {int:not_deleted}
  787. AND labels != {string:minus_one}',
  788. array(
  789. 'not_deleted' => 0,
  790. 'minus_one' => -1,
  791. )
  792. );
  793. while ($row = $smcFunc['db_fetch_assoc']($get_pm_labels))
  794. {
  795. $labels = explode(',', $row['labels']);
  796. foreach ($labels as $a_label)
  797. {
  798. if ($a_label == '-1')
  799. continue;
  800. $new_label_info = $label_info_2[$row['id_member']][$a_label];
  801. $inserts[] = array($row['id_pm'], $new_label_info);
  802. }
  803. }
  804. $smcFunc['db_free_result']($get_pm_labels);
  805. // Insert the new data
  806. if (!empty($inserts))
  807. {
  808. $smcFunc['db_insert']('', '{db_prefix}pm_labeled_messages', array('id_pm', 'id_label'), $inserts, array());
  809. }
  810. // Final step of this ridiculously massive process
  811. $get_pm_rules = $smcFunc['db_query']('', '
  812. SELECT id_member, id_rule, actions
  813. FROM {db_prefix}pm_rules',
  814. array(
  815. ),
  816. );
  817. // Go through the rules, unserialize the actions, then figure out if there's anything we can use
  818. while ($row = $smcFunc['db_fetch_assoc']($get_pm_rules))
  819. {
  820. // Turn this into an array...
  821. $actions = unserialize($row['actions']);
  822. // Loop through the actions and see if we're applying a label anywhere
  823. foreach ($actions as $index => $action)
  824. {
  825. if ($action['t'] == 'lab')
  826. {
  827. // Update the value of this label...
  828. $actions[$index]['v'] = $label_info_2[$row['id_member']][$action['v']];
  829. }
  830. }
  831. // Put this back into a string
  832. $actions = serialize($actions);
  833. $smcFunc['db_query']('', '
  834. UPDATE {db_prefix}pm_rules
  835. SET actions = {string:actions}
  836. WHERE id_rule = {int:id_rule}',
  837. array(
  838. 'actions' => $actions,
  839. 'id_rule' => $row['id_rule'],
  840. )
  841. );
  842. }
  843. $smcFunc['db_free_result']($get_pm_rules);
  844. // Lastly, we drop the old columns
  845. $smcFunc['db_remove_column']('{db_prefix}members', 'message_labels');
  846. $smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
  847. }
  848. }
  849. ******************************************************************************/
  850. --- Adding support for edit reasons
  851. /******************************************************************************/
  852. ---# Adding "modified_reason" column to messages
  853. ALTER TABLE {$db_prefix}messages
  854. ADD COLUMN modified_reason varchar(255) NOT NULL default '';
  855. ---#
  856. /******************************************************************************/
  857. --- Cleaning up guest permissions
  858. /******************************************************************************/
  859. ---# Removing permissions guests can no longer have...
  860. ---{
  861. $illegal_board_permissions = array(
  862. 'announce_topic',
  863. 'delete_any',
  864. 'lock_any',
  865. 'make_sticky',
  866. 'merge_any',
  867. 'modify_any',
  868. 'modify_replies',
  869. 'move_any',
  870. 'poll_add_any',
  871. 'poll_edit_any',
  872. 'poll_lock_any',
  873. 'poll_remove_any',
  874. 'remove_any',
  875. 'report_any',
  876. 'split_any'
  877. );
  878. $illegal_permissions = array('calendar_edit_any', 'moderate_board', 'moderate_forum', 'send_email_to_members');
  879. $smcFunc['db_query']('', '
  880. DELETE FROM {db_prefix}board_permissions
  881. WHERE id_group = {int:guests}
  882. AND permission IN ({array_string:illegal_board_perms})',
  883. array(
  884. 'guests' => -1,
  885. 'illegal_board_perms' => $illegal_board_permissions,
  886. )
  887. );
  888. $smcFunc['db_query']('', '
  889. DELETE FROM {db_prefix}permissions
  890. WHERE id_group = {int:guests}
  891. AND permission IN ({array_string:illegal_perms})',
  892. array(
  893. 'guests' => -1,
  894. 'illegal_perms' => $illegal_permissions,
  895. )
  896. );
  897. ---}
  898. ---#
  899. /******************************************************************************/
  900. --- Adding mail queue settings
  901. /******************************************************************************/
  902. ---#
  903. ---{
  904. if (empty($modSettings['mail_limit']))
  905. {
  906. $smcFunc['db_insert']('replace',
  907. '{db_prefix}settings',
  908. array('variable' => 'string-255', 'value' => 'string'),
  909. array(
  910. array('mail_limit', '5'),
  911. array('mail_quantity', '5'),
  912. ),
  913. array('variable')
  914. );
  915. }
  916. ---}
  917. ---#