upgrade_2-0_sqlite.sql 28 KB

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