upgrade_2-0_sqlite.sql 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. /* ATTENTION: You don't need to run or use this file! The upgrade.php script does everything for you! */
  2. /******************************************************************************/
  3. --- Updating custom fields.
  4. /******************************************************************************/
  5. ---# Adding search ability to custom fields.
  6. ---{
  7. $smcFunc['db_alter_table']('{db_prefix}custom_fields', array(
  8. 'add' => array(
  9. 'can_search' => array(
  10. 'name' => 'can_search',
  11. 'null' => false,
  12. 'default' => 0,
  13. 'type' => 'smallint',
  14. 'size' => 255,
  15. 'auto' => false,
  16. ),
  17. ),
  18. ));
  19. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] < '2.0 Beta 4')
  20. {
  21. upgrade_query("
  22. UPDATE {$db_prefix}custom_fields
  23. SET private = 3
  24. WHERE private = 2");
  25. }
  26. ---}
  27. ---#
  28. ---# Adding new custom fields columns.
  29. ---{
  30. $smcFunc['db_alter_table']('{db_prefix}custom_fields', array(
  31. 'add' => array(
  32. 'enclose' => array(
  33. 'name' => 'enclose',
  34. 'null' => false,
  35. 'default' => '',
  36. 'type' => 'text',
  37. 'auto' => false,
  38. ),
  39. )
  40. ));
  41. $smcFunc['db_alter_table']('{db_prefix}custom_fields', array(
  42. 'add' => array(
  43. 'placement' => array(
  44. 'name' => 'placement',
  45. 'null' => false,
  46. 'default' => '',
  47. 'type' => 'smallint',
  48. 'auto' => false,
  49. ),
  50. )
  51. ));
  52. ---}
  53. ---#
  54. ---# Fixing default value for the "show_profile" column
  55. ---{
  56. $smcFunc['db_alter_table']('{db_prefix}custom_fields', array(
  57. 'change' => array(
  58. 'show_profile' => array(
  59. 'name' => 'show_profile',
  60. 'null' => false,
  61. 'default' => 'forumprofile',
  62. 'type' => 'varchar(20)',
  63. 'auto' => false,
  64. ),
  65. )
  66. ));
  67. ---}
  68. ---#
  69. ALTER TABLE {$db_prefix}custom_fields
  70. ALTER COLUMN show_profile DEFAULT 'forumprofile';
  71. ---#
  72. /******************************************************************************/
  73. --- Adding search engine tracking.
  74. /******************************************************************************/
  75. ---# Creating spider table.
  76. CREATE TABLE {$db_prefix}spiders (
  77. id_spider integer primary key,
  78. spider_name varchar(255) NOT NULL,
  79. user_agent varchar(255) NOT NULL,
  80. ip_info varchar(255) NOT NULL
  81. );
  82. ---#
  83. ---# Inserting the search engines.
  84. ---{
  85. $smcFunc['db_insert']('ignore',
  86. '{db_prefix}spiders',
  87. array('id_spider' => 'int', 'spider_name' => 'string-255', 'user_agent' => 'string-255', 'ip_info' => 'string-255'),
  88. array(
  89. array(1, 'Google', 'googlebot', ''),
  90. array(2, 'Yahoo!', 'slurp', ''),
  91. array(3, 'MSN', 'msnbot', ''),
  92. array(4, 'Google (Mobile)', 'Googlebot-Mobile', ''),
  93. array(5, 'Google (Image)', 'Googlebot-Image', ''),
  94. array(6, 'Google (AdSense)', 'Mediapartners-Google', ''),
  95. array(7, 'Google (Adwords)', 'AdsBot-Google', ''),
  96. array(8, 'Yahoo! (Mobile)', 'YahooSeeker/M1A1-R2D2', ''),
  97. array(9, 'Yahoo! (Image)', 'Yahoo-MMCrawler', ''),
  98. array(10, 'MSN (Mobile)', 'MSNBOT_Mobile', ''),
  99. array(11, 'MSN (Media)', 'msnbot-media', ''),
  100. array(12, 'Cuil', 'twiceler', ''),
  101. array(13, 'Ask', 'Teoma', ''),
  102. array(14, 'Baidu', 'Baiduspider', ''),
  103. array(15, 'Gigablast', 'Gigabot', ''),
  104. array(16, 'InternetArchive', 'ia_archiver-web.archive.org', ''),
  105. array(17, 'Alexa', 'ia_archiver', ''),
  106. array(18, 'Omgili', 'omgilibot', ''),
  107. array(19, 'EntireWeb', 'Speedy Spider', '')
  108. ),
  109. array('user_agent')
  110. );
  111. ---}
  112. ---#
  113. ---# Removing a spider.
  114. ---{
  115. upgrade_query("
  116. DELETE FROM {$db_prefix}spiders
  117. WHERE user_agent = 'yahoo'
  118. AND spider_name = 'Yahoo! (Publisher)'
  119. ");
  120. ---}
  121. ---#
  122. ---# Creating spider hit tracking table.
  123. CREATE TABLE {$db_prefix}log_spider_hits (
  124. id_spider integer NOT NULL default '0',
  125. session varchar(32) NOT NULL default '',
  126. log_time int NOT NULL,
  127. url varchar(255) NOT NULL,
  128. processed smallint NOT NULL default '0'
  129. );
  130. CREATE INDEX {$db_prefix}log_spider_hits_id_spider ON {$db_prefix}log_spider_hits (id_spider);
  131. CREATE INDEX {$db_prefix}log_spider_hits_log_time ON {$db_prefix}log_spider_hits (log_time);
  132. CREATE INDEX {$db_prefix}log_spider_hits_processed ON {$db_prefix}log_spider_hits (processed);
  133. ---#
  134. ---# Creating spider statistic table.
  135. CREATE TABLE {$db_prefix}log_spider_stats (
  136. id_spider integer NOT NULL default '0',
  137. unique_visits smallint NOT NULL default '0',
  138. page_hits smallint NOT NULL default '0',
  139. last_seen int NOT NULL default '0',
  140. stat_date date NOT NULL default '0001-01-01',
  141. PRIMARY KEY (stat_date, id_spider)
  142. );
  143. ---#
  144. /******************************************************************************/
  145. --- Adding new forum settings.
  146. /******************************************************************************/
  147. ---# Enable cache if upgrading from 2.0 beta 1 and lower.
  148. ---{
  149. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1')
  150. {
  151. $request = upgrade_query("
  152. SELECT value
  153. FROM {$db_prefix}settings
  154. WHERE variable = 'cache_enable'");
  155. list ($cache_enable) = $smcFunc['db_fetch_row']($request);
  156. // No cache before
  157. if ($smcFunc['db_num_rows']($request) == 0)
  158. upgrade_query("
  159. INSERT INTO {$db_prefix}settings
  160. (variable, value)
  161. VALUES ('cache_enable', '1')");
  162. elseif (empty($cache_enable))
  163. upgrade_query("
  164. UPDATE {$db_prefix}settings
  165. SET value = '1'
  166. WHERE variable = 'cache_enable'");
  167. }
  168. ---}
  169. ---#
  170. ---# Adding advanced password brute force protection to "members" table...
  171. ---{
  172. $smcFunc['db_alter_table']('{db_prefix}members', array(
  173. 'add' => array(
  174. 'passwd_flood' => array(
  175. 'name' => 'passwd_flood',
  176. 'null' => false,
  177. 'default' => '',
  178. 'type' => 'varchar',
  179. 'size' => 12,
  180. 'auto' => false,
  181. ),
  182. )
  183. ));
  184. ---}
  185. ---#
  186. ---# Ensuring forum width setting present...
  187. ---{
  188. // Don't do this twice!
  189. $smcFunc['db_insert']('ignore',
  190. '{db_prefix}themes',
  191. array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-255'),
  192. array(1, 'forum_width', '90%'),
  193. array('id_theme', 'variable', 'value')
  194. );
  195. ---}
  196. ---#
  197. /******************************************************************************/
  198. --- Adding weekly maintenance task.
  199. /******************************************************************************/
  200. ---# Adding weekly maintenance task...
  201. ---{
  202. $smcFunc['db_insert']('ignore',
  203. '{db_prefix}scheduled_tasks',
  204. array(
  205. 'next_time' => 'int', 'time_offset' => 'int', 'time_regularity' => 'int',
  206. 'time_unit' => 'string', 'disabled' => 'int', 'task' => 'string',
  207. ),
  208. array(
  209. 0, 0, 1, 'w', 0, 'weekly_maintenance',
  210. ),
  211. array('task')
  212. );
  213. ---}
  214. ---#
  215. ---# Setting the birthday email template if not set...
  216. ---{
  217. if (!isset($modSettings['birthday_email']))
  218. {
  219. upgrade_query("
  220. INSERT INTO {$db_prefix}settings
  221. (variable, value)
  222. VALUES
  223. ('birthday_email', 'happy_birthday')");
  224. }
  225. ---}
  226. ---#
  227. /******************************************************************************/
  228. --- Adding log pruning.
  229. /******************************************************************************/
  230. ---# Adding pruning option...
  231. ---{
  232. $smcFunc['db_insert']('ignore',
  233. '{db_prefix}settings',
  234. array('variable' => 'string-255', 'value' => 'string-65534'),
  235. array('pruningOptions', '30,180,180,180,30'),
  236. array('variable')
  237. );
  238. ---}
  239. ---#
  240. /******************************************************************************/
  241. --- Updating mail queue functionality.
  242. /******************************************************************************/
  243. ---# Adding type to mail queue...
  244. ---{
  245. $smcFunc['db_alter_table']('{db_prefix}mail_queue', array(
  246. 'add' => array(
  247. 'private' => array(
  248. 'name' => 'private',
  249. 'null' => false,
  250. 'default' => 0,
  251. 'type' => 'smallint',
  252. 'size' => 1,
  253. 'auto' => false,
  254. ),
  255. )
  256. ));
  257. ---}
  258. ---#
  259. /******************************************************************************/
  260. --- Updating attachments.
  261. /******************************************************************************/
  262. ---# Adding multiple attachment path functionality.
  263. ---{
  264. $smcFunc['db_alter_table']('{db_prefix}attachments', array(
  265. 'add' => array(
  266. 'id_folder' => array(
  267. 'name' => 'id_folder',
  268. 'null' => false,
  269. 'default' => 1,
  270. 'type' => 'smallint',
  271. 'size' => 255,
  272. 'auto' => false,
  273. ),
  274. )
  275. ));
  276. ---}
  277. ---#
  278. ---# Adding file hash.
  279. ---{
  280. $smcFunc['db_alter_table']('{db_prefix}attachments', array(
  281. 'add' => array(
  282. 'file_hash' => array(
  283. 'name' => 'file_hash',
  284. 'null' => false,
  285. 'default' => '',
  286. 'type' => 'varchar',
  287. 'size' => 40,
  288. 'auto' => false,
  289. ),
  290. )
  291. ));
  292. ---}
  293. ---#
  294. /******************************************************************************/
  295. --- Providing more room for apf options.
  296. /******************************************************************************/
  297. ---# Changing field_options column to a larger field type...
  298. ---{
  299. $smcFunc['db_alter_table']('{db_prefix}custom_fields', array(
  300. 'change' => array(
  301. 'aim' => array(
  302. 'name' => 'field_options',
  303. 'null' => false,
  304. 'type' => 'text',
  305. 'default' => ''
  306. )
  307. )
  308. ));
  309. ---}
  310. ---#
  311. /******************************************************************************/
  312. --- Adding extra columns to polls.
  313. /******************************************************************************/
  314. ---# Adding reset poll timestamp and guest voters counter...
  315. ---{
  316. $smcFunc['db_alter_table']('{db_prefix}polls', array(
  317. 'add' => array(
  318. 'reset_poll' => array(
  319. 'name' => 'reset_poll',
  320. 'null' => false,
  321. 'default' => 0,
  322. 'type' => 'int',
  323. 'size' => 10,
  324. 'auto' => false,
  325. ),
  326. 'num_guest_voters' => array(
  327. 'name' => 'num_guest_voters',
  328. 'null' => false,
  329. 'default' => 0,
  330. 'type' => 'int',
  331. 'size' => 10,
  332. 'auto' => false,
  333. ),
  334. )
  335. ));
  336. ---}
  337. ---#
  338. ---# Fixing guest voter tallys on existing polls...
  339. ---{
  340. $request = upgrade_query("
  341. SELECT p.id_poll, count(lp.id_member) as guest_voters
  342. FROM {$db_prefix}polls AS p
  343. LEFT JOIN {$db_prefix}log_polls AS lp ON (lp.id_poll = p.id_poll AND lp.id_member = 0)
  344. WHERE lp.id_member = 0
  345. AND p.num_guest_voters = 0
  346. GROUP BY p.id_poll");
  347. while ($request && $row = $smcFunc['db_fetch_assoc']($request))
  348. upgrade_query("
  349. UPDATE {$db_prefix}polls
  350. SET num_guest_voters = ". $row['guest_voters']. "
  351. WHERE id_poll = " . $row['id_poll'] . "
  352. AND num_guest_voters = 0");
  353. ---}
  354. ---#
  355. /******************************************************************************/
  356. --- Adding restore topic from recycle.
  357. /******************************************************************************/
  358. ---# Adding restore from recycle feature...
  359. ---{
  360. $smcFunc['db_alter_table']('{db_prefix}topics', array(
  361. 'add' => array(
  362. 'id_previous_board' => array(
  363. 'name' => 'id_previous_board',
  364. 'null' => false,
  365. 'default' => 0,
  366. 'type' => 'smallint',
  367. 'auto' => false,
  368. ),
  369. 'id_previous_topic' => array(
  370. 'name' => 'id_previous_topic',
  371. 'null' => false,
  372. 'default' => 0,
  373. 'type' => 'int',
  374. 'auto' => false,
  375. ),
  376. )
  377. ));
  378. ---}
  379. ---#
  380. /******************************************************************************/
  381. --- Fixing aim on members for longer nicks.
  382. /******************************************************************************/
  383. ---# Changing 'aim' to varchar to allow using email...
  384. ---{
  385. $smcFunc['db_alter_table']('{db_prefix}members', array(
  386. 'change' => array(
  387. 'aim' => array(
  388. 'name' => 'aim',
  389. 'null' => false,
  390. 'type' => 'varchar',
  391. 'size' => 255,
  392. 'default' => ''
  393. )
  394. )
  395. ));
  396. ---}
  397. ---#
  398. /******************************************************************************/
  399. --- Allow for longer calendar event/holiday titles.
  400. /******************************************************************************/
  401. ---# Changing event title column to a larger field type...
  402. ---{
  403. $smcFunc['db_alter_table']('{db_prefix}calendar', array(
  404. 'change' => array(
  405. 'title' => array(
  406. 'name' => 'title',
  407. 'null' => false,
  408. 'type' => 'varchar',
  409. 'size' => 255,
  410. 'default' => ''
  411. )
  412. )
  413. ));
  414. ---}
  415. ---#
  416. ---# Changing holiday title column to a larger field type...
  417. ---{
  418. $smcFunc['db_alter_table']('{db_prefix}calendar_holidays', array(
  419. 'change' => array(
  420. 'title' => array(
  421. 'name' => 'title',
  422. 'null' => false,
  423. 'type' => 'varchar',
  424. 'size' => 255,
  425. 'default' => ''
  426. )
  427. )
  428. ));
  429. ---}
  430. ---#
  431. /******************************************************************************/
  432. --- Making changes to the package manager.
  433. /******************************************************************************/
  434. ---# Changing URL to SMF package server...
  435. UPDATE {$db_prefix}package_servers
  436. SET url = 'http://custom.simplemachines.org/packages/mods'
  437. WHERE url = 'http://mods.simplemachines.org';
  438. ---#
  439. /******************************************************************************/
  440. --- Adding new indexes to the topics table.
  441. /******************************************************************************/
  442. ---# Adding index member_started...
  443. CREATE INDEX {$db_prefix}topics_member_started ON {$db_prefix}topics (id_member_started, id_board);
  444. ---#
  445. ---# Adding index last_message_sticky...
  446. CREATE INDEX {$db_prefix}topics_last_message_sticky ON {$db_prefix}topics (id_board, is_sticky, id_last_msg);
  447. ---#
  448. ---# Adding index board_news...
  449. CREATE INDEX {$db_prefix}topics_board_news ON {$db_prefix}topics (id_board, id_first_msg);
  450. ---#
  451. /******************************************************************************/
  452. --- Adding new indexes to members table.
  453. /******************************************************************************/
  454. ---# Adding index on total_time_logged_in...
  455. CREATE INDEX {$db_prefix}members_total_time_logged_in ON {$db_prefix}members (total_time_logged_in);
  456. ---#
  457. ---# Adding index on id_theme...
  458. CREATE INDEX {$db_prefix}members_id_theme ON {$db_prefix}members (id_theme);
  459. ---#
  460. ---# Adding index on real_name...
  461. CREATE INDEX {$db_prefix}members_real_name ON {$db_prefix}members (real_name);
  462. ---#
  463. /******************************************************************************/
  464. --- Adding new indexes to messages table.
  465. /******************************************************************************/
  466. ---# Adding index id_member_msg...
  467. CREATE INDEX {$db_prefix}messages_id_member_msg ON {$db_prefix}messages (id_member, approved, id_msg);
  468. ---#
  469. ---# Adding index current_topic...
  470. CREATE INDEX {$db_prefix}messages_current_topic ON {$db_prefix}messages (id_topic, id_msg, id_member, approved);
  471. ---#
  472. ---# Adding index related_ip...
  473. CREATE INDEX {$db_prefix}messages_related_ip ON {$db_prefix}messages (id_member, poster_ip, id_msg);
  474. ---#
  475. /******************************************************************************/
  476. --- Adding new indexes to attachments table.
  477. /******************************************************************************/
  478. ---# Adding index on attachment_type...
  479. CREATE INDEX {$db_prefix}attachments_attachment_type ON {$db_prefix}attachments (attachment_type);
  480. ---#
  481. /******************************************************************************/
  482. --- Dropping unnecessary indexes...
  483. /******************************************************************************/
  484. ---# Removing index on hits...
  485. ---{
  486. $smcFunc['db_remove_index']($db_prefix . 'log_activity', $db_prefix . 'log_activity_hits');
  487. ---}
  488. ---#
  489. /******************************************************************************/
  490. --- Adding new personal message setting.
  491. /******************************************************************************/
  492. ---# Adding column that stores the PM receiving setting...
  493. ---{
  494. $smcFunc['db_alter_table']('{db_prefix}members', array(
  495. 'add' => array(
  496. 'pm_receive_from' => array(
  497. 'name' => 'pm_receive_from',
  498. 'null' => false,
  499. 'type' => 'tinyint',
  500. 'size' => 4,
  501. 'default' => '1'
  502. )
  503. )
  504. ));
  505. ---}
  506. ---#
  507. ---# Enable the buddy and ignore lists if we have not done so thus far...
  508. ---{
  509. // Don't do this if we've done this already.
  510. if (empty($modSettings['dont_repeat_buddylists']))
  511. {
  512. // Make sure the pm_receive_from column has the right default value - early adoptors might have a '0' set here.
  513. $smcFunc['db_alter_table']('{db_prefix}members', array(
  514. 'change' => array(
  515. 'pm_receive_from' => array(
  516. 'name' => 'pm_receive_from',
  517. 'null' => false,
  518. 'type' => 'tinyint',
  519. 'size' => 4,
  520. 'default' => '1'
  521. )
  522. )
  523. ));
  524. // Update previous ignore lists if they're set to ignore all.
  525. upgrade_query("
  526. UPDATE {$db_prefix}members
  527. SET pm_receive_from = 3, pm_ignore_list = ''
  528. WHERE pm_ignore_list = '*'");
  529. // Enable buddy and ignore lists.
  530. upgrade_query("
  531. REPLACE INTO {$db_prefix}settings
  532. (variable, value)
  533. VALUES
  534. ('enable_buddylist', '1')");
  535. // Ignore posts made by ignored users by default, too.
  536. upgrade_query("
  537. REPLACE INTO {$db_prefix}themes
  538. (id_member, id_theme, variable, value)
  539. VALUES
  540. (-1, 1, 'posts_apply_ignore_list', '1')");
  541. // Make sure not to skip this step next time we run this.
  542. upgrade_query("
  543. REPLACE INTO {$db_prefix}settings
  544. (variable, value)
  545. VALUES
  546. ('dont_repeat_buddylists', '1')");
  547. }
  548. // And yet, and yet... We might have a small hiccup here...
  549. if (!empty($modSettings['dont_repeat_buddylists']) && !isset($modSettings['enable_buddylist']))
  550. {
  551. // Correct RC3 adopters setting here...
  552. if (isset($modSettings['enable_buddylists']))
  553. {
  554. upgrade_query("
  555. REPLACE INTO {$db_prefix}settings
  556. (variable, value)
  557. VALUES
  558. ('enable_buddylist', '". $modSettings['enable_buddylists']. "')");
  559. }
  560. else
  561. {
  562. // This should never happen :)
  563. upgrade_query("
  564. REPLACE INTO {$db_prefix}settings
  565. (variable, value)
  566. VALUES
  567. ('enable_buddylist', '1')");
  568. }
  569. }
  570. ---}
  571. ---#
  572. /******************************************************************************/
  573. --- Adding settings for attachments and avatars.
  574. /******************************************************************************/
  575. ---# Add new security settings for attachments and avatars...
  576. ---{
  577. // Don't do this if we've done this already.
  578. if (!isset($modSettings['attachment_image_reencode']))
  579. {
  580. // Enable image re-encoding by default.
  581. upgrade_query("
  582. REPLACE INTO {$db_prefix}settings
  583. (variable, value)
  584. VALUES
  585. ('attachment_image_reencode', '1')");
  586. }
  587. if (!isset($modSettings['attachment_image_paranoid']))
  588. {
  589. // Disable draconic checks by default.
  590. upgrade_query("
  591. REPLACE INTO {$db_prefix}settings
  592. (variable, value)
  593. VALUES
  594. ('attachment_image_paranoid', '0')");
  595. }
  596. if (!isset($modSettings['avatar_reencode']))
  597. {
  598. // Enable image re-encoding by default.
  599. upgrade_query("
  600. REPLACE INTO {$db_prefix}settings
  601. (variable, value)
  602. VALUES
  603. ('avatar_reencode', '1')");
  604. }
  605. if (!isset($modSettings['avatar_paranoid']))
  606. {
  607. // Disable draconic checks by default.
  608. upgrade_query("
  609. REPLACE INTO {$db_prefix}settings
  610. (variable, value)
  611. VALUES
  612. ('avatar_paranoid', '0')");
  613. }
  614. ---}
  615. ---#
  616. ---# Add other attachment settings...
  617. ---{
  618. if (!isset($modSettings['attachment_thumb_png']))
  619. {
  620. // Make image attachment thumbnail as PNG by default.
  621. upgrade_query("
  622. REPLACE INTO {$db_prefix}settings
  623. (variable, value)
  624. VALUES
  625. ('attachment_thumb_png', '1')");
  626. }
  627. ---}
  628. ---#
  629. /******************************************************************************/
  630. --- Installing new default theme...
  631. /******************************************************************************/
  632. ---# Installing theme settings...
  633. ---{
  634. // This is Grudge's secret "I'm not a developer" theme install code - keep this quiet ;)
  635. // Firstly, I'm going out of my way to not do this twice!
  636. if ((!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '2.0 RC2') && empty($modSettings['dont_repeat_theme_core']))
  637. {
  638. // Check it's not already here, just in case.
  639. $theme_request = upgrade_query("
  640. SELECT id_theme
  641. FROM {$db_prefix}themes
  642. WHERE variable = 'theme_dir'
  643. AND value LIKE '%core'");
  644. // Only do the upgrade if it doesn't find the theme already.
  645. if ($smcFunc['db_num_rows']($theme_request) == 0)
  646. {
  647. // Try to get some settings from the current default theme.
  648. $request = upgrade_query("
  649. SELECT t1.value AS theme_dir, t2.value AS theme_url, t3.value AS images_url
  650. FROM {$db_prefix}themes AS t1, {$db_prefix}themes AS t2, {$db_prefix}themes AS t3
  651. WHERE t1.id_theme = 1
  652. AND t1.id_member = 0
  653. AND t1.variable = 'theme_dir'
  654. AND t2.id_theme = 1
  655. AND t2.id_member = 0
  656. AND t2.variable = 'theme_url'
  657. AND t3.id_theme = 1
  658. AND t3.id_member = 0
  659. AND t3.variable = 'images_url'
  660. LIMIT 1");
  661. if ($smcFunc['db_num_rows']($request) != 0)
  662. {
  663. $curve = $smcFunc['db_fetch_assoc']($request);
  664. if (substr_count($curve['theme_dir'], 'default') === 1)
  665. $core['theme_dir'] = strtr($curve['theme_dir'], array('default' => 'core'));
  666. if (substr_count($curve['theme_url'], 'default') === 1)
  667. $core['theme_url'] = strtr($curve['theme_url'], array('default' => 'core'));
  668. if (substr_count($curve['images_url'], 'default') === 1)
  669. $core['images_url'] = strtr($curve['images_url'], array('default' => 'core'));
  670. }
  671. $smcFunc['db_free_result']($request);
  672. if (!isset($core['theme_dir']))
  673. $core['theme_dir'] = addslashes($GLOBALS['boarddir']) . '/Themes/core';
  674. if (!isset($core['theme_url']))
  675. $core['theme_url'] = $GLOBALS['boardurl'] . '/Themes/core';
  676. if (!isset($core['images_url']))
  677. $core['images_url'] = $GLOBALS['boardurl'] . '/Themes/core/images';
  678. // Get an available id_theme first...
  679. $request = upgrade_query("
  680. SELECT MAX(id_theme) + 1
  681. FROM {$db_prefix}themes");
  682. list ($id_core_theme) = $smcFunc['db_fetch_row']($request);
  683. $smcFunc['db_free_result']($request);
  684. // Insert the core theme into the tables.
  685. $smcFunc['db_insert']('ignore',
  686. '{db_prefix}themes',
  687. array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-255'),
  688. array(
  689. array(0, $id_core_theme, 'name', 'Core Theme'),
  690. array(0, $id_core_theme, 'theme_url', $core['theme_url']),
  691. array(0, $id_core_theme, 'images_url', $core['images_url']),
  692. array(0, $id_core_theme, 'theme_dir', $core['theme_dir'])
  693. ),
  694. array()
  695. );
  696. // Update the name of the default theme in the database.
  697. upgrade_query("
  698. UPDATE {$db_prefix}themes
  699. SET value = 'SMF Default Theme - Curve'
  700. WHERE id_theme = 1
  701. AND variable = 'name'");
  702. $newSettings = array();
  703. // Now that we have the old theme details - switch anyone who used the default to it (Make sense?!)
  704. if (!empty($modSettings['theme_default']) && $modSettings['theme_default'] == 1)
  705. $newSettings[] = "('theme_default', $id_core_theme)";
  706. // Did guests use to use the default?
  707. if (!empty($modSettings['theme_guests']) && $modSettings['theme_guests'] == 1)
  708. $newSettings[] = "('theme_guests', $id_core_theme)";
  709. // If known themes aren't set, let's just pick all themes available.
  710. if (empty($modSettings['knownThemes']))
  711. {
  712. $request = upgrade_query("
  713. SELECT DISTINCT id_theme
  714. FROM {$db_prefix}themes");
  715. $themes = array();
  716. while ($row = $smcFunc['db_fetch_assoc']($request))
  717. $themes[] = $row['id_theme'];
  718. $modSettings['knownThemes'] = implode(',', $themes);
  719. upgrade_query("
  720. UPDATE {$db_prefix}settings
  721. SET value = '$modSettings[knownThemes]'
  722. WHERE variable = 'knownThemes'");
  723. }
  724. // Known themes.
  725. $allThemes = explode(',', $modSettings['knownThemes']);
  726. $allThemes[] = $id_core_theme;
  727. $newSettings[] = "('knownThemes', '" . implode(',', $allThemes) . "')";
  728. upgrade_query("
  729. REPLACE INTO {$db_prefix}settings
  730. (variable, value)
  731. VALUES
  732. " . implode(', ', $newSettings));
  733. // What about members?
  734. upgrade_query("
  735. UPDATE {$db_prefix}members
  736. SET id_theme = $id_core_theme
  737. WHERE id_theme = 1");
  738. // Boards?
  739. upgrade_query("
  740. UPDATE {$db_prefix}boards
  741. SET id_theme = $id_core_theme
  742. WHERE id_theme = 1");
  743. // The other themes used to use core as their base theme.
  744. if (isset($core['theme_dir']) && isset($core['theme_url']))
  745. {
  746. $coreBasedThemes = array_diff($allThemes, array(1));
  747. // Exclude the themes that already have a base_theme_dir.
  748. $request = upgrade_query("
  749. SELECT DISTINCT id_theme
  750. FROM {$db_prefix}themes
  751. WHERE variable = 'base_theme_dir'");
  752. while ($row = $smcFunc['db_fetch_assoc']($request))
  753. $coreBasedThemes = array_diff($coreBasedThemes, array($row['id_theme']));
  754. $smcFunc['db_free_result']($request);
  755. // Only base themes if there are templates that need a fall-back.
  756. $insertRows = array();
  757. $request = upgrade_query("
  758. SELECT id_theme, value AS theme_dir
  759. FROM {$db_prefix}themes
  760. WHERE id_theme IN (" . implode(', ', $coreBasedThemes) . ")
  761. AND id_member = 0
  762. AND variable = 'theme_dir'");
  763. while ($row = $smcFunc['db_fetch_assoc']($request))
  764. {
  765. if (!file_exists($row['theme_dir'] . '/BoardIndex.template.php') || !file_exists($row['theme_dir'] . '/Display.template.php') || !file_exists($row['theme_dir'] . '/index.template.php') || !file_exists($row['theme_dir'] . '/MessageIndex.template.php') || !file_exists($row['theme_dir'] . '/Settings.template.php'))
  766. {
  767. $insertRows[] = "(0, $row[id_theme], 'base_theme_dir', '" . addslashes($core['theme_dir']) . "')";
  768. $insertRows[] = "(0, $row[id_theme], 'base_theme_url', '" . addslashes($core['theme_url']) . "')";
  769. }
  770. }
  771. $smcFunc['db_free_result']($request);
  772. if (!empty($insertRows))
  773. foreach ($insertRows as $insertRow)
  774. upgrade_query("
  775. INSERT IGNORE INTO {$db_prefix}themes
  776. (id_member, id_theme, variable, value)
  777. VALUES
  778. " . implode(',
  779. ', $insertRow));
  780. }
  781. }
  782. $smcFunc['db_free_result']($theme_request);
  783. // This ain't running twice either - not with the risk of log_tables timing us all out!
  784. upgrade_query("
  785. REPLACE INTO {$db_prefix}settings
  786. (variable, value)
  787. VALUES
  788. ('dont_repeat_theme_core', '1')");
  789. }
  790. ---}
  791. ---#
  792. /******************************************************************************/
  793. --- Installing new smileys sets...
  794. /******************************************************************************/
  795. ---# Installing new smiley sets...
  796. ---{
  797. // Don't do this twice!
  798. if (empty($modSettings['installed_new_smiley_sets_20']))
  799. {
  800. // First, the entries.
  801. upgrade_query("
  802. UPDATE {$db_prefix}settings
  803. SET value = CONCAT(value, ',aaron,akyhne')
  804. WHERE variable = 'smiley_sets_known'");
  805. // Second, the names.
  806. upgrade_query("
  807. UPDATE {$db_prefix}settings
  808. SET value = CONCAT(value, '\nAaron\nAkyhne')
  809. WHERE variable = 'smiley_sets_names'");
  810. // This ain't running twice either.
  811. upgrade_query("
  812. REPLACE INTO {$db_prefix}settings
  813. (variable, value)
  814. VALUES
  815. ('installed_new_smiley_sets_20', '1')");
  816. }
  817. ---}
  818. ---#
  819. /******************************************************************************/
  820. --- Adding extra columns to reported post comments
  821. /******************************************************************************/
  822. ---# Adding email address and member ip columns...
  823. ---{
  824. $smcFunc['db_alter_table']('{db_prefix}log_reported_comments', array(
  825. 'add' => array(
  826. 'email_address' => array(
  827. 'name' => 'email_address',
  828. 'null' => false,
  829. 'default' => '',
  830. 'type' => 'varchar',
  831. 'size' => 255,
  832. 'auto' => false,
  833. ),
  834. 'member_ip' => array(
  835. 'name' => 'member_ip',
  836. 'null' => false,
  837. 'default' => '',
  838. 'type' => 'varchar',
  839. 'size' => 255,
  840. 'auto' => false,
  841. ),
  842. )
  843. ));
  844. ---}
  845. ---#
  846. /******************************************************************************/
  847. --- Adjusting group types.
  848. /******************************************************************************/
  849. ---# Fixing the group types.
  850. ---{
  851. // Get the admin group type.
  852. $request = upgrade_query("
  853. SELECT group_type
  854. FROM {$db_prefix}membergroups
  855. WHERE id_group = 1
  856. LIMIT 1");
  857. list ($admin_group_type) = mysql_fetch_row($request);
  858. mysql_free_result($request);
  859. // Not protected means we haven't updated yet!
  860. if ($admin_group_type != 1)
  861. {
  862. // Increase by one.
  863. upgrade_query("
  864. UPDATE {$db_prefix}membergroups
  865. SET group_type = group_type + 1
  866. WHERE group_type > 0");
  867. }
  868. ---}
  869. ---#
  870. ---# Changing the group type for Administrator group.
  871. UPDATE {$db_prefix}membergroups
  872. SET group_type = 1
  873. WHERE id_group = 1;
  874. ---#
  875. /******************************************************************************/
  876. --- Adjusting calendar maximum year.
  877. /******************************************************************************/
  878. ---# Adjusting calendar maximum year.
  879. ---{
  880. if (!isset($modSettings['cal_maxyear']) || $modSettings['cal_maxyear'] == '2010')
  881. {
  882. upgrade_query("
  883. REPLACE INTO {$db_prefix}settings
  884. (variable, value)
  885. VALUES
  886. ('cal_maxyear', '2020')");
  887. }
  888. ---}
  889. ---#