upgrade_1-1.sql 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655
  1. /* ATTENTION: You don't need to run or use this file! The upgrade.php script does everything for you! */
  2. /******************************************************************************/
  3. --- Updating and creating indexes...
  4. /******************************************************************************/
  5. ---# Updating indexes on "messages"...
  6. ---{
  7. $request = upgrade_query("
  8. SHOW KEYS
  9. FROM {$db_prefix}messages");
  10. $found = false;
  11. while ($row = smf_mysql_fetch_assoc($request))
  12. $found |= $row['Key_name'] == 'ID_BOARD' && $row['Column_name'] == 'ID_MSG';
  13. smf_mysql_free_result($request);
  14. if (!$found)
  15. upgrade_query("
  16. ALTER TABLE {$db_prefix}messages
  17. DROP INDEX ID_BOARD");
  18. ---}
  19. ---#
  20. ---# Updating table indexes...
  21. ---{
  22. $_GET['mess_ind'] = isset($_GET['mess_ind']) ? (int) $_GET['mess_ind'] : 0;
  23. $step_progress['name'] = 'Updating table indexes';
  24. $step_progress['current'] = $_GET['mess_ind'];
  25. $custom_warning = 'On a very large board these indexes may take a few minutes to create.';
  26. $index_changes = array(
  27. array(
  28. 'table' => 'log_errors',
  29. 'type' => 'index',
  30. 'method' => 'add',
  31. 'name' => 'ID_MEMBER',
  32. 'target_columns' => array('ID_MEMBER'),
  33. 'text' => 'ADD INDEX ID_MEMBER (ID_MEMBER)',
  34. ),
  35. array(
  36. 'table' => 'log_errors',
  37. 'type' => 'index',
  38. 'method' => 'add',
  39. 'name' => 'IP',
  40. 'target_columns' => array('IP'),
  41. 'text' => 'ADD INDEX IP (IP(15))',
  42. ),
  43. array(
  44. 'table' => 'log_online',
  45. 'type' => 'index',
  46. 'method' => 'add',
  47. 'name' => 'logTime',
  48. 'target_columns' => array('logTime'),
  49. 'text' => 'ADD INDEX logTime (logTime)',
  50. ),
  51. array(
  52. 'table' => 'log_online',
  53. 'type' => 'index',
  54. 'method' => 'remove',
  55. 'name' => 'online',
  56. 'target_columns' => array('online'),
  57. 'text' => 'DROP INDEX online',
  58. ),
  59. array(
  60. 'table' => 'smileys',
  61. 'type' => 'index',
  62. 'method' => 'remove',
  63. 'name' => 'smileyOrder',
  64. 'target_columns' => array('smileyOrder'),
  65. 'text' => 'DROP INDEX smileyOrder',
  66. ),
  67. array(
  68. 'table' => 'boards',
  69. 'type' => 'index',
  70. 'method' => 'add',
  71. 'name' => 'ID_PARENT',
  72. 'target_columns' => array('ID_PARENT'),
  73. 'text' => 'ADD INDEX ID_PARENT (ID_PARENT)',
  74. ),
  75. array(
  76. 'table' => 'boards',
  77. 'type' => 'index',
  78. 'method' => 'remove',
  79. 'name' => 'children',
  80. 'target_columns' => array('children'),
  81. 'text' => 'DROP INDEX children',
  82. ),
  83. array(
  84. 'table' => 'boards',
  85. 'type' => 'index',
  86. 'method' => 'remove',
  87. 'name' => 'boardOrder',
  88. 'target_columns' => array('boardOrder'),
  89. 'text' => 'DROP INDEX boardOrder',
  90. ),
  91. array(
  92. 'table' => 'categories',
  93. 'type' => 'index',
  94. 'method' => 'remove',
  95. 'name' => 'catOrder',
  96. 'target_columns' => array('catOrder'),
  97. 'text' => 'DROP INDEX catOrder',
  98. ),
  99. array(
  100. 'table' => 'messages',
  101. 'type' => 'index',
  102. 'method' => 'add',
  103. 'name' => 'ID_TOPIC',
  104. 'target_columns' => array('ID_TOPIC'),
  105. 'text' => 'ADD INDEX ID_TOPIC (ID_TOPIC)',
  106. ),
  107. array(
  108. 'table' => 'messages',
  109. 'type' => 'index',
  110. 'method' => 'remove',
  111. 'name' => 'ID_MEMBER',
  112. 'target_columns' => array('ID_MEMBER'),
  113. 'text' => 'DROP INDEX ID_MEMBER',
  114. ),
  115. array(
  116. 'table' => 'messages',
  117. 'type' => 'index',
  118. 'method' => 'add',
  119. 'name' => 'ID_BOARD',
  120. 'target_columns' => array('ID_BOARD', 'ID_MSG'),
  121. 'text' => 'ADD UNIQUE ID_BOARD (ID_BOARD, ID_MSG)',
  122. ),
  123. array(
  124. 'table' => 'messages',
  125. 'type' => 'index',
  126. 'method' => 'add',
  127. 'name' => 'ID_MEMBER',
  128. 'target_columns' => array('ID_MEMBER', 'ID_MSG'),
  129. 'text' => 'ADD UNIQUE ID_MEMBER (ID_MEMBER, ID_MSG)',
  130. ),
  131. array(
  132. 'table' => 'messages',
  133. 'type' => 'index',
  134. 'method' => 'add',
  135. 'name' => 'showPosts',
  136. 'target_columns' => array('ID_MEMBER', 'ID_BOARD'),
  137. 'text' => 'ADD INDEX showPosts (ID_MEMBER, ID_BOARD)',
  138. ),
  139. );
  140. $step_progress['total'] = count($index_changes);
  141. // Now we loop through the changes and work out where the hell we are.
  142. foreach ($index_changes as $ind => $change)
  143. {
  144. // Already done it?
  145. if ($_GET['mess_ind'] > $ind)
  146. continue;
  147. // Make the index, with all the protection and all.
  148. protected_alter($change, $substep);
  149. // Store this for the next table.
  150. $_GET['mess_ind']++;
  151. $step_progress['current'] = $_GET['mess_ind'];
  152. }
  153. // Clean up.
  154. unset($_GET['mess_ind']);
  155. ---}
  156. ---#
  157. ---# Reordering boards and categories...
  158. ALTER TABLE {$db_prefix}categories
  159. ORDER BY catOrder;
  160. ALTER TABLE {$db_prefix}boards
  161. ORDER BY boardOrder;
  162. ---#
  163. ---# Updating indexes and data on "smileys"...
  164. ALTER TABLE {$db_prefix}smileys
  165. CHANGE COLUMN smileyOrder smileyOrder smallint(5) unsigned NOT NULL default '0';
  166. UPDATE {$db_prefix}smileys
  167. SET filename = 'embarrassed.gif'
  168. WHERE filename = 'embarassed.gif';
  169. ---#
  170. ---# Updating indexes on "log_boards"...
  171. ALTER TABLE {$db_prefix}log_boards
  172. DROP PRIMARY KEY,
  173. ADD PRIMARY KEY (ID_MEMBER, ID_BOARD);
  174. ---#
  175. ---# Updating indexes on "log_mark_read"...
  176. ALTER TABLE {$db_prefix}log_mark_read
  177. DROP PRIMARY KEY,
  178. ADD PRIMARY KEY (ID_MEMBER, ID_BOARD);
  179. ---#
  180. ---# Updating indexes on "themes"...
  181. ALTER TABLE {$db_prefix}themes
  182. DROP PRIMARY KEY,
  183. ADD PRIMARY KEY (ID_THEME, ID_MEMBER, variable(30)),
  184. ADD INDEX ID_MEMBER (ID_MEMBER);
  185. ---#
  186. /******************************************************************************/
  187. --- Reorganizing configuration settings...
  188. /******************************************************************************/
  189. ---# Updating data in "settings"...
  190. REPLACE INTO {$db_prefix}settings
  191. (variable, value)
  192. SELECT 'totalMembers', COUNT(*)
  193. FROM {$db_prefix}members;
  194. UPDATE {$db_prefix}settings
  195. SET variable = 'notify_new_registration'
  196. WHERE variable = 'notify_on_new_registration'
  197. LIMIT 1;
  198. UPDATE IGNORE {$db_prefix}settings
  199. SET variable = 'max_image_width'
  200. WHERE variable = 'maxwidth'
  201. LIMIT 1;
  202. UPDATE IGNORE {$db_prefix}settings
  203. SET variable = 'max_image_height'
  204. WHERE variable = 'maxheight'
  205. LIMIT 1;
  206. UPDATE {$db_prefix}settings
  207. SET value = IF(value = 'sendmail' OR value = '0', '0', '1')
  208. WHERE variable = 'mail_type'
  209. LIMIT 1;
  210. UPDATE IGNORE {$db_prefix}settings
  211. SET variable = 'search_method'
  212. WHERE variable = 'search_match_complete_words'
  213. LIMIT 1;
  214. UPDATE IGNORE {$db_prefix}settings
  215. SET variable = 'allow_disableAnnounce'
  216. WHERE variable = 'notifyAnncmnts_UserDisable'
  217. LIMIT 1;
  218. ---#
  219. ---# Adding new settings...
  220. INSERT IGNORE INTO {$db_prefix}settings
  221. (variable, value)
  222. VALUES ('edit_disable_time', '0'),
  223. ('oldTopicDays', '120'),
  224. ('cal_showeventsoncalendar', '1'),
  225. ('cal_showbdaysoncalendar', '1'),
  226. ('cal_showholidaysoncalendar', '1'),
  227. ('allow_disableAnnounce', '1'),
  228. ('attachmentThumbnails', '1'),
  229. ('attachmentThumbWidth', '150'),
  230. ('attachmentThumbHeight', '150'),
  231. ('max_pm_recipients', '10');
  232. ---{
  233. if (@$modSettings['smfVersion'] < '1.1')
  234. {
  235. // Hopefully 90 days is enough?
  236. upgrade_query("
  237. INSERT INTO {$db_prefix}settings
  238. (variable, value)
  239. VALUES ('disableHashTime', " . (time() + 7776000) . ")");
  240. }
  241. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '1.1 Beta 4')
  242. {
  243. // Enable the buddy list for those used to it.
  244. upgrade_query("
  245. INSERT INTO {$db_prefix}settings
  246. (variable, value)
  247. VALUES ('enable_buddylist', '1')");
  248. }
  249. ---}
  250. ---#
  251. ---# Adding PM spam protection settings.
  252. ---{
  253. if (empty($modSettings['pm_spam_settings']))
  254. {
  255. if (isset($modSettings['max_pm_recipients']))
  256. $modSettings['pm_spam_settings'] = (int) $modSettings['max_pm_recipients'] . ',5,20';
  257. else
  258. $modSettings['pm_spam_settings'] = '10,5,20';
  259. upgrade_query("
  260. INSERT IGNORE INTO {$db_prefix}settings
  261. (variable, value)
  262. VALUES
  263. ('pm_spam_settings', '$modSettings[pm_spam_settings]')");
  264. }
  265. upgrade_query("
  266. DELETE FROM {$db_prefix}settings
  267. WHERE variable = 'max_pm_recipients'");
  268. ---}
  269. ---#
  270. ---# Cleaning old values from "settings"...
  271. DELETE FROM {$db_prefix}settings
  272. WHERE variable IN ('modlog_enabled', 'localCookies', 'globalCookies', 'send_welcomeEmail', 'search_method', 'notify_new_registration', 'removeNestedQuotes', 'smiley_enable', 'smiley_sets_enable')
  273. AND value = '0';
  274. DELETE FROM {$db_prefix}settings
  275. WHERE variable IN ('allow_guestAccess', 'userLanguage', 'allow_editDisplayName', 'allow_hideOnline', 'allow_hideEmail', 'guest_hideContacts', 'titlesEnable', 'search_match_complete_words')
  276. AND value = '0';
  277. DELETE FROM {$db_prefix}settings
  278. WHERE variable IN ('cal_allowspan', 'hitStats', 'queryless_urls', 'disableHostnameLookup', 'messageIcons_enable', 'disallow_sendBody', 'censorWholeWord')
  279. AND value = '0';
  280. DELETE FROM {$db_prefix}settings
  281. WHERE variable IN (
  282. 'totalMessag',
  283. 'redirectMetaRefresh',
  284. 'memberCount',
  285. 'cal_today_u',
  286. 'approve_registration',
  287. 'registration_disabled',
  288. 'requireRegistrationVerification',
  289. 'returnToPost',
  290. 'send_validation',
  291. 'search_max_cached_results',
  292. 'disableTemporaryTables',
  293. 'search_cache_size',
  294. 'enableReportToMod'
  295. );
  296. ---#
  297. ---# Encoding SMTP password...
  298. ---{
  299. // Can't do this more than once, we just can't...
  300. if ((!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && empty($modSettings['dont_repeat_smtp']))
  301. {
  302. if (!empty($modSettings['smtp_password']))
  303. {
  304. upgrade_query("
  305. UPDATE {$db_prefix}settings
  306. SET value = '" . base64_encode($modSettings['smtp_password']) . "'
  307. WHERE variable = 'smtp_password'");
  308. }
  309. // Don't let this run twice!
  310. upgrade_query("
  311. REPLACE INTO {$db_prefix}settings
  312. (variable, value)
  313. VALUES
  314. ('dont_repeat_smtp', '1')");
  315. }
  316. ---}
  317. ---#
  318. ---# Adjusting timezone settings...
  319. ---{
  320. if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
  321. {
  322. $server_offset = mktime(0, 0, 0, 1, 1, 1970);
  323. $timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600);
  324. if (date_default_timezone_set($timezone_id))
  325. upgrade_query("
  326. REPLACE INTO {$db_prefix}settings
  327. (variable, value)
  328. VALUES
  329. ('default_timezone', '$timezone_id')");
  330. }
  331. ---}
  332. ---#
  333. /******************************************************************************/
  334. --- Installing new default theme...
  335. /******************************************************************************/
  336. ---# Installing theme settings...
  337. ---{
  338. // This is Grudge's secret "I'm not a developer" theme install code - keep this quiet ;)
  339. // Firstly, I'm going out of my way to not do this twice!
  340. if ((!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && empty($modSettings['dont_repeat_theme']))
  341. {
  342. // Check it's not already here, just incase.
  343. $theme_request = upgrade_query("
  344. SELECT ID_THEME
  345. FROM {$db_prefix}themes
  346. WHERE variable = 'theme_dir'
  347. AND value LIKE '%babylon'");
  348. // Only do the upgrade if it doesn't find the theme already.
  349. if (smf_mysql_num_rows($theme_request) == 0)
  350. {
  351. // Try to get some settings from the current default theme.
  352. $request = upgrade_query("
  353. SELECT t1.value AS theme_dir, t2.value AS theme_url, t3.value AS images_url
  354. FROM ({$db_prefix}themes AS t1, {$db_prefix}themes AS t2, {$db_prefix}themes AS t3)
  355. WHERE t1.ID_THEME = 1
  356. AND t1.ID_MEMBER = 0
  357. AND t1.variable = 'theme_dir'
  358. AND t2.ID_THEME = 1
  359. AND t2.ID_MEMBER = 0
  360. AND t2.variable = 'theme_url'
  361. AND t3.ID_THEME = 1
  362. AND t3.ID_MEMBER = 0
  363. AND t3.variable = 'images_url'
  364. LIMIT 1");
  365. if (smf_mysql_num_rows($request) != 0)
  366. {
  367. $core = smf_mysql_fetch_assoc($request);
  368. if (substr_count($core['theme_dir'], 'default') === 1)
  369. $babylon['theme_dir'] = strtr($core['theme_dir'], array('default' => 'babylon'));
  370. if (substr_count($core['theme_url'], 'default') === 1)
  371. $babylon['theme_url'] = strtr($core['theme_url'], array('default' => 'babylon'));
  372. if (substr_count($core['images_url'], 'default') === 1)
  373. $babylon['images_url'] = strtr($core['images_url'], array('default' => 'babylon'));
  374. }
  375. smf_mysql_free_result($request);
  376. if (!isset($babylon['theme_dir']))
  377. $babylon['theme_dir'] = addslashes($GLOBALS['boarddir']) . '/Themes/babylon';
  378. if (!isset($babylon['theme_url']))
  379. $babylon['theme_url'] = $GLOBALS['boardurl'] . '/Themes/babylon';
  380. if (!isset($babylon['images_url']))
  381. $babylon['images_url'] = $GLOBALS['boardurl'] . '/Themes/babylon/images';
  382. // Get an available ID_THEME first...
  383. $request = upgrade_query("
  384. SELECT MAX(ID_THEME) + 1
  385. FROM {$db_prefix}themes");
  386. list ($ID_OLD_THEME) = smf_mysql_fetch_row($request);
  387. smf_mysql_free_result($request);
  388. // Insert the babylon theme into the tables.
  389. upgrade_query("
  390. INSERT INTO {$db_prefix}themes
  391. (ID_MEMBER, ID_THEME, variable, value)
  392. VALUES
  393. (0, $ID_OLD_THEME, 'name', 'Babylon Theme'),
  394. (0, $ID_OLD_THEME, 'theme_url', '$babylon[theme_url]'),
  395. (0, $ID_OLD_THEME, 'images_url', '$babylon[images_url]'),
  396. (0, $ID_OLD_THEME, 'theme_dir', '$babylon[theme_dir]')");
  397. $newSettings = array();
  398. // Now that we have the old theme details - switch anyone who used the default to it (Make sense?!)
  399. if (!empty($modSettings['theme_default']) && $modSettings['theme_default'] == 1)
  400. $newSettings[] = "('theme_default', $ID_OLD_THEME)";
  401. // Did guests use to use the default?
  402. if (!empty($modSettings['theme_guests']) && $modSettings['theme_guests'] == 1)
  403. $newSettings[] = "('theme_guests', $ID_OLD_THEME)";
  404. // If known themes aren't set, let's just pick all themes available.
  405. if (empty($modSettings['knownThemes']))
  406. {
  407. $request = upgrade_query("
  408. SELECT DISTINCT ID_THEME
  409. FROM {$db_prefix}themes");
  410. $themes = array();
  411. while ($row = smf_mysql_fetch_assoc($request))
  412. $themes[] = $row['ID_THEME'];
  413. $modSettings['knownThemes'] = implode(',', $themes);
  414. upgrade_query("
  415. UPDATE {$db_prefix}settings
  416. SET value = '$modSettings[knownThemes]'
  417. WHERE variable = 'knownThemes'");
  418. }
  419. // Known themes.
  420. $allThemes = explode(',', $modSettings['knownThemes']);
  421. $allThemes[] = $ID_OLD_THEME;
  422. $newSettings[] = "('knownThemes', '" . implode(',', $allThemes) . "')";
  423. upgrade_query("
  424. REPLACE INTO {$db_prefix}settings
  425. (variable, value)
  426. VALUES
  427. " . implode(', ', $newSettings));
  428. // What about members?
  429. upgrade_query("
  430. UPDATE {$db_prefix}members
  431. SET ID_THEME = $ID_OLD_THEME
  432. WHERE ID_THEME = 1");
  433. // Boards?
  434. upgrade_query("
  435. UPDATE {$db_prefix}boards
  436. SET ID_THEME = $ID_OLD_THEME
  437. WHERE ID_THEME = 1");
  438. // The other themes used to use babylon as their base theme.
  439. if (isset($babylon['theme_dir']) && isset($babylon['theme_url']))
  440. {
  441. $babylonBasedThemes = array_diff($allThemes, array(1));
  442. // Exclude the themes that already have a base_theme_dir.
  443. $request = upgrade_query("
  444. SELECT DISTINCT ID_THEME
  445. FROM {$db_prefix}themes
  446. WHERE variable = 'base_theme_dir'");
  447. while ($row = smf_mysql_fetch_assoc($request))
  448. $babylonBasedThemes = array_diff($babylonBasedThemes, array($row['ID_THEME']));
  449. smf_mysql_free_result($request);
  450. // Only base themes if there are templates that need a fall-back.
  451. $insertRows = array();
  452. $request = upgrade_query("
  453. SELECT ID_THEME, value AS theme_dir
  454. FROM {$db_prefix}themes
  455. WHERE ID_THEME IN (" . implode(', ', $babylonBasedThemes) . ")
  456. AND ID_MEMBER = 0
  457. AND variable = 'theme_dir'");
  458. while ($row = smf_mysql_fetch_assoc($request))
  459. {
  460. 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'))
  461. {
  462. $insertRows[] = "(0, $row[ID_THEME], 'base_theme_dir', '" . addslashes($babylon['theme_dir']) . "')";
  463. $insertRows[] = "(0, $row[ID_THEME], 'base_theme_url', '" . addslashes($babylon['theme_url']) . "')";
  464. }
  465. }
  466. smf_mysql_free_result($request);
  467. if (!empty($insertRows))
  468. upgrade_query("
  469. INSERT IGNORE INTO {$db_prefix}themes
  470. (ID_MEMBER, ID_THEME, variable, value)
  471. VALUES
  472. " . implode(',
  473. ', $insertRows));
  474. }
  475. }
  476. smf_mysql_free_result($theme_request);
  477. // This ain't running twice either - not with the risk of log_tables timing us all out!
  478. upgrade_query("
  479. REPLACE INTO {$db_prefix}settings
  480. (variable, value)
  481. VALUES
  482. ('dont_repeat_theme', '1')");
  483. }
  484. ---}
  485. ---#
  486. /******************************************************************************/
  487. --- Adding and updating member data...
  488. /******************************************************************************/
  489. ---# Renaming personal message tables...
  490. RENAME TABLE {$db_prefix}instant_messages
  491. TO {$db_prefix}personal_messages;
  492. RENAME TABLE {$db_prefix}im_recipients
  493. TO {$db_prefix}pm_recipients;
  494. ---#
  495. ---# Updating indexes on "pm_recipients"...
  496. ALTER TABLE {$db_prefix}pm_recipients
  497. DROP INDEX ID_MEMBER,
  498. ADD UNIQUE ID_MEMBER (ID_MEMBER, deleted, ID_PM);
  499. ---#
  500. ---# Updating columns on "pm_recipients"...
  501. ALTER TABLE {$db_prefix}pm_recipients
  502. ADD COLUMN labels varchar(60) NOT NULL default '-1';
  503. ALTER TABLE {$db_prefix}pm_recipients
  504. CHANGE COLUMN labels labels varchar(60) NOT NULL default '-1';
  505. UPDATE {$db_prefix}pm_recipients
  506. SET labels = '-1'
  507. WHERE labels NOT RLIKE '[0-9,\-]' OR labels = '';
  508. ---#
  509. ---# Updating columns on "members"...
  510. ALTER TABLE {$db_prefix}members
  511. ADD COLUMN messageLabels text NOT NULL,
  512. ADD COLUMN buddy_list tinytext NOT NULL,
  513. ADD COLUMN notifySendBody tinyint(4) NOT NULL default '0',
  514. ADD COLUMN notifyTypes tinyint(4) NOT NULL default '2',
  515. CHANGE COLUMN im_ignore_list pm_ignore_list tinytext NOT NULL,
  516. CHANGE COLUMN im_email_notify pm_email_notify tinyint(4) NOT NULL default '0';
  517. ---#
  518. ---# Updating columns on "members" - part 2...
  519. ALTER TABLE {$db_prefix}members
  520. CHANGE COLUMN secretAnswer secretAnswer varchar(64) NOT NULL default '';
  521. ALTER TABLE {$db_prefix}members
  522. ADD COLUMN memberIP2 tinytext NOT NULL;
  523. ---#
  524. ---# Updating member approval...
  525. ---{
  526. // Although it *shouldn't* matter, best to do it just once to be sure.
  527. if (@$modSettings['smfVersion'] < '1.1')
  528. {
  529. upgrade_query("
  530. UPDATE {$db_prefix}members
  531. SET is_activated = 3
  532. WHERE validation_code = ''
  533. AND is_activated = 0");
  534. }
  535. ---}
  536. ---#
  537. /******************************************************************************/
  538. --- Updating holidays and calendar...
  539. /******************************************************************************/
  540. ---# Adding new holidays...
  541. ---{
  542. $result = upgrade_query("
  543. SELECT ID_HOLIDAY
  544. FROM {$db_prefix}calendar_holidays
  545. WHERE YEAR(eventDate) > 2010
  546. LIMIT 1");
  547. $do_it = smf_mysql_num_rows($result) == 0;
  548. smf_mysql_free_result($result);
  549. if ($do_it)
  550. {
  551. upgrade_query("
  552. INSERT INTO {$db_prefix}calendar_holidays
  553. (title, eventDate)
  554. VALUES
  555. ('Mother\\'s Day', '2011-05-08'),
  556. ('Mother\\'s Day', '2012-05-13'),
  557. ('Mother\\'s Day', '2013-05-12'),
  558. ('Mother\\'s Day', '2014-05-11'),
  559. ('Mother\\'s Day', '2015-05-10'),
  560. ('Mother\\'s Day', '2016-05-08'),
  561. ('Mother\\'s Day', '2017-05-14'),
  562. ('Mother\\'s Day', '2018-05-13'),
  563. ('Mother\\'s Day', '2019-05-12'),
  564. ('Mother\\'s Day', '2020-05-10'),
  565. ('Father\\'s Day', '2011-06-19'),
  566. ('Father\\'s Day', '2012-06-17'),
  567. ('Father\\'s Day', '2013-06-16'),
  568. ('Father\\'s Day', '2014-06-15'),
  569. ('Father\\'s Day', '2015-06-21'),
  570. ('Father\\'s Day', '2016-06-19'),
  571. ('Father\\'s Day', '2017-06-18'),
  572. ('Father\\'s Day', '2018-06-17'),
  573. ('Father\\'s Day', '2019-06-16'),
  574. ('Father\\'s Day', '2020-06-21'),
  575. ('Summer Solstice', '2011-06-21'),
  576. ('Summer Solstice', '2012-06-20'),
  577. ('Summer Solstice', '2013-06-21'),
  578. ('Summer Solstice', '2014-06-21'),
  579. ('Summer Solstice', '2015-06-21'),
  580. ('Summer Solstice', '2016-06-20'),
  581. ('Summer Solstice', '2017-06-20'),
  582. ('Summer Solstice', '2018-06-21'),
  583. ('Summer Solstice', '2019-06-21'),
  584. ('Summer Solstice', '2020-06-20'),
  585. ('Vernal Equinox', '2011-03-20'),
  586. ('Vernal Equinox', '2012-03-20'),
  587. ('Vernal Equinox', '2013-03-20'),
  588. ('Vernal Equinox', '2014-03-20'),
  589. ('Vernal Equinox', '2015-03-20'),
  590. ('Vernal Equinox', '2016-03-19'),
  591. ('Vernal Equinox', '2017-03-20'),
  592. ('Vernal Equinox', '2018-03-20'),
  593. ('Vernal Equinox', '2019-03-20'),
  594. ('Vernal Equinox', '2020-03-19'),
  595. ('Winter Solstice', '2011-12-22'),
  596. ('Winter Solstice', '2012-12-21'),
  597. ('Winter Solstice', '2013-12-21'),
  598. ('Winter Solstice', '2014-12-21'),
  599. ('Winter Solstice', '2015-12-21'),
  600. ('Winter Solstice', '2016-12-21'),
  601. ('Winter Solstice', '2017-12-21'),
  602. ('Winter Solstice', '2018-12-21'),
  603. ('Winter Solstice', '2019-12-21'),
  604. ('Winter Solstice', '2020-12-21'),
  605. ('Autumnal Equinox', '2011-09-23'),
  606. ('Autumnal Equinox', '2012-09-22'),
  607. ('Autumnal Equinox', '2013-09-22'),
  608. ('Autumnal Equinox', '2014-09-22'),
  609. ('Autumnal Equinox', '2015-09-23'),
  610. ('Autumnal Equinox', '2016-09-22'),
  611. ('Autumnal Equinox', '2017-09-22'),
  612. ('Autumnal Equinox', '2018-09-22'),
  613. ('Autumnal Equinox', '2019-09-23'),
  614. ('Autumnal Equinox', '2020-09-22'),
  615. ('Thanksgiving', '2011-11-24'),
  616. ('Thanksgiving', '2012-11-22'),
  617. ('Thanksgiving', '2013-11-21'),
  618. ('Thanksgiving', '2014-11-20'),
  619. ('Thanksgiving', '2015-11-26'),
  620. ('Thanksgiving', '2016-11-24'),
  621. ('Thanksgiving', '2017-11-23'),
  622. ('Thanksgiving', '2018-11-22'),
  623. ('Thanksgiving', '2019-11-21'),
  624. ('Thanksgiving', '2020-11-26'),
  625. ('Memorial Day', '2011-05-30'),
  626. ('Memorial Day', '2012-05-28'),
  627. ('Memorial Day', '2013-05-27'),
  628. ('Memorial Day', '2014-05-26'),
  629. ('Memorial Day', '2015-05-25'),
  630. ('Memorial Day', '2016-05-30'),
  631. ('Memorial Day', '2017-05-29'),
  632. ('Memorial Day', '2018-05-28'),
  633. ('Memorial Day', '2019-05-27'),
  634. ('Memorial Day', '2020-05-25'),
  635. ('Labor Day', '2011-09-05'),
  636. ('Labor Day', '2012-09-03'),
  637. ('Labor Day', '2013-09-09'),
  638. ('Labor Day', '2014-09-08'),
  639. ('Labor Day', '2015-09-07'),
  640. ('Labor Day', '2016-09-05'),
  641. ('Labor Day', '2017-09-04'),
  642. ('Labor Day', '2018-09-03'),
  643. ('Labor Day', '2019-09-09'),
  644. ('Labor Day', '2020-09-07')");
  645. }
  646. ---}
  647. ---#
  648. ---# Updating event start and end dates...
  649. ALTER TABLE {$db_prefix}calendar
  650. DROP INDEX eventDate;
  651. ALTER TABLE {$db_prefix}calendar
  652. CHANGE COLUMN eventDate startDate date NOT NULL default '0001-01-01';
  653. ALTER TABLE {$db_prefix}calendar
  654. CHANGE COLUMN startDate startDate date NOT NULL default '0001-01-01';
  655. UPDATE {$db_prefix}calendar
  656. SET startDate = '0001-01-01'
  657. WHERE startDate = '0000-00-00';
  658. ALTER TABLE {$db_prefix}calendar
  659. ADD COLUMN endDate date NOT NULL default '0001-01-01';
  660. ALTER TABLE {$db_prefix}calendar
  661. CHANGE COLUMN endDate endDate date NOT NULL default '0001-01-01';
  662. UPDATE {$db_prefix}calendar
  663. SET endDate = startDate
  664. WHERE endDate = '0001-01-01'
  665. OR endDate = '0000-00-00';
  666. ALTER TABLE {$db_prefix}calendar
  667. ADD INDEX startDate (startDate),
  668. ADD INDEX endDate (endDate);
  669. ALTER TABLE {$db_prefix}calendar
  670. DROP INDEX ID_TOPIC;
  671. ALTER TABLE {$db_prefix}calendar
  672. ADD INDEX topic (ID_TOPIC, ID_MEMBER);
  673. ALTER TABLE {$db_prefix}calendar_holidays
  674. CHANGE COLUMN eventDate eventDate date NOT NULL default '0001-01-01';
  675. UPDATE {$db_prefix}calendar_holidays
  676. SET eventDate = '0001-01-01'
  677. WHERE eventDate = '0000-00-00';
  678. UPDATE {$db_prefix}calendar_holidays
  679. SET eventDate = CONCAT('0004-', MONTH(eventDate), '-', DAYOFMONTH(eventDate))
  680. WHERE YEAR(eventDate) = 0;
  681. ---#
  682. ---# Converting other date columns...
  683. ALTER TABLE {$db_prefix}log_activity
  684. CHANGE COLUMN startDate date date NOT NULL default '0001-01-01';
  685. ALTER TABLE {$db_prefix}log_activity
  686. CHANGE COLUMN date date date NOT NULL default '0001-01-01';
  687. UPDATE {$db_prefix}log_activity
  688. SET date = '0001-01-01'
  689. WHERE date = '0000-00-00';
  690. ALTER TABLE {$db_prefix}members
  691. CHANGE COLUMN birthdate birthdate date NOT NULL default '0001-01-01';
  692. UPDATE {$db_prefix}members
  693. SET birthdate = '0001-01-01'
  694. WHERE birthdate = '0000-00-00';
  695. UPDATE {$db_prefix}members
  696. SET birthdate = CONCAT('0004-', MONTH(birthdate), '-', DAYOFMONTH(birthdate))
  697. WHERE YEAR(birthdate) = 0;
  698. ---#
  699. /******************************************************************************/
  700. --- Adding custom message icons...
  701. /******************************************************************************/
  702. ---# Checking for an old table...
  703. ---{
  704. $request = upgrade_query("
  705. SHOW COLUMNS
  706. FROM {$db_prefix}message_icons");
  707. $test = false;
  708. while ($request && $row = smf_mysql_fetch_row($request))
  709. $test |= $row[0] == 'Name';
  710. if ($request)
  711. smf_mysql_free_result($request);
  712. if ($test)
  713. {
  714. upgrade_query("
  715. ALTER TABLE {$db_prefix}message_icons
  716. DROP PRIMARY KEY,
  717. CHANGE COLUMN id_icon id_icon smallint(5) unsigned NOT NULL auto_increment PRIMARY KEY,
  718. CHANGE COLUMN Name filename varchar(80) NOT NULL default '',
  719. CHANGE COLUMN Description title varchar(80) NOT NULL default '',
  720. CHANGE COLUMN ID_BOARD ID_BOARD mediumint(8) unsigned NOT NULL default '0',
  721. DROP INDEX id_icon,
  722. ADD COLUMN iconOrder smallint(5) unsigned NOT NULL default '0'");
  723. }
  724. ---}
  725. ---#
  726. ---# Creating "message_icons"...
  727. CREATE TABLE IF NOT EXISTS {$db_prefix}message_icons (
  728. id_icon smallint(5) unsigned NOT NULL auto_increment,
  729. title varchar(80) NOT NULL default '',
  730. filename varchar(80) NOT NULL default '',
  731. ID_BOARD mediumint(8) unsigned NOT NULL default 0,
  732. iconOrder smallint(5) unsigned NOT NULL default 0,
  733. PRIMARY KEY (id_icon),
  734. KEY ID_BOARD (ID_BOARD)
  735. ) ENGINE=MyISAM;
  736. ---#
  737. ---# Inserting "message_icons"...
  738. ---{
  739. // We do not want to do this twice!
  740. if (@$modSettings['smfVersion'] < '1.1')
  741. {
  742. upgrade_query("
  743. INSERT INTO {$db_prefix}message_icons
  744. (filename, title, iconOrder)
  745. VALUES ('xx', 'Standard', '0'),
  746. ('thumbup', 'Thumb Up', '1'),
  747. ('thumbdown', 'Thumb Down', '2'),
  748. ('exclamation', 'Exclamation point', '3'),
  749. ('question', 'Question mark', '4'),
  750. ('lamp', 'Lamp', '5'),
  751. ('smiley', 'Smiley', '6'),
  752. ('angry', 'Angry', '7'),
  753. ('cheesy', 'Cheesy', '8'),
  754. ('grin', 'Grin', '9'),
  755. ('sad', 'Sad', '10'),
  756. ('wink', 'Wink', '11')");
  757. }
  758. ---}
  759. ---#
  760. /******************************************************************************/
  761. --- Adding package servers...
  762. /******************************************************************************/
  763. ---# Creating "package_servers"...
  764. CREATE TABLE IF NOT EXISTS {$db_prefix}package_servers (
  765. id_server smallint(5) unsigned NOT NULL auto_increment,
  766. name tinytext NOT NULL,
  767. url tinytext NOT NULL,
  768. PRIMARY KEY (id_server)
  769. ) ENGINE=MyISAM;
  770. ---#
  771. ---# Inserting "package_servers"...
  772. INSERT IGNORE INTO {$db_prefix}package_servers
  773. (id_server, name, url)
  774. VALUES
  775. (1, 'Simple Machines Third-party Mod Site', 'http://mods.simplemachines.org');
  776. ---#
  777. /******************************************************************************/
  778. --- Cleaning up database...
  779. /******************************************************************************/
  780. ---# Updating flood control log...
  781. ALTER IGNORE TABLE {$db_prefix}log_floodcontrol
  782. CHANGE COLUMN ip ip char(16) NOT NULL default ' ';
  783. ALTER TABLE {$db_prefix}log_floodcontrol
  784. DROP INDEX logTime;
  785. ---#
  786. ---# Updating ip address storage...
  787. ALTER IGNORE TABLE {$db_prefix}log_actions
  788. CHANGE COLUMN IP ip char(16) NOT NULL default ' ';
  789. ALTER IGNORE TABLE {$db_prefix}log_banned
  790. CHANGE COLUMN IP ip char(16) NOT NULL default ' ';
  791. ALTER IGNORE TABLE {$db_prefix}log_banned
  792. DROP COLUMN ban_ids;
  793. ALTER IGNORE TABLE {$db_prefix}log_errors
  794. DROP INDEX IP,
  795. CHANGE COLUMN IP ip char(16) NOT NULL default ' ',
  796. ADD INDEX ip (ip(16));
  797. ---#
  798. ---# Converting "log_online"...
  799. DROP TABLE IF EXISTS {$db_prefix}log_online;
  800. CREATE TABLE {$db_prefix}log_online (
  801. session char(32) NOT NULL default ' ',
  802. logTime timestamp /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */,
  803. ID_MEMBER mediumint(8) unsigned NOT NULL default '0',
  804. ip int(10) unsigned NOT NULL default '0',
  805. url text NOT NULL,
  806. PRIMARY KEY (session),
  807. KEY online (logTime, ID_MEMBER),
  808. KEY ID_MEMBER (ID_MEMBER)
  809. ) ENGINE=MyISAM;
  810. ---#
  811. ---# Updating poll column sizes...
  812. ALTER TABLE {$db_prefix}polls
  813. CHANGE COLUMN maxVotes maxVotes tinyint(3) unsigned NOT NULL default '1',
  814. CHANGE COLUMN hideResults hideResults tinyint(3) unsigned NOT NULL default '0',
  815. CHANGE COLUMN changeVote changeVote tinyint(3) unsigned NOT NULL default '0';
  816. ALTER TABLE {$db_prefix}poll_choices
  817. CHANGE COLUMN ID_CHOICE ID_CHOICE tinyint(3) unsigned NOT NULL default '0';
  818. ALTER TABLE {$db_prefix}log_polls
  819. CHANGE COLUMN ID_CHOICE ID_CHOICE tinyint(3) unsigned NOT NULL default '0';
  820. ---#
  821. ---# Updating attachments table...
  822. ALTER TABLE {$db_prefix}attachments
  823. DROP PRIMARY KEY,
  824. CHANGE COLUMN ID_ATTACH ID_ATTACH int(10) unsigned NOT NULL auto_increment PRIMARY KEY;
  825. ---#
  826. ---# Updating boards and topics...
  827. ALTER TABLE {$db_prefix}topics
  828. CHANGE COLUMN numReplies numReplies int(10) unsigned NOT NULL default 0,
  829. CHANGE COLUMN numViews numViews int(10) unsigned NOT NULL default 0;
  830. ---#
  831. ---# Updating members...
  832. ALTER TABLE {$db_prefix}members
  833. CHANGE COLUMN lastLogin lastLogin int(10) unsigned NOT NULL default 0;
  834. ---#
  835. ---# Recounting member pm totals (step 1)...
  836. ---{
  837. $request = upgrade_query("
  838. SELECT COUNT(*)
  839. FROM {$db_prefix}members");
  840. list ($totalMembers) = smf_mysql_fetch_row($request);
  841. smf_mysql_free_result($request);
  842. $_GET['m'] = isset($_GET['m']) ? (int) $_GET['m'] : 0;
  843. while ($_GET['m'] < $totalMembers)
  844. {
  845. nextSubstep($substep);
  846. $mrequest = upgrade_query("
  847. SELECT mem.ID_MEMBER, COUNT(pmr.ID_PM) AS instantMessages_real, mem.instantMessages
  848. FROM {$db_prefix}members AS mem
  849. LEFT JOIN {$db_prefix}pm_recipients AS pmr ON (pmr.ID_MEMBER = mem.ID_MEMBER AND pmr.deleted = 0)
  850. WHERE mem.ID_MEMBER > $_GET[m]
  851. AND mem.ID_MEMBER <= $_GET[m] + 128
  852. GROUP BY mem.ID_MEMBER
  853. HAVING instantMessages_real != instantMessages
  854. LIMIT 256");
  855. while ($row = smf_mysql_fetch_assoc($mrequest))
  856. {
  857. upgrade_query("
  858. UPDATE {$db_prefix}members
  859. SET instantMessages = $row[instantMessages_real]
  860. WHERE ID_MEMBER = $row[ID_MEMBER]
  861. LIMIT 1");
  862. }
  863. $_GET['m'] += 128;
  864. }
  865. unset($_GET['m']);
  866. ---}
  867. ---#
  868. ---# Recounting member pm totals (step 2)...
  869. ---{
  870. $request = upgrade_query("
  871. SELECT COUNT(*)
  872. FROM {$db_prefix}members");
  873. list ($totalMembers) = smf_mysql_fetch_row($request);
  874. smf_mysql_free_result($request);
  875. $_GET['m'] = isset($_GET['m']) ? (int) $_GET['m'] : 0;
  876. while ($_GET['m'] < $totalMembers)
  877. {
  878. nextSubstep($substep);
  879. $mrequest = upgrade_query("
  880. SELECT mem.ID_MEMBER, COUNT(pmr.ID_PM) AS unreadMessages_real, mem.unreadMessages
  881. FROM {$db_prefix}members AS mem
  882. LEFT JOIN {$db_prefix}pm_recipients AS pmr ON (pmr.ID_MEMBER = mem.ID_MEMBER AND pmr.deleted = 0 AND pmr.is_read = 0)
  883. WHERE mem.ID_MEMBER > $_GET[m]
  884. AND mem.ID_MEMBER <= $_GET[m] + 128
  885. GROUP BY mem.ID_MEMBER
  886. HAVING unreadMessages_real != unreadMessages
  887. LIMIT 256");
  888. while ($row = smf_mysql_fetch_assoc($mrequest))
  889. {
  890. upgrade_query("
  891. UPDATE {$db_prefix}members
  892. SET unreadMessages = $row[unreadMessages_real]
  893. WHERE ID_MEMBER = $row[ID_MEMBER]
  894. LIMIT 1");
  895. }
  896. $_GET['m'] += 128;
  897. }
  898. unset($_GET['m']);
  899. ---}
  900. ---#
  901. /******************************************************************************/
  902. --- Converting avatar permissions...
  903. /******************************************************************************/
  904. ---# Converting server stored setting...
  905. ---{
  906. if (!empty($modSettings['avatar_allow_server_stored']))
  907. {
  908. // Create permissions for existing membergroups.
  909. upgrade_query("
  910. INSERT INTO {$db_prefix}permissions
  911. (ID_GROUP, permission)
  912. SELECT IF(ID_GROUP = 1, 0, ID_GROUP), 'profile_server_avatar'
  913. FROM {$db_prefix}membergroups
  914. WHERE ID_GROUP != 3
  915. AND minPosts = -1");
  916. }
  917. ---}
  918. ---#
  919. ---# Converting avatar upload setting...
  920. ---{
  921. // Do the same, but for uploading avatars.
  922. if (!empty($modSettings['avatar_allow_upload']))
  923. {
  924. // Put in these permissions
  925. upgrade_query("
  926. INSERT INTO {$db_prefix}permissions
  927. (ID_GROUP, permission)
  928. SELECT IF(ID_GROUP = 1, 0, ID_GROUP), 'profile_upload_avatar'
  929. FROM {$db_prefix}membergroups
  930. WHERE ID_GROUP != 3
  931. AND minPosts = -1");
  932. }
  933. ---}
  934. ---#
  935. /******************************************************************************/
  936. --- Adjusting uploadable avatars...
  937. /******************************************************************************/
  938. ---# Updating attachments...
  939. ALTER TABLE {$db_prefix}attachments
  940. CHANGE COLUMN ID_MEMBER ID_MEMBER mediumint(8) unsigned NOT NULL default '0';
  941. ---#
  942. ---# Updating settings...
  943. DELETE FROM {$db_prefix}settings
  944. WHERE variable IN ('avatar_allow_external_url', 'avatar_check_size', 'avatar_allow_upload', 'avatar_allow_server_stored');
  945. ---#
  946. /******************************************************************************/
  947. --- Updating thumbnails...
  948. /******************************************************************************/
  949. ---# Registering thumbs...
  950. ---{
  951. // Checkout the current structure of the attachment table.
  952. $request = upgrade_query("
  953. SHOW COLUMNS
  954. FROM {$db_prefix}attachments");
  955. $has_customAvatarDir_column = false;
  956. $has_attachmentType_column = false;
  957. while ($row = smf_mysql_fetch_assoc($request))
  958. {
  959. $has_customAvatarDir_column |= $row['Field'] == 'customAvatarDir';
  960. $has_attachmentType_column |= $row['Field'] == 'attachmentType';
  961. }
  962. smf_mysql_free_result($request);
  963. // Post SMF 1.1 Beta 1.
  964. if ($has_customAvatarDir_column)
  965. $request = upgrade_query("
  966. ALTER TABLE {$db_prefix}attachments
  967. CHANGE COLUMN customAvatarDir attachmentType tinyint(3) unsigned NOT NULL default '0'");
  968. // Pre SMF 1.1.
  969. elseif (!$has_attachmentType_column)
  970. $request = upgrade_query("
  971. ALTER TABLE {$db_prefix}attachments
  972. ADD COLUMN attachmentType tinyint(3) unsigned NOT NULL default '0'");
  973. if (!$has_attachmentType_column)
  974. {
  975. $request = upgrade_query("
  976. ALTER TABLE {$db_prefix}attachments
  977. ADD COLUMN id_thumb int(10) unsigned NOT NULL default '0' AFTER ID_ATTACH,
  978. ADD COLUMN width mediumint(8) unsigned NOT NULL default '0',
  979. ADD COLUMN height mediumint(8) unsigned NOT NULL default '0'");
  980. // Get a list of attachments currently stored in the database.
  981. $request = upgrade_query("
  982. SELECT ID_ATTACH, ID_MSG, filename
  983. FROM {$db_prefix}attachments");
  984. $filenames = array();
  985. $encrypted_filenames = array();
  986. $ID_MSG = array();
  987. while ($row = smf_mysql_fetch_assoc($request))
  988. {
  989. $clean_name = strtr($row['filename'], 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
  990. $clean_name = strtr($clean_name, array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u'));
  991. $clean_name = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $clean_name);
  992. $enc_name = $row['ID_ATTACH'] . '_' . strtr($clean_name, '.', '_') . md5($clean_name);
  993. $clean_name = preg_replace('~\.[\.]+~', '.', $clean_name);
  994. if (file_exists($modSettings['attachmentUploadDir'] . '/' . $enc_name))
  995. $filename = $enc_name;
  996. elseif (file_exists($modSettings['attachmentUploadDir'] . '/' . $clean_name))
  997. $filename = $clean_name;
  998. else
  999. $filename = $row['filename'];
  1000. $filenames[$row['ID_ATTACH']] = $clean_name;
  1001. $encrypted_filenames[$row['ID_ATTACH']] = $filename;
  1002. $ID_MSG[$row['ID_ATTACH']] = $row['ID_MSG'];
  1003. }
  1004. smf_mysql_free_result($request);
  1005. // Let's loop through the attachments
  1006. if (is_dir($modSettings['attachmentUploadDir']) && $dir = @opendir($modSettings['attachmentUploadDir']))
  1007. {
  1008. while ($file = readdir($dir))
  1009. {
  1010. if (substr($file, -6) == '_thumb')
  1011. {
  1012. // We found a thumbnail, now find the attachment it represents.
  1013. $attach_realFilename = substr($file, 0, -6);
  1014. if (in_array($attach_realFilename, $filenames))
  1015. {
  1016. $attach_id = array_search($attach_realFilename, $filenames);
  1017. $attach_filename = $attach_realFilename;
  1018. }
  1019. elseif (in_array($attach_realFilename, $encrypted_filenames))
  1020. {
  1021. $attach_id = array_search($attach_realFilename, $encrypted_filenames);
  1022. $attach_filename = $filenames[$attach_id];
  1023. }
  1024. else
  1025. continue;
  1026. // No need to register thumbs of non-existent attachments.
  1027. if (!file_exists($modSettings['attachmentUploadDir'] . '/' . $attach_realFilename) || strlen($attach_filename) > 249)
  1028. continue;
  1029. // Determine the dimensions of the thumb.
  1030. list ($thumb_width, $thumb_height) = @getimagesize($modSettings['attachmentUploadDir'] . '/' . $file);
  1031. $thumb_size = filesize($modSettings['attachmentUploadDir'] . '/' . $file);
  1032. $thumb_filename = $attach_filename . '_thumb';
  1033. // Insert the thumbnail in the attachment database.
  1034. upgrade_query("
  1035. INSERT INTO {$db_prefix}attachments
  1036. (ID_MSG, attachmentType, filename, size, width, height)
  1037. VALUES (" . $ID_MSG[$attach_id] . ", 3, '$thumb_filename', " . (int) $thumb_size . ', ' . (int) $thumb_width . ', ' . (int) $thumb_height . ')');
  1038. $thumb_attach_id = smf_mysql_insert_id();
  1039. // Determine the dimensions of the original attachment.
  1040. $attach_width = $attach_height = 0;
  1041. list ($attach_width, $attach_height) = @getimagesize($modSettings['attachmentUploadDir'] . '/' . $attach_realFilename);
  1042. // Link the original attachment to its thumb.
  1043. upgrade_query("
  1044. UPDATE {$db_prefix}attachments
  1045. SET
  1046. id_thumb = $thumb_attach_id,
  1047. width = " . (int) $attach_width . ",
  1048. height = " . (int) $attach_height . "
  1049. WHERE ID_ATTACH = $attach_id
  1050. LIMIT 1");
  1051. // Since it's an attachment now, we might as well encrypt it.
  1052. if (!empty($modSettings['attachmentEncryptFilenames']))
  1053. @rename($modSettings['attachmentUploadDir'] . '/' . $file, $modSettings['attachmentUploadDir'] . '/' . $thumb_attach_id . '_' . strtr($thumb_filename, '.', '_') . md5($thumb_filename));
  1054. }
  1055. }
  1056. closedir($dir);
  1057. }
  1058. }
  1059. ---}
  1060. ---#
  1061. ---# Adding image dimensions...
  1062. ---{
  1063. // Now add dimension to the images that have no thumb (yet).
  1064. $request = upgrade_query("
  1065. SELECT ID_ATTACH, filename, attachmentType
  1066. FROM {$db_prefix}attachments
  1067. WHERE id_thumb = 0
  1068. AND (RIGHT(filename, 4) IN ('.gif', '.jpg', '.png', '.bmp') OR RIGHT(filename, 5) = '.jpeg')
  1069. AND width = 0
  1070. AND height = 0");
  1071. while ($row = smf_mysql_fetch_assoc($request))
  1072. {
  1073. if ($row['attachmentType'] == 1)
  1074. $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename'];
  1075. else
  1076. {
  1077. $clean_name = strtr($row['filename'], 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
  1078. $clean_name = strtr($clean_name, array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u'));
  1079. $clean_name = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $clean_name);
  1080. $enc_name = $row['ID_ATTACH'] . '_' . strtr($clean_name, '.', '_') . md5($clean_name);
  1081. $clean_name = preg_replace('~\.[\.]+~', '.', $clean_name);
  1082. if (file_exists($modSettings['attachmentUploadDir'] . '/' . $enc_name))
  1083. $filename = $modSettings['attachmentUploadDir'] . '/' . $enc_name;
  1084. elseif (file_exists($modSettings['attachmentUploadDir'] . '/' . $clean_name))
  1085. $filename = $modSettings['attachmentUploadDir'] . '/' . $clean_name;
  1086. else
  1087. $filename = $modSettings['attachmentUploadDir'] . '/' . $row['filename'];
  1088. }
  1089. $width = 0;
  1090. $height = 0;
  1091. list ($width, $height) = @getimagesize($filename);
  1092. if (!empty($width) && !empty($height))
  1093. upgrade_query("
  1094. UPDATE {$db_prefix}attachments
  1095. SET
  1096. width = $width,
  1097. height = $height
  1098. WHERE ID_ATTACH = $row[ID_ATTACH]
  1099. LIMIT 1");
  1100. }
  1101. smf_mysql_free_result($request);
  1102. ---}
  1103. ---#
  1104. /******************************************************************************/
  1105. --- Updating ban system...
  1106. /******************************************************************************/
  1107. ---# Splitting ban table...
  1108. ---{
  1109. // Checkout the current structure of the attachment table.
  1110. $request = upgrade_query("
  1111. SHOW TABLES
  1112. LIKE '{$db_prefix}banned'");
  1113. $upgradeBanTable = smf_mysql_num_rows($request) == 1;
  1114. smf_mysql_free_result($request);
  1115. if ($upgradeBanTable)
  1116. {
  1117. upgrade_query("
  1118. RENAME TABLE {$db_prefix}banned
  1119. TO {$db_prefix}ban_groups");
  1120. upgrade_query("
  1121. ALTER TABLE {$db_prefix}ban_groups
  1122. CHANGE COLUMN id_ban id_ban_group mediumint(8) unsigned NOT NULL auto_increment");
  1123. upgrade_query("
  1124. CREATE TABLE IF NOT EXISTS {$db_prefix}ban_items (
  1125. id_ban mediumint(8) unsigned NOT NULL auto_increment,
  1126. id_ban_group smallint(5) unsigned NOT NULL default '0',
  1127. ip_low1 tinyint(3) unsigned NOT NULL default '0',
  1128. ip_high1 tinyint(3) unsigned NOT NULL default '0',
  1129. ip_low2 tinyint(3) unsigned NOT NULL default '0',
  1130. ip_high2 tinyint(3) unsigned NOT NULL default '0',
  1131. ip_low3 tinyint(3) unsigned NOT NULL default '0',
  1132. ip_high3 tinyint(3) unsigned NOT NULL default '0',
  1133. ip_low4 tinyint(3) unsigned NOT NULL default '0',
  1134. ip_high4 tinyint(3) unsigned NOT NULL default '0',
  1135. hostname tinytext NOT NULL,
  1136. email_address tinytext NOT NULL,
  1137. ID_MEMBER mediumint(8) unsigned NOT NULL default '0',
  1138. hits mediumint(8) unsigned NOT NULL default '0',
  1139. PRIMARY KEY (id_ban),
  1140. KEY id_ban_group (id_ban_group)
  1141. ) ENGINE=MyISAM");
  1142. upgrade_query("
  1143. INSERT INTO {$db_prefix}ban_items
  1144. (id_ban_group, ip_low1, ip_high1, ip_low2, ip_high2, ip_low3, ip_high3, ip_low4, ip_high4, hostname, email_address, ID_MEMBER)
  1145. SELECT id_ban_group, ip_low1, ip_high1, ip_low2, ip_high2, ip_low3, ip_high3, ip_low4, ip_high4, hostname, email_address, ID_MEMBER
  1146. FROM {$db_prefix}ban_groups");
  1147. upgrade_query("
  1148. ALTER TABLE {$db_prefix}ban_groups
  1149. DROP COLUMN ban_type,
  1150. DROP COLUMN ip_low1,
  1151. DROP COLUMN ip_high1,
  1152. DROP COLUMN ip_low2,
  1153. DROP COLUMN ip_high2,
  1154. DROP COLUMN ip_low3,
  1155. DROP COLUMN ip_high3,
  1156. DROP COLUMN ip_low4,
  1157. DROP COLUMN ip_high4,
  1158. DROP COLUMN hostname,
  1159. DROP COLUMN email_address,
  1160. DROP COLUMN ID_MEMBER,
  1161. ADD COLUMN cannot_access tinyint(3) unsigned NOT NULL default '0' AFTER expire_time,
  1162. ADD COLUMN cannot_register tinyint(3) unsigned NOT NULL default '0' AFTER cannot_access,
  1163. ADD COLUMN cannot_post tinyint(3) unsigned NOT NULL default '0' AFTER cannot_register,
  1164. ADD COLUMN cannot_login tinyint(3) unsigned NOT NULL default '0' AFTER cannot_post");
  1165. // Generate names for existing bans.
  1166. upgrade_query("
  1167. ALTER TABLE {$db_prefix}ban_groups
  1168. ADD COLUMN name varchar(20) NOT NULL default '' AFTER id_ban_group");
  1169. $request = upgrade_query("
  1170. SELECT id_ban_group, restriction_type
  1171. FROM {$db_prefix}ban_groups
  1172. ORDER BY ban_time ASC");
  1173. $ban_names = array(
  1174. 'full_ban' => 1,
  1175. 'cannot_register' => 1,
  1176. 'cannot_post' => 1,
  1177. );
  1178. if ($request != false)
  1179. {
  1180. while ($row = smf_mysql_fetch_assoc($request))
  1181. upgrade_query("
  1182. UPDATE {$db_prefix}ban_groups
  1183. SET name = '" . $row['restriction_type'] . '_' . str_pad($ban_names[$row['restriction_type']]++, 3, '0', STR_PAD_LEFT) . "'
  1184. WHERE id_ban_group = $row[id_ban_group]");
  1185. smf_mysql_free_result($request);
  1186. }
  1187. // Move each restriction type to its own column.
  1188. upgrade_query("
  1189. UPDATE {$db_prefix}ban_groups
  1190. SET
  1191. cannot_access = IF(restriction_type = 'full_ban', 1, 0),
  1192. cannot_register = IF(restriction_type = 'cannot_register', 1, 0),
  1193. cannot_post = IF(restriction_type = 'cannot_post', 1, 0)");
  1194. upgrade_query("
  1195. ALTER TABLE {$db_prefix}ban_groups
  1196. DROP COLUMN restriction_type");
  1197. // Make sure everybody's ban situation is re-evaluated.
  1198. upgrade_query("
  1199. UPDATE {$db_prefix}settings
  1200. SET value = '" . time() . "'
  1201. WHERE variable = 'banLastUpdated'");
  1202. }
  1203. ---}
  1204. ---#
  1205. ---# Updating ban statistics...
  1206. ---{
  1207. $request = upgrade_query("
  1208. SELECT mem.ID_MEMBER, mem.is_activated + 10 AS new_value
  1209. FROM ({$db_prefix}ban_groups AS bg, {$db_prefix}ban_items AS bi, {$db_prefix}members AS mem)
  1210. WHERE bg.id_ban_group = bi.id_ban_group
  1211. AND bg.cannot_access = 1
  1212. AND (bg.expire_time IS NULL OR bg.expire_time > " . time() . ")
  1213. AND (mem.ID_MEMBER = bi.ID_MEMBER OR mem.emailAddress LIKE bi.email_address)
  1214. AND mem.is_activated < 10");
  1215. $updates = array();
  1216. while ($row = smf_mysql_fetch_assoc($request))
  1217. $updates[$row['new_value']][] = $row['ID_MEMBER'];
  1218. smf_mysql_free_result($request);
  1219. // Find members that are wrongfully marked as banned.
  1220. $request = upgrade_query("
  1221. SELECT mem.ID_MEMBER, mem.is_activated - 10 AS new_value
  1222. FROM {$db_prefix}members AS mem
  1223. LEFT JOIN {$db_prefix}ban_items AS bi ON (bi.ID_MEMBER = mem.ID_MEMBER OR mem.emailAddress LIKE bi.email_address)
  1224. LEFT JOIN {$db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND bg.cannot_access = 1 AND (bg.expire_time IS NULL OR bg.expire_time > " . time() . "))
  1225. WHERE (bi.id_ban IS NULL OR bg.id_ban_group IS NULL)
  1226. AND mem.is_activated >= 10");
  1227. while ($row = smf_mysql_fetch_assoc($request))
  1228. $updates[$row['new_value']][] = $row['ID_MEMBER'];
  1229. smf_mysql_free_result($request);
  1230. if (!empty($updates))
  1231. foreach ($updates as $newStatus => $members)
  1232. upgrade_query("
  1233. UPDATE {$db_prefix}members
  1234. SET is_activated = $newStatus
  1235. WHERE ID_MEMBER IN (" . implode(', ', $members) . ")
  1236. LIMIT " . count($members));
  1237. ---}
  1238. ---#
  1239. /******************************************************************************/
  1240. --- Updating permissions...
  1241. /******************************************************************************/
  1242. ---# Deleting some very old permissions...
  1243. DELETE FROM {$db_prefix}board_permissions
  1244. WHERE permission IN ('view_threads', 'poll_delete_own', 'poll_delete_any', 'profile_edit_own', 'profile_edit_any');
  1245. ---#
  1246. ---# Renaming permissions...
  1247. ---{
  1248. // We *cannot* do this twice!
  1249. if (@$modSettings['smfVersion'] < '1.1')
  1250. {
  1251. upgrade_query("
  1252. UPDATE {$db_prefix}board_permissions
  1253. SET
  1254. permission = REPLACE(permission, 'remove_replies', 'delete_replies'),
  1255. permission = REPLACE(permission, 'remove_own', 'delete2_own'),
  1256. permission = REPLACE(permission, 'remove_any', 'delete2_any')");
  1257. upgrade_query("
  1258. UPDATE {$db_prefix}board_permissions
  1259. SET
  1260. permission = REPLACE(permission, 'delete_own', 'remove_own'),
  1261. permission = REPLACE(permission, 'delete_any', 'remove_any')");
  1262. upgrade_query("
  1263. UPDATE {$db_prefix}board_permissions
  1264. SET
  1265. permission = REPLACE(permission, 'delete2_own', 'delete_own'),
  1266. permission = REPLACE(permission, 'delete2_any', 'delete_any')");
  1267. }
  1268. ---}
  1269. ---#
  1270. ---# Upgrading "deny"-permissions...
  1271. ---{
  1272. if (!isset($modSettings['permission_enable_deny']))
  1273. {
  1274. // Only disable if no deny permissions are used.
  1275. $request = upgrade_query("
  1276. SELECT permission
  1277. FROM {$db_prefix}permissions
  1278. WHERE addDeny = 0
  1279. LIMIT 1");
  1280. $disable_deny_permissions = smf_mysql_num_rows($request) == 0;
  1281. smf_mysql_free_result($request);
  1282. // Still wanna disable deny permissions? Check board permissions.
  1283. if ($disable_deny_permissions)
  1284. {
  1285. $request = upgrade_query("
  1286. SELECT permission
  1287. FROM {$db_prefix}board_permissions
  1288. WHERE addDeny = 0
  1289. LIMIT 1");
  1290. $disable_deny_permissions &= smf_mysql_num_rows($request) == 0;
  1291. smf_mysql_free_result($request);
  1292. }
  1293. $request = upgrade_query("
  1294. INSERT INTO {$db_prefix}settings
  1295. (variable, value)
  1296. VALUES ('permission_enable_deny', '" . ($disable_deny_permissions ? '0' : '1') . "')");
  1297. }
  1298. ---}
  1299. ---#
  1300. ---# Upgrading post based group permissions...
  1301. ---{
  1302. if (!isset($modSettings['permission_enable_postgroups']))
  1303. {
  1304. // Only disable if no post group permissions are used.
  1305. $disable_postgroup_permissions = true;
  1306. $request = upgrade_query("
  1307. SELECT p.permission
  1308. FROM ({$db_prefix}permissions AS p, {$db_prefix}membergroups AS mg)
  1309. WHERE mg.ID_GROUP = p.ID_GROUP
  1310. AND mg.minPosts != -1
  1311. LIMIT 1");
  1312. $disable_postgroup_permissions &= smf_mysql_num_rows($request) == 0;
  1313. smf_mysql_free_result($request);
  1314. // Still wanna disable postgroup permissions? Check board permissions.
  1315. if ($disable_postgroup_permissions)
  1316. {
  1317. $request = upgrade_query("
  1318. SELECT bp.permission
  1319. FROM ({$db_prefix}board_permissions AS bp, {$db_prefix}membergroups AS mg)
  1320. WHERE mg.ID_GROUP = bp.ID_GROUP
  1321. AND mg.minPosts != -1
  1322. LIMIT 1");
  1323. $disable_postgroup_permissions &= smf_mysql_num_rows($request) == 0;
  1324. smf_mysql_free_result($request);
  1325. }
  1326. $request = upgrade_query("
  1327. INSERT INTO {$db_prefix}settings
  1328. (variable, value)
  1329. VALUES ('permission_enable_postgroups', '" . ($disable_postgroup_permissions ? '0' : '1') . "')");
  1330. }
  1331. ---}
  1332. ---#
  1333. ---# Upgrading by-board permissions...
  1334. ALTER TABLE {$db_prefix}boards
  1335. CHANGE COLUMN use_local_permissions permission_mode tinyint(4) unsigned NOT NULL default '0';
  1336. ---{
  1337. if (!isset($modSettings['permission_enable_by_board']))
  1338. {
  1339. // Enable by-board permissions if there's >= 1 local permission board.
  1340. $request = upgrade_query("
  1341. SELECT ID_BOARD
  1342. FROM {$db_prefix}boards
  1343. WHERE permission_mode = 1
  1344. LIMIT 1");
  1345. $enable_by_board = smf_mysql_num_rows($request) == 1 ? '1' : '0';
  1346. smf_mysql_free_result($request);
  1347. $request = upgrade_query("
  1348. INSERT INTO {$db_prefix}settings
  1349. (variable, value)
  1350. VALUES ('permission_enable_by_board', '$enable_by_board')");
  1351. }
  1352. ---}
  1353. ---#
  1354. ---# Removing all guest deny permissions...
  1355. DELETE FROM {$db_prefix}permissions
  1356. WHERE ID_GROUP = -1
  1357. AND addDeny = 0;
  1358. DELETE FROM {$db_prefix}board_permissions
  1359. WHERE ID_GROUP = -1
  1360. AND addDeny = 0;
  1361. ---#
  1362. ---# Removing guest admin permissions (if any)...
  1363. DELETE FROM {$db_prefix}permissions
  1364. WHERE ID_GROUP = -1
  1365. AND permission IN ('admin_forum', 'manage_boards', 'manage_attachments', 'manage_smileys', 'edit_news', 'moderate_forum', 'manage_membergroups', 'manage_permissions', 'manage_bans', 'send_mail');
  1366. DELETE FROM {$db_prefix}board_permissions
  1367. WHERE ID_GROUP = -1
  1368. AND permission IN ('admin_forum', 'manage_boards', 'manage_attachments', 'manage_smileys', 'edit_news', 'moderate_forum', 'manage_membergroups', 'manage_permissions', 'manage_bans', 'send_mail');
  1369. ---#
  1370. /******************************************************************************/
  1371. --- Updating search cache...
  1372. /******************************************************************************/
  1373. ---# Creating search cache tables...
  1374. DROP TABLE IF EXISTS {$db_prefix}log_search_fulltext;
  1375. DROP TABLE IF EXISTS {$db_prefix}log_search_messages;
  1376. DROP TABLE IF EXISTS {$db_prefix}log_search_topics;
  1377. DROP TABLE IF EXISTS {$db_prefix}log_search;
  1378. CREATE TABLE IF NOT EXISTS {$db_prefix}log_search_messages (
  1379. id_search tinyint(3) unsigned NOT NULL default '0',
  1380. ID_MSG int(10) NOT NULL default '0',
  1381. PRIMARY KEY (id_search, ID_MSG)
  1382. ) ENGINE=MyISAM;
  1383. CREATE TABLE IF NOT EXISTS {$db_prefix}log_search_topics (
  1384. id_search tinyint(3) unsigned NOT NULL default '0',
  1385. ID_TOPIC mediumint(9) NOT NULL default '0',
  1386. PRIMARY KEY (id_search, ID_TOPIC)
  1387. ) ENGINE=MyISAM;
  1388. CREATE TABLE IF NOT EXISTS {$db_prefix}log_search_results (
  1389. id_search tinyint(3) unsigned NOT NULL default '0',
  1390. ID_TOPIC mediumint(8) unsigned NOT NULL default '0',
  1391. ID_MSG int(10) unsigned NOT NULL default '0',
  1392. relevance smallint(5) unsigned NOT NULL default '0',
  1393. num_matches smallint(5) unsigned NOT NULL default '0',
  1394. PRIMARY KEY (id_search, ID_TOPIC),
  1395. KEY relevance (relevance)
  1396. ) ENGINE=MyISAM;
  1397. CREATE TABLE IF NOT EXISTS {$db_prefix}log_search_subjects (
  1398. word varchar(20) NOT NULL default '',
  1399. ID_TOPIC mediumint(8) unsigned NOT NULL default '0',
  1400. PRIMARY KEY (word, ID_TOPIC),
  1401. KEY ID_TOPIC (ID_TOPIC)
  1402. ) ENGINE=MyISAM;
  1403. ---#
  1404. ---# Rebuilding fulltext index...
  1405. ---{
  1406. $request = upgrade_query("
  1407. SHOW KEYS
  1408. FROM {$db_prefix}messages");
  1409. $found = false;
  1410. while ($row = smf_mysql_fetch_assoc($request))
  1411. $found |= $row['Key_name'] == 'subject' && $row['Column_name'] == 'subject';
  1412. smf_mysql_free_result($request);
  1413. if ($found)
  1414. {
  1415. $request = upgrade_query("
  1416. ALTER TABLE {$db_prefix}messages
  1417. DROP INDEX subject,
  1418. DROP INDEX body,
  1419. ADD FULLTEXT body (body)");
  1420. }
  1421. ---}
  1422. ---#
  1423. ---# Indexing topic subjects...
  1424. ---{
  1425. $request = upgrade_query("
  1426. SELECT COUNT(*)
  1427. FROM {$db_prefix}log_search_subjects");
  1428. list ($numIndexedWords) = smf_mysql_fetch_row($request);
  1429. smf_mysql_free_result($request);
  1430. if ($numIndexedWords == 0 || isset($_GET['lt']))
  1431. {
  1432. $request = upgrade_query("
  1433. SELECT COUNT(*)
  1434. FROM {$db_prefix}topics");
  1435. list ($maxTopics) = smf_mysql_fetch_row($request);
  1436. smf_mysql_free_result($request);
  1437. $_GET['lt'] = isset($_GET['lt']) ? (int) $_GET['lt'] : 0;
  1438. $step_progress['name'] = 'Indexing Topic Subjects';
  1439. $step_progress['current'] = $_GET['lt'];
  1440. $step_progress['total'] = $maxTopics;
  1441. while ($_GET['lt'] <= $maxTopics)
  1442. {
  1443. $request = upgrade_query("
  1444. SELECT t.ID_TOPIC, m.subject
  1445. FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
  1446. WHERE m.ID_MSG = t.ID_FIRST_MSG
  1447. LIMIT $_GET[lt], 250");
  1448. $inserts = array();
  1449. while ($row = smf_mysql_fetch_assoc($request))
  1450. {
  1451. foreach (text2words($row['subject']) as $word)
  1452. $inserts[] = "'" . smf_mysql_real_escape_string($word) . "', $row[ID_TOPIC]";
  1453. }
  1454. smf_mysql_free_result($request);
  1455. if (!empty($inserts))
  1456. upgrade_query("
  1457. INSERT INTO {$db_prefix}log_search_subjects
  1458. (word, ID_TOPIC)
  1459. VALUES (" . implode('),
  1460. (', array_unique($inserts)) . ")");
  1461. $_GET['lt'] += 250;
  1462. $step_progress['current'] = $_GET['lt'];
  1463. nextSubstep($substep);
  1464. }
  1465. unset($_GET['lt']);
  1466. }
  1467. ---}
  1468. ---#
  1469. ---# Converting settings...
  1470. ---{
  1471. if (isset($modSettings['search_method']))
  1472. {
  1473. if (!empty($modSettings['search_method']))
  1474. $request = upgrade_query("
  1475. INSERT INTO {$db_prefix}settings
  1476. (variable, value)
  1477. VALUES
  1478. ('search_match_words', '1')");
  1479. if ($modSettings['search_method'] > 1)
  1480. $request = upgrade_query("
  1481. INSERT INTO {$db_prefix}settings
  1482. (variable, value)
  1483. VALUES
  1484. ('search_index', 'fulltext')");
  1485. if ($modSettings['search_method'] == 3)
  1486. $request = upgrade_query("
  1487. INSERT INTO {$db_prefix}settings
  1488. (variable, value)
  1489. VALUES
  1490. ('search_force_index', '1')");
  1491. $request = upgrade_query("
  1492. DELETE FROM {$db_prefix}settings
  1493. WHERE variable = 'search_method'");
  1494. }
  1495. ---}
  1496. ---#
  1497. /******************************************************************************/
  1498. --- Upgrading log system...
  1499. /******************************************************************************/
  1500. ---# Creating log table indexes (this might take some time!)...
  1501. ---{
  1502. $request = upgrade_query("
  1503. SHOW COLUMNS
  1504. FROM {$db_prefix}log_topics");
  1505. $upgradeLogTable = false;
  1506. while ($request && $row = smf_mysql_fetch_row($request))
  1507. $upgradeLogTable |= $row[0] == 'logTime';
  1508. if ($request !== false)
  1509. smf_mysql_free_result($request);
  1510. if ($upgradeLogTable)
  1511. {
  1512. $_GET['preprep_lt'] = isset($_GET['preprep_lt']) ? (int) $_GET['preprep_lt'] : 0;
  1513. $step_progress['name'] = 'Creating index\'s for log table';
  1514. $step_progress['current'] = $_GET['preprep_lt'];
  1515. $custom_warning = 'On a very large board these index\'s may take a few minutes to create.';
  1516. $log_additions = array(
  1517. array(
  1518. 'table' => 'log_boards',
  1519. 'type' => 'index',
  1520. 'method' => 'add',
  1521. 'name' => 'logTime',
  1522. 'target_columns' => array('logTime'),
  1523. 'text' => 'ADD INDEX logTime (logTime)',
  1524. ),
  1525. array(
  1526. 'table' => 'log_mark_read',
  1527. 'type' => 'index',
  1528. 'method' => 'add',
  1529. 'name' => 'logTime',
  1530. 'target_columns' => array('logTime'),
  1531. 'text' => 'ADD INDEX logTime (logTime)',
  1532. ),
  1533. array(
  1534. 'table' => 'messages',
  1535. 'type' => 'index',
  1536. 'method' => 'add',
  1537. 'name' => 'modifiedTime',
  1538. 'target_columns' => array('modifiedTime'),
  1539. 'text' => 'ADD INDEX modifiedTime (modifiedTime)',
  1540. ),
  1541. );
  1542. $step_progress['total'] = count($log_additions);
  1543. // Now we loop through the changes and work out where the hell we are.
  1544. foreach ($log_additions as $ind => $change)
  1545. {
  1546. // Already done it?
  1547. if ($_GET['preprep_lt'] > $ind)
  1548. continue;
  1549. // Make the index, with all the protection and all.
  1550. protected_alter($change, $substep);
  1551. // Store this for the next table.
  1552. $_GET['preprep_lt']++;
  1553. $step_progress['current'] = $_GET['preprep_lt'];
  1554. }
  1555. // Clean up.
  1556. unset($_GET['preprep_lt']);
  1557. }
  1558. ---}
  1559. ---#
  1560. ---# Preparing log table upgrade...
  1561. ---{
  1562. $request = upgrade_query("
  1563. SHOW COLUMNS
  1564. FROM {$db_prefix}log_topics");
  1565. $upgradeLogTable = false;
  1566. while ($request && $row = smf_mysql_fetch_row($request))
  1567. $upgradeLogTable |= $row[0] == 'logTime';
  1568. if ($request !== false)
  1569. smf_mysql_free_result($request);
  1570. if ($upgradeLogTable)
  1571. {
  1572. $_GET['prep_lt'] = isset($_GET['prep_lt']) ? (int) $_GET['prep_lt'] : 0;
  1573. $step_progress['name'] = 'Preparing log table update';
  1574. $step_progress['current'] = $_GET['prep_lt'];
  1575. $custom_warning = 'This step may take quite some time. During this time it may appear that nothing is happening while
  1576. the databases MySQL tables are expanded. Please be patient.';
  1577. // All these changes need to be made, they may take a while, so let's timeout neatly.
  1578. $log_additions = array(
  1579. array(
  1580. 'table' => 'log_topics',
  1581. 'type' => 'index',
  1582. 'method' => 'remove',
  1583. 'name' => 'ID_MEMBER',
  1584. 'target_columns' => array('ID_MEMBER'),
  1585. 'text' => 'DROP INDEX ID_MEMBER',
  1586. ),
  1587. array(
  1588. 'table' => 'log_topics',
  1589. 'type' => 'index',
  1590. 'method' => 'change',
  1591. 'name' => 'PRIMARY',
  1592. 'target_columns' => array('ID_MEMBER', 'ID_TOPIC'),
  1593. 'text' => '
  1594. DROP PRIMARY KEY,
  1595. ADD PRIMARY KEY (ID_MEMBER, ID_TOPIC)',
  1596. ),
  1597. array(
  1598. 'table' => 'log_topics',
  1599. 'type' => 'index',
  1600. 'method' => 'add',
  1601. 'name' => 'logTime',
  1602. 'target_columns' => array('logTime'),
  1603. 'text' => 'ADD INDEX logTime (logTime)',
  1604. ),
  1605. array(
  1606. 'table' => 'log_boards',
  1607. 'type' => 'column',
  1608. 'method' => 'add',
  1609. 'name' => 'ID_MSG',
  1610. 'text' => 'ADD COLUMN ID_MSG mediumint(8) unsigned NOT NULL default \'0\'',
  1611. ),
  1612. array(
  1613. 'table' => 'log_mark_read',
  1614. 'type' => 'column',
  1615. 'method' => 'add',
  1616. 'name' => 'ID_MSG',
  1617. 'text' => 'ADD COLUMN ID_MSG mediumint(8) unsigned NOT NULL default \'0\'',
  1618. ),
  1619. array(
  1620. 'table' => 'log_topics',
  1621. 'type' => 'column',
  1622. 'method' => 'add',
  1623. 'name' => 'ID_MSG',
  1624. 'text' => 'ADD COLUMN ID_MSG mediumint(8) unsigned NOT NULL default \'0\'',
  1625. ),
  1626. array(
  1627. 'table' => 'messages',
  1628. 'type' => 'column',
  1629. 'method' => 'add',
  1630. 'name' => 'ID_MSG_MODIFIED',
  1631. 'text' => 'ADD COLUMN ID_MSG_MODIFIED mediumint(8) unsigned NOT NULL default \'0\' AFTER ID_MEMBER',
  1632. ),
  1633. array(
  1634. 'table' => 'boards',
  1635. 'type' => 'column',
  1636. 'method' => 'add',
  1637. 'name' => 'ID_MSG_UPDATED',
  1638. 'text' => 'ADD COLUMN ID_MSG_UPDATED mediumint(8) unsigned NOT NULL default \'0\' AFTER ID_LAST_MSG',
  1639. ),
  1640. array(
  1641. 'table' => 'boards',
  1642. 'type' => 'index',
  1643. 'method' => 'add',
  1644. 'name' => 'ID_MSG_UPDATED',
  1645. 'target_columns' => array('ID_MSG_UPDATED'),
  1646. 'text' => 'ADD INDEX ID_MSG_UPDATED (ID_MSG_UPDATED)',
  1647. ),
  1648. );
  1649. $step_progress['total'] = count($log_additions);
  1650. // Now we loop through the changes and work out where the hell we are.
  1651. foreach ($log_additions as $ind => $change)
  1652. {
  1653. // Already done it?
  1654. if ($_GET['prep_lt'] > $ind)
  1655. continue;
  1656. // Make the index, with all the protection and all.
  1657. protected_alter($change, $substep);
  1658. // Store this for the next table.
  1659. $_GET['prep_lt']++;
  1660. $step_progress['current'] = $_GET['prep_lt'];
  1661. }
  1662. // Clean up.
  1663. unset($_GET['prep_lt']);
  1664. }
  1665. ---}
  1666. ---#
  1667. ---# Converting log tables (this might take some time!)...
  1668. ---{
  1669. $request = upgrade_query("
  1670. SHOW COLUMNS
  1671. FROM {$db_prefix}log_topics");
  1672. $upgradeLogTable = false;
  1673. while ($request && $row = smf_mysql_fetch_row($request))
  1674. $upgradeLogTable |= $row[0] == 'logTime';
  1675. if ($request !== false)
  1676. smf_mysql_free_result($request);
  1677. if ($upgradeLogTable)
  1678. {
  1679. $request = upgrade_query("
  1680. SELECT MAX(ID_MSG)
  1681. FROM {$db_prefix}messages");
  1682. list($maxMsg) = smf_mysql_fetch_row($request);
  1683. smf_mysql_free_result($request);
  1684. if (empty($maxMsg))
  1685. $maxMsg = 0;
  1686. $_GET['m'] = isset($_GET['m']) ? (int) $_GET['m'] : 0;
  1687. $step_progress['name'] = 'Converting Log Tables';
  1688. $step_progress['current'] = $_GET['m'];
  1689. $step_progress['total'] = $maxMsg;
  1690. $custom_warning = 'This step is converting all your log tables and may take quite some time on a large forum (Several hours for a forum with ~500,000 messages).';
  1691. // Only adjust the structure if this is the first message.
  1692. if ($_GET['m'] === 0)
  1693. {
  1694. // By default a message is modified when it was written.
  1695. upgrade_query("
  1696. UPDATE {$db_prefix}messages
  1697. SET ID_MSG_MODIFIED = ID_MSG");
  1698. $request = upgrade_query("
  1699. SELECT posterTime
  1700. FROM {$db_prefix}messages
  1701. WHERE ID_MSG = $maxMsg");
  1702. list($maxPosterTime) = smf_mysql_fetch_row($request);
  1703. smf_mysql_free_result($request);
  1704. if (empty($maxPosterTime))
  1705. $maxPosterTime = 0;
  1706. upgrade_query("
  1707. UPDATE {$db_prefix}log_boards
  1708. SET ID_MSG = $maxMsg
  1709. WHERE logTime >= $maxPosterTime");
  1710. upgrade_query("
  1711. UPDATE {$db_prefix}log_mark_read
  1712. SET ID_MSG = $maxMsg
  1713. WHERE logTime >= $maxPosterTime");
  1714. upgrade_query("
  1715. UPDATE {$db_prefix}log_topics
  1716. SET ID_MSG = $maxMsg
  1717. WHERE logTime >= $maxPosterTime");
  1718. upgrade_query("
  1719. UPDATE {$db_prefix}messages
  1720. SET ID_MSG_MODIFIED = $maxMsg
  1721. WHERE modifiedTime >= $maxPosterTime");
  1722. // Timestamp 1 is where it all starts.
  1723. $lower_limit = 1;
  1724. }
  1725. else
  1726. {
  1727. // Determine the lower limit.
  1728. $request = upgrade_query("
  1729. SELECT MAX(posterTime) + 1
  1730. FROM {$db_prefix}messages
  1731. WHERE ID_MSG < $_GET[m]");
  1732. list($lower_limit) = smf_mysql_fetch_row($request);
  1733. smf_mysql_free_result($request);
  1734. if (empty($lower_limit))
  1735. $lower_limit = 1;
  1736. if (empty($maxPosterTime))
  1737. $maxPosterTime = 1;
  1738. }
  1739. while ($_GET['m'] <= $maxMsg)
  1740. {
  1741. $condition = '';
  1742. $lowest_limit = $lower_limit;
  1743. $request = upgrade_query("
  1744. SELECT MAX(ID_MSG) AS ID_MSG, posterTime
  1745. FROM {$db_prefix}messages
  1746. WHERE ID_MSG BETWEEN $_GET[m] AND " . ($_GET['m'] + 300) . "
  1747. GROUP BY posterTime
  1748. ORDER BY posterTime
  1749. LIMIT 300");
  1750. while ($row = smf_mysql_fetch_assoc($request))
  1751. {
  1752. if ($condition === '')
  1753. $condition = "IF(logTime BETWEEN $lower_limit AND $row[posterTime], $row[ID_MSG], %else%)";
  1754. else
  1755. $condition = strtr($condition, array('%else%' => "IF(logTime <= $row[posterTime], $row[ID_MSG], %else%)"));
  1756. $lower_limit = $row['posterTime'] + 1;
  1757. }
  1758. smf_mysql_free_result($request);
  1759. if ($condition !== '')
  1760. {
  1761. $condition = strtr($condition, array('%else%' => '0'));
  1762. $highest_limit = $lower_limit;
  1763. upgrade_query("
  1764. UPDATE {$db_prefix}log_boards
  1765. SET ID_MSG = $condition
  1766. WHERE logTime BETWEEN $lowest_limit AND $highest_limit
  1767. AND ID_MSG = 0");
  1768. upgrade_query("
  1769. UPDATE {$db_prefix}log_mark_read
  1770. SET ID_MSG = $condition
  1771. WHERE logTime BETWEEN $lowest_limit AND $highest_limit
  1772. AND ID_MSG = 0");
  1773. upgrade_query("
  1774. UPDATE {$db_prefix}log_topics
  1775. SET ID_MSG = $condition
  1776. WHERE logTime BETWEEN $lowest_limit AND $highest_limit
  1777. AND ID_MSG = 0");
  1778. upgrade_query("
  1779. UPDATE {$db_prefix}messages
  1780. SET ID_MSG_MODIFIED = " . strtr($condition, array('logTime' => 'modifiedTime')) . "
  1781. WHERE modifiedTime BETWEEN $lowest_limit AND $highest_limit
  1782. AND modifiedTime > 0");
  1783. }
  1784. $_GET['m'] += 300;
  1785. nextSubstep($substep);
  1786. }
  1787. unset($_GET['m']);
  1788. }
  1789. ---}
  1790. ---#
  1791. ---# Updating last message IDs for boards.
  1792. ---{
  1793. $request = upgrade_query("
  1794. SHOW COLUMNS
  1795. FROM {$db_prefix}boards");
  1796. $upgradeBoardsTable = false;
  1797. while ($request && $row = smf_mysql_fetch_row($request))
  1798. $upgradeBoardsTable |= $row[0] == 'lastUpdated';
  1799. if ($request !== false)
  1800. smf_mysql_free_result($request);
  1801. if ($upgradeBoardsTable)
  1802. {
  1803. $request = upgrade_query("
  1804. SELECT MAX(ID_BOARD)
  1805. FROM {$db_prefix}boards");
  1806. list ($maxBoard) = smf_mysql_fetch_row($request);
  1807. smf_mysql_free_result($request);
  1808. $_GET['bdi'] = isset($_GET['bdi']) ? (int) $_GET['bdi'] : 0;
  1809. $step_progress['name'] = 'Updating Last Board ID';
  1810. $step_progress['current'] = $_GET['bdi'];
  1811. $step_progress['total'] = $maxBoard;
  1812. // OK, we need to get the last updated message.
  1813. $request = upgrade_query("
  1814. SELECT ID_BOARD, lastUpdated
  1815. FROM {$db_prefix}boards");
  1816. while ($row = smf_mysql_fetch_assoc($request))
  1817. {
  1818. // Done this?
  1819. if ($row['ID_BOARD'] < $_GET['bdi'])
  1820. continue;
  1821. // Maybe we don't have any?
  1822. if ($row['lastUpdated'] == 0)
  1823. $ID_MSG = 0;
  1824. // Otherwise need to query it?
  1825. else
  1826. {
  1827. $request2 = upgrade_query("
  1828. SELECT MIN(ID_MSG)
  1829. FROM {$db_prefix}messages
  1830. WHERE posterTime >= $row[lastUpdated]");
  1831. list ($ID_MSG) = smf_mysql_fetch_row($request2);
  1832. if (empty($ID_MSG))
  1833. $ID_MSG = 0;
  1834. }
  1835. upgrade_query("
  1836. UPDATE {$db_prefix}boards
  1837. SET ID_MSG_UPDATED = $ID_MSG
  1838. WHERE ID_BOARD = $row[ID_BOARD]");
  1839. $_GET['bdi']++;
  1840. $step_progress['current'] = $_GET['bdi'];
  1841. nextSubstep($substep);
  1842. }
  1843. unset($_GET['bdi']);
  1844. }
  1845. ---}
  1846. ---#
  1847. ---# Cleaning up old log indexes...
  1848. ---{
  1849. $request = upgrade_query("
  1850. SHOW COLUMNS
  1851. FROM {$db_prefix}log_topics");
  1852. $upgradeLogTable = false;
  1853. while ($request && $row = smf_mysql_fetch_row($request))
  1854. $upgradeLogTable |= $row[0] == 'logTime';
  1855. if ($request !== false)
  1856. smf_mysql_free_result($request);
  1857. if ($upgradeLogTable)
  1858. {
  1859. $_GET['prep_lt'] = isset($_GET['prep_lt']) ? (int) $_GET['prep_lt'] : 0;
  1860. $step_progress['name'] = 'Cleaning up old log table index\'s';
  1861. $step_progress['current'] = $_GET['prep_lt'];
  1862. $custom_warning = 'This step may take quite some time. During this time it may appear that nothing is happening while
  1863. the databases MySQL tables are cleaned. Please be patient.';
  1864. // Here we remove all the unused indexes
  1865. $log_deletions = array(
  1866. array(
  1867. 'table' => 'boards',
  1868. 'type' => 'index',
  1869. 'method' => 'remove',
  1870. 'name' => 'lastUpdated',
  1871. 'target_columns' => array('lastUpdated'),
  1872. 'text' => 'DROP INDEX lastUpdated',
  1873. ),
  1874. array(
  1875. 'table' => 'messages',
  1876. 'type' => 'index',
  1877. 'method' => 'remove',
  1878. 'name' => 'posterTime',
  1879. 'target_columns' => array('posterTime'),
  1880. 'text' => 'DROP INDEX posterTime',
  1881. ),
  1882. array(
  1883. 'table' => 'messages',
  1884. 'type' => 'index',
  1885. 'method' => 'remove',
  1886. 'name' => 'modifiedTime',
  1887. 'target_columns' => array('modifiedTime'),
  1888. 'text' => 'DROP INDEX modifiedTime',
  1889. ),
  1890. array(
  1891. 'table' => 'log_topics',
  1892. 'type' => 'column',
  1893. 'method' => 'remove',
  1894. 'name' => 'logTime',
  1895. 'text' => 'DROP COLUMN logTime',
  1896. ),
  1897. array(
  1898. 'table' => 'log_boards',
  1899. 'type' => 'column',
  1900. 'method' => 'remove',
  1901. 'name' => 'logTime',
  1902. 'text' => 'DROP COLUMN logTime',
  1903. ),
  1904. array(
  1905. 'table' => 'log_mark_read',
  1906. 'type' => 'column',
  1907. 'method' => 'remove',
  1908. 'name' => 'logTime',
  1909. 'text' => 'DROP COLUMN logTime',
  1910. ),
  1911. array(
  1912. 'table' => 'boards',
  1913. 'type' => 'column',
  1914. 'method' => 'remove',
  1915. 'name' => 'lastUpdated',
  1916. 'text' => 'DROP COLUMN lastUpdated',
  1917. ),
  1918. );
  1919. $step_progress['total'] = count($log_deletions);
  1920. // Now we loop through the changes and work out where the hell we are.
  1921. foreach ($log_deletions as $ind => $change)
  1922. {
  1923. // Already done it?
  1924. if ($_GET['prep_lt'] > $ind)
  1925. continue;
  1926. // Make the index, with all the protection and all.
  1927. protected_alter($change, $substep);
  1928. // Store this for the next table.
  1929. $_GET['prep_lt']++;
  1930. $step_progress['current'] = $_GET['prep_lt'];
  1931. }
  1932. // Clean up.
  1933. unset($_GET['prep_lt']);
  1934. $step_progress = array();
  1935. }
  1936. ---}
  1937. ---#
  1938. /******************************************************************************/
  1939. --- Making SMF MySQL strict compatible...
  1940. /******************************************************************************/
  1941. ---# Preparing messages table for strict upgrade
  1942. ALTER IGNORE TABLE {$db_prefix}messages
  1943. DROP INDEX ipIndex;
  1944. ---#
  1945. ---# Adjusting text fields
  1946. ---#
  1947. ---{
  1948. // Note we move on by one as there is no point ALTER'ing the same thing twice.
  1949. $_GET['strict_step'] = isset($_GET['strict_step']) ? (int) $_GET['strict_step'] + 1 : 0;
  1950. $step_progress['name'] = 'Adding MySQL strict compatibility';
  1951. $step_progress['current'] = $_GET['strict_step'];
  1952. // Take care with the body column from messages, just in case it's been enlarged by others.
  1953. $request = upgrade_query("
  1954. SHOW COLUMNS
  1955. FROM {$db_prefix}messages
  1956. LIKE 'body'");
  1957. $body_row = smf_mysql_fetch_assoc($request);
  1958. smf_mysql_free_result($request);
  1959. $body_type = $body_row['Type'];
  1960. $textfield_updates = array(
  1961. array(
  1962. 'table' => 'attachments',
  1963. 'column' => 'filename',
  1964. 'type' => 'tinytext',
  1965. 'null_allowed' => false,
  1966. ),
  1967. array(
  1968. 'table' => 'ban_groups',
  1969. 'column' => 'reason',
  1970. 'type' => 'tinytext',
  1971. 'null_allowed' => false,
  1972. ),
  1973. array(
  1974. 'table' => 'ban_items',
  1975. 'column' => 'hostname',
  1976. 'type' => 'tinytext',
  1977. 'null_allowed' => false,
  1978. ),
  1979. array(
  1980. 'table' => 'ban_items',
  1981. 'column' => 'email_address',
  1982. 'type' => 'tinytext',
  1983. 'null_allowed' => false,
  1984. ),
  1985. array(
  1986. 'table' => 'boards',
  1987. 'column' => 'name',
  1988. 'type' => 'tinytext',
  1989. 'null_allowed' => false,
  1990. ),
  1991. array(
  1992. 'table' => 'boards',
  1993. 'column' => 'description',
  1994. 'type' => 'text',
  1995. 'null_allowed' => false,
  1996. ),
  1997. array(
  1998. 'table' => 'categories',
  1999. 'column' => 'name',
  2000. 'type' => 'tinytext',
  2001. 'null_allowed' => false,
  2002. ),
  2003. array(
  2004. 'table' => 'log_actions',
  2005. 'column' => 'extra',
  2006. 'type' => 'text',
  2007. 'null_allowed' => false,
  2008. ),
  2009. array(
  2010. 'table' => 'log_banned',
  2011. 'column' => 'email',
  2012. 'type' => 'tinytext',
  2013. 'null_allowed' => false,
  2014. ),
  2015. array(
  2016. 'table' => 'log_banned',
  2017. 'column' => 'email',
  2018. 'type' => 'tinytext',
  2019. 'null_allowed' => false,
  2020. ),
  2021. array(
  2022. 'table' => 'log_errors',
  2023. 'column' => 'url',
  2024. 'type' => 'text',
  2025. 'null_allowed' => false,
  2026. ),
  2027. array(
  2028. 'table' => 'log_errors',
  2029. 'column' => 'message',
  2030. 'type' => 'text',
  2031. 'null_allowed' => false,
  2032. ),
  2033. array(
  2034. 'table' => 'log_online',
  2035. 'column' => 'url',
  2036. 'type' => 'text',
  2037. 'null_allowed' => false,
  2038. ),
  2039. array(
  2040. 'table' => 'membergroups',
  2041. 'column' => 'stars',
  2042. 'type' => 'tinytext',
  2043. 'null_allowed' => false,
  2044. ),
  2045. array(
  2046. 'table' => 'members',
  2047. 'column' => 'lngfile',
  2048. 'type' => 'tinytext',
  2049. 'null_allowed' => false,
  2050. ),
  2051. array(
  2052. 'table' => 'members',
  2053. 'column' => 'realName',
  2054. 'type' => 'tinytext',
  2055. 'null_allowed' => false,
  2056. ),
  2057. array(
  2058. 'table' => 'members',
  2059. 'column' => 'buddy_list',
  2060. 'type' => 'tinytext',
  2061. 'null_allowed' => false,
  2062. ),
  2063. array(
  2064. 'table' => 'members',
  2065. 'column' => 'pm_ignore_list',
  2066. 'type' => 'text',
  2067. 'null_allowed' => false,
  2068. ),
  2069. array(
  2070. 'table' => 'members',
  2071. 'column' => 'messageLabels',
  2072. 'type' => 'text',
  2073. 'null_allowed' => false,
  2074. ),
  2075. array(
  2076. 'table' => 'members',
  2077. 'column' => 'emailAddress',
  2078. 'type' => 'tinytext',
  2079. 'null_allowed' => false,
  2080. ),
  2081. array(
  2082. 'table' => 'members',
  2083. 'column' => 'personalText',
  2084. 'type' => 'tinytext',
  2085. 'null_allowed' => false,
  2086. ),
  2087. array(
  2088. 'table' => 'members',
  2089. 'column' => 'websiteTitle',
  2090. 'type' => 'tinytext',
  2091. 'null_allowed' => false,
  2092. ),
  2093. array(
  2094. 'table' => 'members',
  2095. 'column' => 'websiteUrl',
  2096. 'type' => 'tinytext',
  2097. 'null_allowed' => false,
  2098. ),
  2099. array(
  2100. 'table' => 'members',
  2101. 'column' => 'location',
  2102. 'type' => 'tinytext',
  2103. 'null_allowed' => false,
  2104. ),
  2105. array(
  2106. 'table' => 'members',
  2107. 'column' => 'ICQ',
  2108. 'type' => 'tinytext',
  2109. 'null_allowed' => false,
  2110. ),
  2111. array(
  2112. 'table' => 'members',
  2113. 'column' => 'MSN',
  2114. 'type' => 'tinytext',
  2115. 'null_allowed' => false,
  2116. ),
  2117. array(
  2118. 'table' => 'members',
  2119. 'column' => 'signature',
  2120. 'type' => 'text',
  2121. 'null_allowed' => false,
  2122. ),
  2123. array(
  2124. 'table' => 'members',
  2125. 'column' => 'avatar',
  2126. 'type' => 'tinytext',
  2127. 'null_allowed' => false,
  2128. ),
  2129. array(
  2130. 'table' => 'members',
  2131. 'column' => 'usertitle',
  2132. 'type' => 'tinytext',
  2133. 'null_allowed' => false,
  2134. ),
  2135. array(
  2136. 'table' => 'members',
  2137. 'column' => 'memberIP',
  2138. 'type' => 'tinytext',
  2139. 'null_allowed' => false,
  2140. ),
  2141. array(
  2142. 'table' => 'members',
  2143. 'column' => 'secretQuestion',
  2144. 'type' => 'tinytext',
  2145. 'null_allowed' => false,
  2146. ),
  2147. array(
  2148. 'table' => 'members',
  2149. 'column' => 'additionalGroups',
  2150. 'type' => 'tinytext',
  2151. 'null_allowed' => false,
  2152. ),
  2153. array(
  2154. 'table' => 'messages',
  2155. 'column' => 'subject',
  2156. 'type' => 'tinytext',
  2157. 'null_allowed' => false,
  2158. ),
  2159. array(
  2160. 'table' => 'messages',
  2161. 'column' => 'posterName',
  2162. 'type' => 'tinytext',
  2163. 'null_allowed' => false,
  2164. ),
  2165. array(
  2166. 'table' => 'messages',
  2167. 'column' => 'posterEmail',
  2168. 'type' => 'tinytext',
  2169. 'null_allowed' => false,
  2170. ),
  2171. array(
  2172. 'table' => 'messages',
  2173. 'column' => 'posterIP',
  2174. 'type' => 'tinytext',
  2175. 'null_allowed' => false,
  2176. ),
  2177. array(
  2178. 'table' => 'messages',
  2179. 'column' => 'modifiedName',
  2180. 'type' => 'tinytext',
  2181. 'null_allowed' => false,
  2182. ),
  2183. array(
  2184. 'table' => 'messages',
  2185. 'column' => 'body',
  2186. 'type' => $body_type,
  2187. 'null_allowed' => false,
  2188. ),
  2189. array(
  2190. 'table' => 'personal_messages',
  2191. 'column' => 'body',
  2192. 'type' => 'text',
  2193. 'null_allowed' => false,
  2194. ),
  2195. array(
  2196. 'table' => 'package_servers',
  2197. 'column' => 'name',
  2198. 'type' => 'tinytext',
  2199. 'null_allowed' => false,
  2200. ),
  2201. array(
  2202. 'table' => 'personal_messages',
  2203. 'column' => 'fromName',
  2204. 'type' => 'tinytext',
  2205. 'null_allowed' => false,
  2206. ),
  2207. array(
  2208. 'table' => 'personal_messages',
  2209. 'column' => 'subject',
  2210. 'type' => 'tinytext',
  2211. 'null_allowed' => false,
  2212. ),
  2213. array(
  2214. 'table' => 'personal_messages',
  2215. 'column' => 'body',
  2216. 'type' => 'text',
  2217. 'null_allowed' => false,
  2218. ),
  2219. array(
  2220. 'table' => 'polls',
  2221. 'column' => 'question',
  2222. 'type' => 'tinytext',
  2223. 'null_allowed' => false,
  2224. ),
  2225. array(
  2226. 'table' => 'polls',
  2227. 'column' => 'posterName',
  2228. 'type' => 'tinytext',
  2229. 'null_allowed' => false,
  2230. ),
  2231. array(
  2232. 'table' => 'poll_choices',
  2233. 'column' => 'label',
  2234. 'type' => 'tinytext',
  2235. 'null_allowed' => false,
  2236. ),
  2237. array(
  2238. 'table' => 'settings',
  2239. 'column' => 'variable',
  2240. 'type' => 'tinytext',
  2241. 'null_allowed' => false,
  2242. ),
  2243. array(
  2244. 'table' => 'settings',
  2245. 'column' => 'value',
  2246. 'type' => 'text',
  2247. 'null_allowed' => false,
  2248. ),
  2249. array(
  2250. 'table' => 'sessions',
  2251. 'column' => 'data',
  2252. 'type' => 'text',
  2253. 'null_allowed' => false,
  2254. ),
  2255. array(
  2256. 'table' => 'themes',
  2257. 'column' => 'variable',
  2258. 'type' => 'tinytext',
  2259. 'null_allowed' => false,
  2260. ),
  2261. array(
  2262. 'table' => 'themes',
  2263. 'column' => 'value',
  2264. 'type' => 'text',
  2265. 'null_allowed' => false,
  2266. ),
  2267. );
  2268. $step_progress['total'] = count($textfield_updates);
  2269. foreach ($textfield_updates as $ind => $change)
  2270. {
  2271. // Already done it?
  2272. if ($_GET['strict_step'] > $ind)
  2273. continue;
  2274. // Make the index, with all the protection and all.
  2275. textfield_alter($change, $substep);
  2276. // Store this for the next table.
  2277. $_GET['strict_step']++;
  2278. $step_progress['current'] = $_GET['strict_step'];
  2279. }
  2280. $step_progress = array();
  2281. ---}
  2282. ---#
  2283. ---# Replacing messages index.
  2284. ALTER TABLE {$db_prefix}messages
  2285. ADD INDEX ipIndex (posterIP(15), ID_TOPIC);
  2286. ---#
  2287. ---# Adding log_topics index.
  2288. ---{
  2289. upgrade_query("
  2290. ALTER TABLE {$db_prefix}log_topics
  2291. ADD INDEX ID_TOPIC (ID_TOPIC)", true);
  2292. ---}
  2293. ---#
  2294. /******************************************************************************/
  2295. --- Adding more room for the buddy list
  2296. /******************************************************************************/
  2297. ---# Updating the members table ...
  2298. ALTER TABLE {$db_prefix}members
  2299. CHANGE COLUMN buddy_list buddy_list text NOT NULL;
  2300. ---#
  2301. /******************************************************************************/
  2302. --- Change some column types to accomodate more messages.
  2303. /******************************************************************************/
  2304. ---# Expanding message column size.
  2305. ---{
  2306. $_GET['msg_change'] = isset($_GET['msg_change']) ? (int) $_GET['msg_change'] : 0;
  2307. $step_progress['name'] = 'Expanding Message Capacity';
  2308. $step_progress['current'] = $_GET['msg_change'];
  2309. // The array holding all the changes.
  2310. $columnChanges = array(
  2311. array(
  2312. 'table' => 'boards',
  2313. 'type' => 'column',
  2314. 'method' => 'change',
  2315. 'name' => 'ID_LAST_MSG',
  2316. 'text' => 'CHANGE ID_LAST_MSG ID_LAST_MSG int(10) unsigned NOT NULL default \'0\'',
  2317. ),
  2318. array(
  2319. 'table' => 'boards',
  2320. 'type' => 'column',
  2321. 'method' => 'change',
  2322. 'name' => 'ID_MSG_UPDATED',
  2323. 'text' => 'CHANGE ID_MSG_UPDATED ID_MSG_UPDATED int(10) unsigned NOT NULL default \'0\'',
  2324. ),
  2325. array(
  2326. 'table' => 'log_boards',
  2327. 'type' => 'column',
  2328. 'method' => 'change',
  2329. 'name' => 'ID_MSG',
  2330. 'text' => 'CHANGE ID_MSG ID_MSG int(10) unsigned NOT NULL default \'0\'',
  2331. ),
  2332. array(
  2333. 'table' => 'log_mark_read',
  2334. 'type' => 'column',
  2335. 'method' => 'change',
  2336. 'name' => 'ID_MSG',
  2337. 'text' => 'CHANGE ID_MSG ID_MSG int(10) unsigned NOT NULL default \'0\'',
  2338. ),
  2339. array(
  2340. 'table' => 'log_topics',
  2341. 'type' => 'column',
  2342. 'method' => 'change',
  2343. 'name' => 'ID_MSG',
  2344. 'text' => 'CHANGE ID_MSG ID_MSG int(10) unsigned NOT NULL default \'0\'',
  2345. ),
  2346. array(
  2347. 'table' => 'messages',
  2348. 'type' => 'column',
  2349. 'method' => 'change',
  2350. 'name' => 'ID_MSG_MODIFIED',
  2351. 'text' => 'CHANGE ID_MSG_MODIFIED ID_MSG_MODIFIED int(10) unsigned NOT NULL default \'0\'',
  2352. ),
  2353. );
  2354. if (!empty($modSettings['search_custom_index_config']))
  2355. $columnChanges[] = array(
  2356. 'table' => 'log_search_words',
  2357. 'type' => 'column',
  2358. 'method' => 'change',
  2359. 'name' => 'ID_MSG',
  2360. 'text' => 'CHANGE ID_MSG ID_MSG int(10) unsigned NOT NULL default \'0\'',
  2361. );
  2362. $step_progress['total'] = count($columnChanges);
  2363. // Now we do all the changes...
  2364. foreach ($columnChanges as $index => $change)
  2365. {
  2366. // Already done it?
  2367. if ($_GET['msg_change'] > $ind)
  2368. continue;
  2369. // Now change the column at last.
  2370. protected_alter($change, $substep);
  2371. // Update where we are...
  2372. $_GET['msg_change']++;
  2373. $step_progress['current'] = $_GET['msg_change'];
  2374. }
  2375. // Clean up.
  2376. unset($_GET['msg_change']);
  2377. ---}
  2378. ---#
  2379. /******************************************************************************/
  2380. --- Final clean up...
  2381. /******************************************************************************/
  2382. ---# Sorting the boards...
  2383. ALTER TABLE {$db_prefix}categories
  2384. ORDER BY catOrder;
  2385. ALTER TABLE {$db_prefix}boards
  2386. ORDER BY boardOrder;
  2387. ---#
  2388. ---# Removing upgrade loop protection...
  2389. DELETE FROM {$db_prefix}settings
  2390. WHERE variable IN ('dont_repeat_smtp', 'dont_repeat_theme');
  2391. ---#