upgrade_2-1_postgresql.sql 34 KB

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