upgrade_1-1.sql 71 KB

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