upgrade_2-1_sqlite.sql 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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 logging who fulfils a group request.
  177. /******************************************************************************/
  178. ---# Adding new columns to log_group_requests
  179. ALTER TABLE {$db_prefix}log_group_requests
  180. ADD COLUMN status smallint unsigned NOT NULL default '0',
  181. ADD COLUMN id_member_acted int unsigned NOT NULL default '0',
  182. ADD COLUMN member_name_acted varchar(255) NOT NULL default '',
  183. ADD COLUMN time_acted int unsigned NOT NULL default '0',
  184. ADD COLUMN act_reason text NOT NULL;
  185. ---#
  186. ---# Adjusting the indexes for log_group_requests
  187. DROP INDEX {$db_prefix}log_group_requests_id_member;
  188. CREATE INDEX {$db_prefix}log_group_requests_id_member ON {$db_prefix}log_group_requests (id_member, id_group);
  189. ---#
  190. /******************************************************************************/
  191. --- Adding support for <credits> tag in package manager
  192. /******************************************************************************/
  193. ---# Adding new columns to log_packages ..
  194. ALTER TABLE {$db_prefix}log_packages
  195. ADD COLUMN credits varchar(255) NOT NULL DEFAULT '';
  196. ---#
  197. /******************************************************************************/
  198. --- Adding more space for session ids
  199. /******************************************************************************/
  200. ---# Altering the session_id columns...
  201. ALTER TABLE {$db_prefix}log_online
  202. CHANGE `session` `session` varchar(64) NOT NULL DEFAULT '';
  203. ALTER TABLE {$db_prefix}log_errors
  204. CHANGE `session` `session` char(64) NOT NULL default ' ';
  205. ALTER TABLE {$db_prefix}sessions
  206. CHANGE `session_id` `session_id` char(64) NOT NULL;
  207. ---#
  208. /******************************************************************************/
  209. --- Adding new columns for MOVED topic updates
  210. /******************************************************************************/
  211. ---# Adding new custom fields columns.
  212. ---{
  213. $smcFunc['db_alter_table']('{db_prefix}topics', array(
  214. 'add' => array(
  215. 'redirect_expires' => array(
  216. 'name' => 'redirect_expires',
  217. 'null' => false,
  218. 'default' => '0',
  219. 'type' => 'int',
  220. 'auto' => false,
  221. ),
  222. )
  223. ));
  224. $smcFunc['db_alter_table']('{db_prefix}topics', array(
  225. 'add' => array(
  226. 'id_redirect_topic' => array(
  227. 'name' => 'id_redirect_topic',
  228. 'null' => false,
  229. 'default' => '0',
  230. 'type' => 'int',
  231. 'auto' => false,
  232. ),
  233. )
  234. ));
  235. ---}
  236. ---#
  237. /******************************************************************************/
  238. --- Adding new scheduled tasks
  239. /******************************************************************************/
  240. ---# Adding new scheduled tasks
  241. INSERT INTO {$db_prefix}scheduled_tasks
  242. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  243. VALUES
  244. (0, 120, 1, 'd', 0, 'remove_temp_attachments');
  245. INSERT INTO {$db_prefix}scheduled_tasks
  246. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  247. VALUES
  248. (0, 180, 1, 'd', 0, 'remove_topic_redirect');
  249. INSERT INTO {$db_prefix}scheduled_tasks
  250. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  251. VALUES
  252. (0, 240, 1, 'd', 0, 'remove_old_drafts');
  253. ---#
  254. /******************************************************************************/
  255. ---- Adding background tasks support
  256. /******************************************************************************/
  257. ---# Adding the new table
  258. CREATE TABLE IF NOT EXISTS {$db_prefix}background_tasks (
  259. id_task integer primary key,
  260. task_file varchar(255) NOT NULL default '',
  261. task_class varchar(255) NOT NULL default '',
  262. task_data text NOT NULL,
  263. claimed_time int NOT NULL default '0',
  264. PRIMARY KEY (id_task)
  265. );
  266. ---#
  267. /******************************************************************************/
  268. ---- Replacing MSN with Skype
  269. /******************************************************************************/
  270. ---# Modifying the "msn" column...
  271. ALTER TABLE {$db_prefix}members
  272. CHANGE msn skype varchar(255) NOT NULL DEFAULT '';
  273. ---#
  274. /******************************************************************************/
  275. --- Adding support for deny boards access
  276. /******************************************************************************/
  277. ---# Adding new columns to boards...
  278. ---{
  279. $smcFunc['db_alter_table']('{db_prefix}boards', array(
  280. 'add' => array(
  281. 'deny_member_groups' => array(
  282. 'name' => 'deny_member_groups',
  283. 'null' => false,
  284. 'default' => '',
  285. 'type' => varchar,
  286. 'size' => 255,
  287. 'auto' => false,
  288. ),
  289. )
  290. ));
  291. ---}
  292. ---#
  293. /******************************************************************************/
  294. --- Adding support for category descriptions
  295. /******************************************************************************/
  296. ---# Adding new columns to categories...
  297. ---{
  298. $smcFunc['db_alter_table']('{db_prefix}log_topics', array(
  299. 'add' => array(
  300. 'description' => array(
  301. 'name' => 'description',
  302. 'null' => false,
  303. 'type' => 'text',
  304. 'auto' => false,
  305. ),
  306. )
  307. ));
  308. ---}
  309. ---#
  310. /******************************************************************************/
  311. --- Adding support for alerts
  312. /******************************************************************************/
  313. ---# Adding the count to the members table...
  314. ---{
  315. $smcFunc['db_alter_table']('{db_prefix}members', array(
  316. 'add' => array(
  317. 'alerts' => array(
  318. 'name' => 'ualerts',
  319. 'null' => false,
  320. 'default' => 0,
  321. 'type' => 'int',
  322. 'auto' => false,
  323. ),
  324. )
  325. ));
  326. ---}
  327. ---#
  328. ---# Adding the new table for alerts.
  329. CREATE TABLE IF NOT EXISTS {$db_prefix}user_alerts (
  330. id_alert int primary key,
  331. alert_time int unsigned NOT NULL default '0',
  332. id_member int unsigned NOT NULL default '0',
  333. id_member_started int unsigned NOT NULL default '0',
  334. member_name varchar(255) NOT NULL default '',
  335. content_type varchar(255) NOT NULL default '',
  336. content_id int unsigned NOT NULL default '0',
  337. content_action varchar(255) NOT NULL default '',
  338. is_read smallint unsigned NOT NULL default '0',
  339. extra text NOT NULL,
  340. PRIMARY KEY (id_alert)
  341. );
  342. CREATE INDEX {$db_prefix}user_alerts_id_member ON {$db_prefix}user_alerts (id_member);
  343. CREATE INDEX {$db_prefix}user_alerts_alert_time ON {$db_prefix}user_alerts (alert_time);
  344. ---#
  345. ---# Adding alert preferences.
  346. CREATE TABLE IF NOT EXISTS {$db_prefix}user_alerts_prefs (
  347. id_member int unsigned NOT NULL default '0',
  348. alert_pref varchar(32) NOT NULL default '',
  349. alert_value tinyint(3) NOT NULL default '0',
  350. PRIMARY KEY (id_member, alert_pref)
  351. );
  352. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'member_group_request', 1);
  353. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'member_register', 1);
  354. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_like', 1);
  355. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report', 1);
  356. INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report_reply', 1);
  357. ---#
  358. /******************************************************************************/
  359. --- Adding support for topic unwatch
  360. /******************************************************************************/
  361. ---# Adding new columns to log_topics...
  362. ---{
  363. $smcFunc['db_alter_table']('{db_prefix}log_topics', array(
  364. 'add' => array(
  365. 'unwatched' => array(
  366. 'name' => 'unwatched',
  367. 'null' => false,
  368. 'default' => 0,
  369. 'type' => 'int',
  370. 'auto' => false,
  371. ),
  372. )
  373. ));
  374. UPDATE {$db_prefix}log_topics
  375. SET unwatched = 0;
  376. INSERT INTO {$db_prefix}settings
  377. (variable, value)
  378. VALUES
  379. ('enable_unwatch', 0);
  380. ---}
  381. ---#
  382. ---# Fixing column name change...
  383. ---{
  384. $smcFunc['db_alter_table']('{db_prefix}log_topics', array(
  385. 'change' => array(
  386. 'disregarded' => array(
  387. 'name' => 'unwatched',
  388. 'null' => false,
  389. 'default' => 0,
  390. 'type' => 'int',
  391. 'auto' => false,
  392. ),
  393. )
  394. ));
  395. ---}
  396. ---#
  397. /******************************************************************************/
  398. --- Name changes
  399. /******************************************************************************/
  400. ---# Altering the membergroup stars to icons
  401. ---{
  402. upgrade_query("
  403. ALTER TABLE {$db_prefix}membergroups
  404. CHANGE `stars` `icons` varchar(255) NOT NULL DEFAULT ''");
  405. ---}
  406. ---#
  407. ---# Renaming default theme...
  408. UPDATE {$db_prefix}themes
  409. SET value = 'SMF Default Theme - Curve2'
  410. WHERE value LIKE 'SMF Default Theme%';
  411. ---#
  412. ---# Adding the enableThemes setting.
  413. INSERT INTO {$db_prefix}settings
  414. (variable, value)
  415. VALUES
  416. ('enableThemes', '1');
  417. ---#
  418. ---# Setting "default" as the default...
  419. UPDATE {$db_prefix}settings
  420. SET value = '1'
  421. WHERE variable = 'theme_guests';
  422. UPDATE {$db_prefix}boards
  423. SET id_theme = 0;
  424. UPDATE {$db_prefix}members
  425. SET id_theme = 0;
  426. ---#
  427. /******************************************************************************/
  428. --- Cleaning up after old themes...
  429. /******************************************************************************/
  430. ---# Checking for "core" and removing it if necessary...
  431. ---{
  432. // Do they have "core" installed?
  433. if (file_exists($GLOBALS['boarddir'] . '/Themes/core'))
  434. {
  435. $core_dir = $GLOBALS['boarddir'] . '/Themes/core';
  436. $theme_request = upgrade_query("
  437. SELECT id_theme
  438. FROM {$db_prefix}themes
  439. WHERE variable = 'theme_dir'
  440. AND value ='$core_dir'");
  441. // Don't do anything if this theme is already uninstalled
  442. if ($smcFunc['db_num_rows']($theme_request) == 1)
  443. {
  444. list($id_theme) = $smcFunc['db_fetch_row']($theme_request, 0);
  445. $smcFunc['db_free_result']($theme_request);
  446. $known_themes = explode(', ', $modSettings['knownThemes']);
  447. // Remove this value...
  448. $known_themes = array_diff($known_themes, array($id_theme));
  449. // Change back to a string...
  450. $known_themes = implode(', ', $known_themes);
  451. // Update the database
  452. upgrade_query("
  453. UPDATE {$db_prefix}settings
  454. SET value = '$known_themes'
  455. WHERE variable = 'knownThemes'");
  456. // Delete any info about this theme
  457. upgrade_query("
  458. DELETE FROM {$db_prefix}themes
  459. WHERE id_theme = $id_theme");
  460. }
  461. }
  462. /******************************************************************************/
  463. --- Adding support for drafts
  464. /******************************************************************************/
  465. ---# Creating drafts table.
  466. CREATE TABLE IF NOT EXISTS {$db_prefix}user_drafts (
  467. id_draft int unsigned NOT NULL auto_increment,
  468. id_topic int unsigned NOT NULL default '0',
  469. id_board smallint unsigned NOT NULL default '0',
  470. id_reply int unsigned NOT NULL default '0',
  471. type smallint NOT NULL default '0',
  472. poster_time int unsigned NOT NULL default '0',
  473. id_member int unsigned NOT NULL default '0',
  474. subject varchar(255) NOT NULL default '',
  475. smileys_enabled smallint NOT NULL default '1',
  476. body text NOT NULL,
  477. icon varchar(16) NOT NULL default 'xx',
  478. locked smallint NOT NULL default '0',
  479. is_sticky smallint NOT NULL default '0',
  480. to_list varchar(255) NOT NULL default '',
  481. PRIMARY KEY (id_draft)
  482. );
  483. CREATE UNIQUE INDEX {$db_prefix}user_drafts_id_member ON {$db_prefix}user_drafts (id_member, id_draft, type);
  484. ---#
  485. ---# Adding draft permissions...
  486. ---{
  487. // We cannot do this twice
  488. if (@$modSettings['smfVersion'] < '2.1')
  489. {
  490. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  491. $request = upgrade_query("
  492. SELECT id_group, id_board, add_deny, permission
  493. FROM {$db_prefix}board_permissions
  494. WHERE permission = 'post_unapproved_topics'");
  495. $inserts = array();
  496. while ($row = $smcFunc['db_fetch_assoc']($request))
  497. {
  498. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  499. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  500. }
  501. $smcFunc['db_free_result']($request);
  502. if (!empty($inserts))
  503. {
  504. foreach ($inserts AS $insert)
  505. {
  506. upgrade_query("
  507. INSERT INTO {$db_prefix}board_permissions
  508. (id_group, id_board, permission, add_deny)
  509. VALUES
  510. " . $insert);
  511. }
  512. }
  513. // Next we find people who can send PMs, and assume they can save pm_drafts as well
  514. $request = upgrade_query("
  515. SELECT id_group, add_deny, permission
  516. FROM {$db_prefix}permissions
  517. WHERE permission = 'pm_send'");
  518. $inserts = array();
  519. while ($row = $smcFunc['db_fetch_assoc']($request))
  520. {
  521. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  522. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  523. }
  524. $smcFunc['db_free_result']($request);
  525. if (!empty($inserts))
  526. {
  527. foreach ($inserts AS $insert)
  528. {
  529. upgrade_query("
  530. INSERT INTO {$db_prefix}permissions
  531. (id_group, permission, add_deny)
  532. VALUES
  533. " . $insert);
  534. }
  535. }
  536. }
  537. ---}
  538. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_autosave_enabled', '1');
  539. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_show_saved_enabled', '1');
  540. INSERT INTO {$db_prefix}settings (variable, value) VALUES ('drafts_keep_days', '7');
  541. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_autosave_enabled', '1');
  542. INSERT INTO {$db_prefix}themes (id_theme, variable, value) VALUES ('1', 'drafts_show_saved_enabled', '1');
  543. ---#
  544. /******************************************************************************/
  545. --- Adding support for likes
  546. /******************************************************************************/
  547. ---# Creating likes table.
  548. CREATE TABLE IF NOT EXISTS {$db_prefix}user_likes (
  549. id_member int NOT NULL default '0',
  550. content_type char(6) default '',
  551. content_id int NOT NULL default '0',
  552. like_time int NOT NULL default '0',
  553. PRIMARY KEY (content_id, content_type, id_member)
  554. );
  555. CREATE INDEX {$db_prefix}user_likes_content ON {$db_prefix}user_likes (content_id, content_type);
  556. CREATE INDEX {$db_prefix}user_likes_liker ON {$db_prefix}user_likes (id_member);
  557. ---#
  558. ---# Adding count to the messages table.
  559. ALTER TABLE {$db_prefix}messages
  560. ADD COLUMN likes smallint NOT NULL default '0';
  561. ---#
  562. /******************************************************************************/
  563. --- Adding support for group-based board moderation
  564. /******************************************************************************/
  565. ---# Creating moderator_groups table
  566. CREATE TABLE IF NOT EXISTS {$db_prefix}moderator_groups (
  567. id_board smallint NOT NULL default '0',
  568. id_group smallint NOT NULL default '0',
  569. PRIMARY KEY (id_board, id_group)
  570. );
  571. ---#
  572. /******************************************************************************/
  573. --- Cleaning up integration hooks
  574. /******************************************************************************/
  575. ---#
  576. DELETE FROM {$db_prefix}settings
  577. WHERE variable LIKE 'integrate_%';
  578. ---#
  579. /******************************************************************************/
  580. --- Cleaning up old settings
  581. /******************************************************************************/
  582. ---# Updating the default time format
  583. ---{
  584. if (!empty($modSettings['time_format']))
  585. {
  586. // First, use the shortened form of the month in the date.
  587. $time_format = str_replace('%B', '%b', $modSettings['time_format']);
  588. // Second, shorten the time to stop including seconds.
  589. $time_format = str_replace(':%S', '', $time_format);
  590. // Then, update the database.
  591. $smcFunc['db_query']('', '
  592. UPDATE {db_prefix}settings
  593. SET value = {string:new_format}
  594. WHERE variable = {literal:time_format}',
  595. array(
  596. 'new_format' => $time_format,
  597. )
  598. );
  599. }
  600. ---}
  601. ---#
  602. ---# Fixing a deprecated option.
  603. UPDATE {$db_prefix}settings
  604. SET value = 'option_css_resize'
  605. WHERE variable = 'avatar_action_too_large'
  606. AND (value = 'option_html_resize' OR value = 'option_js_resize');
  607. ---#
  608. ---# Cleaning up old settings.
  609. DELETE FROM {$db_prefix}settings
  610. WHERE variable IN ('enableStickyTopics', 'guest_hideContacts', 'notify_new_registration', 'attachmentEncryptFilenames', 'hotTopicPosts', 'hotTopicVeryPosts', 'fixLongWords');
  611. ---#
  612. ---# Cleaning up old theme settings.
  613. DELETE FROM {$db_prefix}themes
  614. WHERE variable IN ('show_board_desc', 'no_new_reply_warning', 'display_quick_reply');
  615. ---#
  616. /******************************************************************************/
  617. --- Removing old Simple Machines files we do not need to fetch any more
  618. /******************************************************************************/
  619. ---# We no longer call on the latest packages list.
  620. DELETE FROM {$db_prefix}admin_info_files
  621. WHERE filename IN ('latest-packages.js', 'latest-support.js', 'latest-themes.js')
  622. AND path = '/smf/';
  623. ---#
  624. /******************************************************************************/
  625. --- Upgrading "verification questions" feature
  626. /******************************************************************************/
  627. ---# Creating qanda table
  628. CREATE TABLE IF NOT EXISTS {$db_prefix}qanda (
  629. id_question smallint(5) unsigned NOT NULL auto_increment,
  630. lngfile varchar(255) NOT NULL default '',
  631. question varchar(255) NOT NULL default '',
  632. answers text NOT NULL,
  633. PRIMARY KEY (id_question),
  634. KEY lngfile (lngfile)
  635. );
  636. ---#
  637. ---# Moving questions and answers to the new table
  638. ---{
  639. $questions = array();
  640. $get_questions = upgrade_query("
  641. SELECT body AS question, recipient_name AS answer
  642. FROM {$db_prefix}log_comments
  643. WHERE comment_type = 'ver_test'");
  644. while ($row = $smcFunc['db_fetch_assoc']($get_questions))
  645. $questions[] = array($language, $row['question'], serialize(array($row['answer'])));
  646. $smcFunc['db_free_result']($get_questions);
  647. if (!empty($questions))
  648. {
  649. $smcFunc['db_insert']('',
  650. '{db_prefix}qanda',
  651. array('lngfile' => 'string', 'question' => 'string', 'answers' => 'string'),
  652. $questions,
  653. array('id_question')
  654. );
  655. // Delete the questions from log_comments now
  656. upgrade_query("
  657. DELETE FROM {$db_prefix}log_comments
  658. WHERE comment_type = 'ver_test'
  659. ");
  660. }
  661. ---}
  662. ---#
  663. /******************************************************************************/
  664. --- Marking packages as uninstalled...
  665. /******************************************************************************/
  666. ---# Updating log_packages
  667. UPDATE {$db_prefix}log_packages
  668. SET install_state = 0;
  669. ---#
  670. /******************************************************************************/
  671. --- Updating profile permissions...
  672. /******************************************************************************/
  673. ---# Removing the old "view your own profile" permission
  674. DELETE FROM {$db_prefix}permissions
  675. WHERE permission = 'profile_view_own';
  676. ---#
  677. ---# Updating the old "view any profile" permission
  678. UPDATE {$db_prefix}permissions
  679. SET permission = 'profile_view'
  680. WHERE permission = 'profile_view_any';
  681. ---#
  682. ---# Removing the old notification permissions
  683. DELETE FROM {$db_prefix}board_permissions
  684. WHERE permission = 'mark_notify' OR permission = 'mark_any_notify';
  685. ---#
  686. ---# Adding "profile_password_own"
  687. ---{
  688. $inserts = array();
  689. $request = upgrade_query("
  690. SELECT id_group, add_deny
  691. FROM {$db_prefix}permissions
  692. WHERE permission = 'profile_identity_own'");
  693. while ($row = $smcFunc['db_fetch_assoc']($request))
  694. {
  695. $inserts[] = "($row[id_group], 'profile_password_own', $row[add_deny])";
  696. }
  697. $smcFunc['db_free_result']($request);
  698. if (!empty($inserts))
  699. {
  700. foreach ($inserts as $insert)
  701. {
  702. upgrade_query("
  703. INSERT INTO {$db_prefix}permissions
  704. (id_group, permission, add_deny)
  705. VALUES
  706. " . $insert);
  707. }
  708. }
  709. ---}
  710. ---#
  711. ---# Adding other profile permissions
  712. ---{
  713. $inserts = array();
  714. $request = upgrade_query("
  715. SELECT id_group, add_deny
  716. FROM {$db_prefix}permissions
  717. WHERE permission = 'profile_extra_own'");
  718. while ($row = $smcFunc['db_fetch_assoc']($request))
  719. {
  720. $inserts[] = "($row[id_group], 'profile_blurb_own', $row[add_deny])";
  721. $inserts[] = "($row[id_group], 'profile_displayed_name_own', $row[add_deny])";
  722. $inserts[] = "($row[id_group], 'profile_forum_own', $row[add_deny])";
  723. $inserts[] = "($row[id_group], 'profile_other_own', $row[add_deny])";
  724. $inserts[] = "($row[id_group], 'profile_signature_own', $row[add_deny])";
  725. }
  726. $smcFunc['db_free_result']($request);
  727. if (!empty($inserts))
  728. {
  729. foreach ($inserts as $insert)
  730. {
  731. upgrade_query("
  732. INSERT INTO {$db_prefix}permissions
  733. (id_group, permission, add_deny)
  734. VALUES
  735. " . $insert);
  736. }
  737. }
  738. ---}
  739. ---#
  740. /******************************************************************************/
  741. --- Upgrading PM labels...
  742. /******************************************************************************/
  743. ---# Adding pm_labels table...
  744. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labels (
  745. id_label integer primary key,
  746. id_member int NOT NULL default '0',
  747. name varchar(30) NOT NULL default '',
  748. );
  749. ---#
  750. ---# Adding pm_labeled_messages table...
  751. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_labeled_messages (
  752. id_label int NOT NULL default '0',
  753. id_pm int NOT NULL default '0',
  754. PRIMARY KEY (id_label, id_pm)
  755. );
  756. ---#
  757. ---# Adding "in_inbox" column to pm_recipients
  758. ALTER TABLE {$db_prefix}pm_recipients
  759. ADD COLUMN in_inbox tinyint(3) NOT NULL default '1';
  760. ---#
  761. ---# Moving label info to new tables and updating rules...
  762. ---{
  763. // First see if we still have a message_labels column
  764. $results = $smcFunc['db_list_columns']('{db_prefix}members');
  765. if (in_array('message_labels', $results))
  766. {
  767. // They've still got it, so pull the label info
  768. $get_labels = $smcFunc['db_query']('', '
  769. SELECT id_member, message_labels
  770. FROM {db_prefix}members
  771. WHERE message_labels != {string:blank}',
  772. array(
  773. 'blank' => '',
  774. )
  775. );
  776. $inserts = array();
  777. $label_info = array();
  778. while ($row = $smcFunc['db_fetch_assoc']($get_labels))
  779. {
  780. // Stick this in an array
  781. $labels = explode(',', $row['message_labels']);
  782. // Build some inserts
  783. foreach ($labels AS $index => $label)
  784. {
  785. // Keep track of the index of this label - we'll need that in a bit...
  786. $label_info[$row['id_member']][$label] = $index;
  787. $inserts[] = array($row['id_member'], $label);
  788. }
  789. }
  790. $smcFunc['db_free_result']($get_labels);
  791. if (!empty($inserts))
  792. {
  793. $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'int'), $inserts, array());
  794. // Clear this out for our next query below
  795. $inserts = array();
  796. }
  797. // This is the easy part - update the inbox stuff
  798. $smcFunc['db_query']('', '
  799. UPDATE {db_prefix}pm_recipients
  800. SET in_inbox = {int:in_inbox}
  801. WHERE FIND_IN_SET({int:minus_one}, labels)',
  802. array(
  803. 'in_inbox' => 1,
  804. 'minus_one' => -1,
  805. )
  806. );
  807. // Now we go pull the new IDs for each label
  808. $get_new_label_ids = $smcFunc['db_query']('', '
  809. SELECT *
  810. FROM {db_prefix}pm_labels',
  811. array(
  812. )
  813. );
  814. $label_info_2 = array();
  815. while ($label_row = $smcFunc['db_fetch_assoc']($get_new_label_ids))
  816. {
  817. // Map the old index values to the new ID values...
  818. $old_index = $label_info[$row['id_member']][$row['label_name']];
  819. $label_info_2[$row['id_member']][$old_index] = $row['id_label'];
  820. }
  821. $smcFunc['db_free_result']($get_new_label_ids);
  822. // Pull label info from pm_recipients
  823. // Ignore any that are only in the inbox
  824. $get_pm_labels = $smcFunc['db_query']('', '
  825. SELECT id_pm, id_member, labels
  826. FROM {db_prefix}pm_recipients
  827. WHERE deleted = {int:not_deleted}
  828. AND labels != {string:minus_one}',
  829. array(
  830. 'not_deleted' => 0,
  831. 'minus_one' => -1,
  832. )
  833. );
  834. while ($row = $smcFunc['db_fetch_assoc']($get_pm_labels))
  835. {
  836. $labels = explode(',', $row['labels']);
  837. foreach ($labels as $a_label)
  838. {
  839. if ($a_label == '-1')
  840. continue;
  841. $new_label_info = $label_info_2[$row['id_member']][$a_label];
  842. $inserts[] = array($row['id_pm'], $new_label_info);
  843. }
  844. }
  845. $smcFunc['db_free_result']($get_pm_labels);
  846. // Insert the new data
  847. if (!empty($inserts))
  848. {
  849. $smcFunc['db_insert']('', '{db_prefix}pm_labeled_messages', array('id_pm', 'id_label'), $inserts, array());
  850. }
  851. // Final step of this ridiculously massive process
  852. $get_pm_rules = $smcFunc['db_query']('', '
  853. SELECT id_member, id_rule, actions
  854. FROM {db_prefix}pm_rules',
  855. array(
  856. ),
  857. );
  858. // Go through the rules, unserialize the actions, then figure out if there's anything we can use
  859. while ($row = $smcFunc['db_fetch_assoc']($get_pm_rules))
  860. {
  861. // Turn this into an array...
  862. $actions = unserialize($row['actions']);
  863. // Loop through the actions and see if we're applying a label anywhere
  864. foreach ($actions as $index => $action)
  865. {
  866. if ($action['t'] == 'lab')
  867. {
  868. // Update the value of this label...
  869. $actions[$index]['v'] = $label_info_2[$row['id_member']][$action['v']];
  870. }
  871. }
  872. // Put this back into a string
  873. $actions = serialize($actions);
  874. $smcFunc['db_query']('', '
  875. UPDATE {db_prefix}pm_rules
  876. SET actions = {string:actions}
  877. WHERE id_rule = {int:id_rule}',
  878. array(
  879. 'actions' => $actions,
  880. 'id_rule' => $row['id_rule'],
  881. )
  882. );
  883. }
  884. $smcFunc['db_free_result']($get_pm_rules);
  885. // Lastly, we drop the old columns
  886. $smcFunc['db_remove_column']('{db_prefix}members', 'message_labels');
  887. $smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
  888. }
  889. }
  890. ******************************************************************************/
  891. --- Adding support for edit reasons
  892. /******************************************************************************/
  893. ---# Adding "modified_reason" column to messages
  894. ALTER TABLE {$db_prefix}messages
  895. ADD COLUMN modified_reason varchar(255) NOT NULL default '';
  896. ---#
  897. /******************************************************************************/
  898. --- Cleaning up guest permissions
  899. /******************************************************************************/
  900. ---# Removing permissions guests can no longer have...
  901. ---{
  902. $illegal_board_permissions = array(
  903. 'announce_topic',
  904. 'delete_any',
  905. 'lock_any',
  906. 'make_sticky',
  907. 'merge_any',
  908. 'modify_any',
  909. 'modify_replies',
  910. 'move_any',
  911. 'poll_add_any',
  912. 'poll_edit_any',
  913. 'poll_lock_any',
  914. 'poll_remove_any',
  915. 'remove_any',
  916. 'report_any',
  917. 'split_any'
  918. );
  919. $illegal_permissions = array('calendar_edit_any', 'moderate_board', 'moderate_forum', 'send_email_to_members');
  920. $smcFunc['db_query']('', '
  921. DELETE FROM {db_prefix}board_permissions
  922. WHERE id_group = {int:guests}
  923. AND permission IN ({array_string:illegal_board_perms})',
  924. array(
  925. 'guests' => -1,
  926. 'illegal_board_perms' => $illegal_board_permissions,
  927. )
  928. );
  929. $smcFunc['db_query']('', '
  930. DELETE FROM {db_prefix}permissions
  931. WHERE id_group = {int:guests}
  932. AND permission IN ({array_string:illegal_perms})',
  933. array(
  934. 'guests' => -1,
  935. 'illegal_perms' => $illegal_permissions,
  936. )
  937. );
  938. ---}
  939. ---#
  940. /******************************************************************************/
  941. --- Adding mail queue settings
  942. /******************************************************************************/
  943. ---#
  944. ---{
  945. if (empty($modSettings['mail_limit']))
  946. {
  947. $smcFunc['db_insert']('replace',
  948. '{db_prefix}settings',
  949. array('variable' => 'string-255', 'value' => 'string'),
  950. array(
  951. array('mail_limit', '5'),
  952. array('mail_quantity', '5'),
  953. ),
  954. array('variable')
  955. );
  956. }
  957. ---}
  958. ---#