upgrade_2-0_mysql.sql 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134
  1. /* ATTENTION: You don't need to run or use this file! The upgrade.php script does everything for you! */
  2. /******************************************************************************/
  3. --- Changing column names.
  4. /******************************************************************************/
  5. ---# Renaming table columns.
  6. ---{
  7. // The array holding all the changes.
  8. $nameChanges = array(
  9. 'admin_info_files' => array(
  10. 'ID_FILE' => 'ID_FILE id_file tinyint(4) unsigned NOT NULL auto_increment',
  11. ),
  12. 'approval_queue' => array(
  13. 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'',
  14. 'ID_ATTACH' => 'ID_ATTACH id_attach int(10) unsigned NOT NULL default \'0\'',
  15. 'ID_EVENT' => 'ID_EVENT id_event smallint(5) unsigned NOT NULL default \'0\'',
  16. 'attachmentType' => 'attachmentType attachment_type tinyint(3) unsigned NOT NULL default \'0\'',
  17. ),
  18. 'attachments' => array(
  19. 'ID_ATTACH' => 'ID_ATTACH id_attach int(10) unsigned NOT NULL auto_increment',
  20. 'ID_THUMB' => 'ID_THUMB id_thumb int(10) unsigned NOT NULL default \'0\'',
  21. 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'',
  22. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  23. 'attachmentType' => 'attachmentType attachment_type tinyint(3) unsigned NOT NULL default \'0\'',
  24. ),
  25. 'ban_groups' => array(
  26. 'ID_BAN_GROUP' => 'ID_BAN_GROUP id_ban_group mediumint(8) unsigned NOT NULL auto_increment',
  27. ),
  28. 'ban_items' => array(
  29. 'ID_BAN' => 'ID_BAN id_ban mediumint(8) unsigned NOT NULL auto_increment',
  30. 'ID_BAN_GROUP' => 'ID_BAN_GROUP id_ban_group smallint(5) unsigned NOT NULL default \'0\'',
  31. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  32. ),
  33. 'board_permissions' => array(
  34. 'ID_GROUP' => 'ID_GROUP id_group smallint(5) NOT NULL default \'0\'',
  35. 'ID_PROFILE' => 'ID_PROFILE id_profile smallint(5) NOT NULL default \'0\'',
  36. 'addDeny' => 'addDeny add_deny tinyint(4) NOT NULL default \'1\'',
  37. ),
  38. 'boards' => array(
  39. 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL auto_increment',
  40. 'ID_CAT' => 'ID_CAT id_cat tinyint(4) unsigned NOT NULL default \'0\'',
  41. 'childLevel' => 'childLevel child_level tinyint(4) unsigned NOT NULL default \'0\'',
  42. 'ID_PARENT' => 'ID_PARENT id_parent smallint(5) unsigned NOT NULL default \'0\'',
  43. 'boardOrder' => 'boardOrder board_order smallint(5) NOT NULL default \'0\'',
  44. 'ID_LAST_MSG' => 'ID_LAST_MSG id_last_msg int(10) unsigned NOT NULL default \'0\'',
  45. 'ID_MSG_UPDATED' => 'ID_MSG_UPDATED id_msg_updated int(10) unsigned NOT NULL default \'0\'',
  46. 'memberGroups' => 'memberGroups member_groups varchar(255) NOT NULL default \'-1,0\'',
  47. 'ID_PROFILE' => 'ID_PROFILE id_profile smallint(5) unsigned NOT NULL default \'1\'',
  48. 'numTopics' => 'numTopics num_topics mediumint(8) unsigned NOT NULL default \'0\'',
  49. 'numPosts' => 'numPosts num_posts mediumint(8) unsigned NOT NULL default \'0\'',
  50. 'countPosts' => 'countPosts count_posts tinyint(4) NOT NULL default \'0\'',
  51. 'ID_THEME' => 'ID_THEME id_theme tinyint(4) unsigned NOT NULL default \'0\'',
  52. 'unapprovedPosts' => 'unapprovedPosts unapproved_posts smallint(5) NOT NULL default \'0\'',
  53. 'unapprovedTopics' => 'unapprovedTopics unapproved_topics smallint(5) NOT NULL default \'0\'',
  54. ),
  55. 'calendar' => array(
  56. 'ID_EVENT' => 'ID_EVENT id_event smallint(5) unsigned NOT NULL auto_increment',
  57. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  58. 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'',
  59. 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'',
  60. 'startDate' => 'startDate start_date date NOT NULL default \'0001-01-01\'',
  61. 'endDate' => 'endDate end_date date NOT NULL default \'0001-01-01\'',
  62. ),
  63. 'calendar_holidays' => array(
  64. 'ID_HOLIDAY' => 'ID_HOLIDAY id_holiday smallint(5) unsigned NOT NULL auto_increment',
  65. 'eventDate' => 'eventDate event_date date NOT NULL default \'0001-01-01\'',
  66. ),
  67. 'categories' => array(
  68. 'ID_CAT' => 'ID_CAT id_cat tinyint(4) unsigned NOT NULL auto_increment',
  69. 'catOrder' => 'catOrder cat_order tinyint(4) NOT NULL default \'0\'',
  70. 'canCollapse' => 'canCollapse can_collapse tinyint(1) NOT NULL default \'1\'',
  71. ),
  72. 'collapsed_categories' => array(
  73. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  74. 'ID_CAT' => 'ID_CAT id_cat tinyint(4) unsigned NOT NULL',
  75. ),
  76. 'custom_fields' => array(
  77. 'ID_FIELD' => 'ID_FIELD id_field smallint(5) NOT NULL auto_increment',
  78. 'colName' => 'colName col_name varchar(12) NOT NULL default \'\'',
  79. 'fieldName' => 'fieldName field_name varchar(40) NOT NULL default \'\'',
  80. 'fieldDesc' => 'fieldDesc field_desc varchar(255) NOT NULL default \'\'',
  81. 'fieldType' => 'fieldType field_type varchar(8) NOT NULL default \'text\'',
  82. 'fieldLength' => 'fieldLength field_length smallint(5) NOT NULL default \'255\'',
  83. 'fieldOptions' => 'fieldOptions field_options text NOT NULL',
  84. 'showReg' => 'showReg show_reg tinyint(3) NOT NULL default \'0\'',
  85. 'showDisplay' => 'showDisplay show_display tinyint(3) NOT NULL default \'0\'',
  86. 'showProfile' => 'showProfile show_profile varchar(20) NOT NULL default \'forumprofile\'',
  87. 'defaultValue' => 'defaultValue default_value varchar(8) NOT NULL default \'0\'',
  88. ),
  89. 'group_moderators' => array(
  90. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  91. 'ID_GROUP' => 'ID_GROUP id_group smallint(5) unsigned NOT NULL default \'0\'',
  92. ),
  93. 'log_actions' => array(
  94. 'ID_ACTION' => 'ID_ACTION id_action int(10) unsigned NOT NULL auto_increment',
  95. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  96. 'logTime' => 'logTime log_time int(10) unsigned NOT NULL default \'0\'',
  97. 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'',
  98. 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'',
  99. 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'',
  100. ),
  101. 'log_activity' => array(
  102. 'mostOn' => 'mostOn most_on smallint(5) unsigned NOT NULL default \'0\'',
  103. ),
  104. 'log_banned' => array(
  105. 'ID_BAN_LOG' => 'ID_BAN_LOG id_ban_log mediumint(8) unsigned NOT NULL auto_increment',
  106. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  107. 'logTime' => 'logTime log_time int(10) unsigned NOT NULL default \'0\'',
  108. ),
  109. 'log_boards' => array(
  110. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  111. 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'',
  112. 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'',
  113. ),
  114. 'log_digest' => array(
  115. 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'',
  116. 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'',
  117. ),
  118. 'log_errors' => array(
  119. 'ID_ERROR' => 'ID_ERROR id_error mediumint(8) unsigned NOT NULL auto_increment',
  120. 'logTime' => 'logTime log_time int(10) unsigned NOT NULL default \'0\'',
  121. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  122. 'errorType' => 'errorType error_type char(15) NOT NULL default \'general\'',
  123. ),
  124. 'log_floodcontrol' => array(
  125. 'logTime' => 'logTime log_time int(10) unsigned NOT NULL default \'0\'',
  126. ),
  127. 'log_group_requests' => array(
  128. 'ID_REQUEST' => 'ID_REQUEST id_request mediumint(8) unsigned NOT NULL auto_increment',
  129. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  130. 'ID_GROUP' => 'ID_GROUP id_group smallint(5) unsigned NOT NULL default \'0\'',
  131. ),
  132. 'log_karma' => array(
  133. 'ID_TARGET' => 'ID_TARGET id_target mediumint(8) unsigned NOT NULL default \'0\'',
  134. 'ID_EXECUTOR' => 'ID_EXECUTOR id_executor mediumint(8) unsigned NOT NULL default \'0\'',
  135. 'logTime' => 'logTime log_time int(10) unsigned NOT NULL default \'0\'',
  136. ),
  137. 'log_mark_read' => array(
  138. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  139. 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'',
  140. 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'',
  141. ),
  142. 'log_notify' => array(
  143. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  144. 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'',
  145. 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'',
  146. ),
  147. 'log_packages' => array(
  148. 'ID_INSTALL' => 'ID_INSTALL id_install int(10) NOT NULL auto_increment',
  149. 'ID_MEMBER_INSTALLED' => 'ID_MEMBER_INSTALLED id_member_installed mediumint(8) NOT NULL default \'0\'',
  150. 'ID_MEMBER_REMOVED' => 'ID_MEMBER_REMOVED id_member_removed mediumint(8) NOT NULL default \'0\'',
  151. ),
  152. 'log_polls' => array(
  153. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  154. 'ID_CHOICE' => 'ID_CHOICE id_choice tinyint(3) unsigned NOT NULL default \'0\'',
  155. 'ID_POLL' => 'ID_POLL id_poll mediumint(8) unsigned NOT NULL default \'0\'',
  156. ),
  157. 'log_reported' => array(
  158. 'ID_REPORT' => 'ID_REPORT id_report mediumint(8) unsigned NOT NULL auto_increment',
  159. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  160. 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'',
  161. 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'',
  162. 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'',
  163. ),
  164. 'log_reported_comments' => array(
  165. 'ID_COMMENT' => 'ID_COMMENT id_comment mediumint(8) unsigned NOT NULL auto_increment',
  166. 'ID_REPORT' => 'ID_REPORT id_report mediumint(8) NOT NULL default \'0\'',
  167. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  168. ),
  169. 'log_scheduled_tasks' => array(
  170. 'ID_LOG' => 'ID_LOG id_log mediumint(8) NOT NULL auto_increment',
  171. 'ID_TASK' => 'ID_TASK id_task smallint(5) NOT NULL default \'0\'',
  172. 'timeRun' => 'timeRun time_run int(10) NOT NULL default \'0\'',
  173. 'timeTaken' => 'timeTaken time_taken float NOT NULL default \'0\'',
  174. ),
  175. 'log_search_messages' => array(
  176. 'ID_SEARCH' => 'ID_SEARCH id_search tinyint(3) unsigned NOT NULL default \'0\'',
  177. 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'',
  178. ),
  179. 'log_search_results' => array(
  180. 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'',
  181. 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'',
  182. 'ID_SEARCH' => 'ID_SEARCH id_search tinyint(3) unsigned NOT NULL default \'0\'',
  183. ),
  184. 'log_search_subjects' => array(
  185. 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'',
  186. ),
  187. 'log_search_topics' => array(
  188. 'ID_SEARCH' => 'ID_SEARCH id_search tinyint(3) unsigned NOT NULL default \'0\'',
  189. 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'',
  190. ),
  191. 'log_subscribed' => array(
  192. 'ID_SUBLOG' => 'ID_SUBLOG id_sublog int(10) unsigned NOT NULL auto_increment',
  193. 'ID_SUBSCRIBE' => 'ID_SUBSCRIBE id_subscribe mediumint(8) unsigned NOT NULL default \'0\'',
  194. 'OLD_ID_GROUP' => 'OLD_ID_GROUP old_id_group smallint(5) NOT NULL default \'0\'',
  195. 'startTime' => 'startTime start_time int(10) NOT NULL default \'0\'',
  196. 'endTime' => 'endTime end_time int(10) NOT NULL default \'0\'',
  197. ),
  198. 'log_topics' => array(
  199. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  200. 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'',
  201. 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'',
  202. ),
  203. 'mail_queue' => array(
  204. 'ID_MAIL' => 'ID_MAIL id_mail int(10) unsigned NOT NULL auto_increment',
  205. ),
  206. 'members' => array(
  207. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL auto_increment',
  208. 'memberName' => 'memberName member_name varchar(80) NOT NULL default \'\'',
  209. 'dateRegistered' => 'dateRegistered date_registered int(10) unsigned NOT NULL default \'0\'',
  210. 'ID_GROUP' => 'ID_GROUP id_group smallint(5) unsigned NOT NULL default \'0\'',
  211. 'lastLogin' => 'lastLogin last_login int(10) unsigned NOT NULL default \'0\'',
  212. 'realName' => 'realName real_name varchar(255) NOT NULL default \'\'',
  213. 'instantMessages' => 'instantMessages instant_messages smallint(5) NOT NULL default \'0\'',
  214. 'unreadMessages' => 'unreadMessages unread_messages smallint(5) NOT NULL default \'0\'',
  215. 'messageLabels' => 'messageLabels message_labels text NOT NULL',
  216. 'emailAddress' => 'emailAddress email_address varchar(255) NOT NULL default \'\'',
  217. 'personalText' => 'personalText personal_text varchar(255) NOT NULL default \'\'',
  218. 'websiteTitle' => 'websiteTitle website_title varchar(255) NOT NULL default \'\'',
  219. 'websiteUrl' => 'websiteUrl website_url varchar(255) NOT NULL default \'\'',
  220. 'ICQ' => 'ICQ icq varchar(255) NOT NULL default \'\'',
  221. 'AIM' => 'AIM aim varchar(255) NOT NULL default \'\'',
  222. 'YIM' => 'YIM yim varchar(32) NOT NULL default \'\'',
  223. 'MSN' => 'MSN msn varchar(255) NOT NULL default \'\'',
  224. 'hideEmail' => 'hideEmail hide_email tinyint(4) NOT NULL default \'0\'',
  225. 'showOnline' => 'showOnline show_online tinyint(4) NOT NULL default \'1\'',
  226. 'timeFormat' => 'timeFormat time_format varchar(80) NOT NULL default \'\'',
  227. 'timeOffset' => 'timeOffset time_offset float NOT NULL default \'0\'',
  228. 'karmaBad' => 'karmaBad karma_bad smallint(5) unsigned NOT NULL default \'0\'',
  229. 'karmaGood' => 'karmaGood karma_good smallint(5) unsigned NOT NULL default \'0\'',
  230. 'notifyAnnouncements' => 'notifyAnnouncements notify_announcements tinyint(4) NOT NULL default \'1\'',
  231. 'notifyRegularity' => 'notifyRegularity notify_regularity tinyint(4) NOT NULL default \'1\'',
  232. 'notifySendBody' => 'notifySendBody notify_send_body tinyint(4) NOT NULL default \'0\'',
  233. 'notifyTypes' => 'notifyTypes notify_types tinyint(4) NOT NULL default \'2\'',
  234. 'memberIP' => 'memberIP member_ip varchar(255) NOT NULL default \'\'',
  235. 'secretQuestion' => 'secretQuestion secret_question varchar(255) NOT NULL default \'\'',
  236. 'secretAnswer' => 'secretAnswer secret_answer varchar(64) NOT NULL default \'\'',
  237. 'ID_THEME' => 'ID_THEME id_theme tinyint(4) unsigned NOT NULL default \'0\'',
  238. 'ID_MSG_LAST_VISIT' => 'ID_MSG_LAST_VISIT id_msg_last_visit int(10) unsigned NOT NULL default \'0\'',
  239. 'additionalGroups' => 'additionalGroups additional_groups varchar(255) NOT NULL default \'\'',
  240. 'smileySet' => 'smileySet smiley_set varchar(48) NOT NULL default \'\'',
  241. 'ID_POST_GROUP' => 'ID_POST_GROUP id_post_group smallint(5) unsigned NOT NULL default \'0\'',
  242. 'totalTimeLoggedIn' => 'totalTimeLoggedIn total_time_logged_in int(10) unsigned NOT NULL default \'0\'',
  243. 'passwordSalt' => 'passwordSalt password_salt varchar(255) NOT NULL default \'\'',
  244. 'ignoreBoards' => 'ignoreBoards ignore_boards text NOT NULL',
  245. 'memberIP2' => 'memberIP2 member_ip2 varchar(255) NOT NULL default \'\'',
  246. ),
  247. 'messages' => array(
  248. 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL auto_increment',
  249. 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'',
  250. 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'',
  251. 'posterTime' => 'posterTime poster_time int(10) unsigned NOT NULL default \'0\'',
  252. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  253. 'ID_MSG_MODIFIED' => 'ID_MSG_MODIFIED id_msg_modified int(10) unsigned NOT NULL default \'0\'',
  254. 'posterName' => 'posterName poster_name varchar(255) NOT NULL default \'\'',
  255. 'posterEmail' => 'posterEmail poster_email varchar(255) NOT NULL default \'\'',
  256. 'posterIP' => 'posterIP poster_ip varchar(255) NOT NULL default \'\'',
  257. 'smileysEnabled' => 'smileysEnabled smileys_enabled tinyint(4) NOT NULL default \'1\'',
  258. 'modifiedTime' => 'modifiedTime modified_time int(10) unsigned NOT NULL default \'0\'',
  259. 'modifiedName' => 'modifiedName modified_name varchar(255) NOT NULL default \'\'',
  260. ),
  261. 'membergroups' => array(
  262. 'ID_GROUP' => 'ID_GROUP id_group smallint(5) unsigned NOT NULL auto_increment',
  263. 'ID_PARENT' => 'ID_PARENT id_parent smallint(5) NOT NULL default \'-2\'',
  264. 'groupName' => 'groupName group_name varchar(80) NOT NULL default \'\'',
  265. 'onlineColor' => 'onlineColor online_color varchar(20) NOT NULL default \'\'',
  266. 'minPosts' => 'minPosts min_posts mediumint(9) NOT NULL default \'-1\'',
  267. 'maxMessages' => 'maxMessages max_messages smallint(5) unsigned NOT NULL default \'0\'',
  268. 'groupType' => 'groupType group_type tinyint(3) NOT NULL default \'0\'',
  269. ),
  270. 'message_icons' => array(
  271. 'ID_ICON' => 'ID_ICON id_icon smallint(5) unsigned NOT NULL auto_increment',
  272. 'iconOrder' => 'iconOrder icon_order smallint(5) unsigned NOT NULL default \'0\'',
  273. 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'',
  274. ),
  275. 'moderators' => array(
  276. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  277. 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'',
  278. ),
  279. 'package_servers' => array(
  280. 'ID_SERVER' => 'ID_SERVER id_server smallint(5) unsigned NOT NULL auto_increment',
  281. ),
  282. 'personal_messages' => array(
  283. 'ID_PM' => 'ID_PM id_pm int(10) unsigned NOT NULL auto_increment',
  284. 'ID_MEMBER_FROM' => 'ID_MEMBER_FROM id_member_from mediumint(8) unsigned NOT NULL default \'0\'',
  285. 'deletedBySender' => 'deletedBySender deleted_by_sender tinyint(3) unsigned NOT NULL default \'0\'',
  286. 'fromName' => 'fromName from_name varchar(255) NOT NULL default \'\'',
  287. ),
  288. 'permission_profiles' => array(
  289. 'ID_PROFILE' => 'ID_PROFILE id_profile smallint(5) NOT NULL auto_increment',
  290. ),
  291. 'permissions' => array(
  292. 'ID_GROUP' => 'ID_GROUP id_group smallint(5) NOT NULL default \'0\'',
  293. 'addDeny' => 'addDeny add_deny tinyint(4) NOT NULL default \'1\'',
  294. ),
  295. 'pm_recipients' => array(
  296. 'ID_PM' => 'ID_PM id_pm int(10) unsigned NOT NULL default \'0\'',
  297. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  298. ),
  299. 'polls' => array(
  300. 'ID_POLL' => 'ID_POLL id_poll mediumint(8) unsigned NOT NULL auto_increment',
  301. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'',
  302. 'votingLocked' => 'votingLocked voting_locked tinyint(1) NOT NULL default \'0\'',
  303. 'maxVotes' => 'maxVotes max_votes tinyint(3) unsigned NOT NULL default \'1\'',
  304. 'expireTime' => 'expireTime expire_time int(10) unsigned NOT NULL default \'0\'',
  305. 'hideResults' => 'hideResults hide_results tinyint(3) unsigned NOT NULL default \'0\'',
  306. 'changeVote' => 'changeVote change_vote tinyint(3) unsigned NOT NULL default \'0\'',
  307. 'posterName' => 'posterName poster_name varchar(255) NOT NULL default \'\'',
  308. ),
  309. 'poll_choices' => array(
  310. 'ID_CHOICE' => 'ID_CHOICE id_choice tinyint(3) unsigned NOT NULL default \'0\'',
  311. 'ID_POLL' => 'ID_POLL id_poll mediumint(8) unsigned NOT NULL default \'0\'',
  312. ),
  313. 'scheduled_tasks' => array(
  314. 'ID_TASK' => 'ID_TASK id_task smallint(5) NOT NULL auto_increment',
  315. 'nextTime' => 'nextTime next_time int(10) NOT NULL default \'0\'',
  316. 'timeRegularity' => 'timeRegularity time_regularity smallint(5) NOT NULL default \'0\'',
  317. 'timeOffset' => 'timeOffset time_offset int(10) NOT NULL default \'0\'',
  318. 'timeUnit' => 'timeUnit time_unit varchar(1) NOT NULL default \'h\'',
  319. ),
  320. 'smileys' => array(
  321. 'ID_SMILEY' => 'ID_SMILEY id_smiley smallint(5) unsigned NOT NULL auto_increment',
  322. 'smileyRow' => 'smileyRow smiley_row tinyint(4) unsigned NOT NULL default \'0\'',
  323. 'smileyOrder' => 'smileyOrder smiley_order smallint(5) unsigned NOT NULL default \'0\'',
  324. ),
  325. 'subscriptions' => array(
  326. 'ID_SUBSCRIBE' => 'ID_SUBSCRIBE id_subscribe mediumint(8) unsigned NOT NULL auto_increment',
  327. 'ID_GROUP' => 'ID_GROUP id_group smallint(5) NOT NULL default \'0\'',
  328. 'addGroups' => 'addGroups add_groups varchar(40) NOT NULL default \'\'',
  329. 'allowPartial' => 'allowPartial allow_partial tinyint(3) NOT NULL default \'0\'',
  330. ),
  331. 'themes' => array(
  332. 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) NOT NULL default \'0\'',
  333. 'ID_THEME' => 'ID_THEME id_theme tinyint(4) unsigned NOT NULL default \'1\'',
  334. ),
  335. 'topics' => array(
  336. 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL auto_increment',
  337. 'isSticky' => 'isSticky is_sticky tinyint(4) NOT NULL default \'0\'',
  338. 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'',
  339. 'ID_FIRST_MSG' => 'ID_FIRST_MSG id_first_msg int(10) unsigned NOT NULL default \'0\'',
  340. 'ID_LAST_MSG' => 'ID_LAST_MSG id_last_msg int(10) unsigned NOT NULL default \'0\'',
  341. 'ID_MEMBER_STARTED' => 'ID_MEMBER_STARTED id_member_started mediumint(8) unsigned NOT NULL default \'0\'',
  342. 'ID_MEMBER_UPDATED' => 'ID_MEMBER_UPDATED id_member_updated mediumint(8) unsigned NOT NULL default \'0\'',
  343. 'ID_POLL' => 'ID_POLL id_poll mediumint(8) unsigned NOT NULL default \'0\'',
  344. 'numReplies' => 'numReplies num_replies int(10) unsigned NOT NULL default \'0\'',
  345. 'numViews' => 'numViews num_views int(10) unsigned NOT NULL default \'0\'',
  346. 'unapprovedPosts' => 'unapprovedPosts unapproved_posts smallint(5) NOT NULL default \'0\'',
  347. ),
  348. );
  349. $_GET['ren_col'] = isset($_GET['ren_col']) ? (int) $_GET['ren_col'] : 0;
  350. $step_progress['name'] = 'Renaming columns';
  351. $step_progress['current'] = $_GET['ren_col'];
  352. $step_progress['total'] = count($nameChanges);
  353. $count = 0;
  354. // Now do every table...
  355. foreach ($nameChanges as $table_name => $table)
  356. {
  357. // Already done this?
  358. $count++;
  359. if ($_GET['ren_col'] > $count)
  360. continue;
  361. $_GET['ren_col'] = $count;
  362. // Check the table exists!
  363. $request = upgrade_query("
  364. SHOW TABLES
  365. LIKE '{$db_prefix}$table_name'");
  366. if (smf_mysql_num_rows($request) == 0)
  367. {
  368. smf_mysql_free_result($request);
  369. continue;
  370. }
  371. smf_mysql_free_result($request);
  372. // Check each column!
  373. $actualChanges = array();
  374. foreach ($table as $colname => $coldef)
  375. {
  376. $change = array(
  377. 'table' => $table_name,
  378. 'name' => $colname,
  379. 'type' => 'column',
  380. 'method' => 'change_remove',
  381. 'text' => 'CHANGE ' . $coldef,
  382. );
  383. // Check if this change may need a special edit.
  384. checkChange($change);
  385. if (protected_alter($change, $substep, true) == false)
  386. $actualChanges[] = ' CHANGE COLUMN ' . $coldef;
  387. }
  388. // Do the query - if it needs doing.
  389. if (!empty($actualChanges))
  390. {
  391. $change = array(
  392. 'table' => $table_name,
  393. 'name' => 'na',
  394. 'type' => 'table',
  395. 'method' => 'full_change',
  396. 'text' => implode(', ', $actualChanges),
  397. );
  398. // Here we go - hold on!
  399. protected_alter($change, $substep);
  400. }
  401. // Update where we are!
  402. $step_progress['current'] = $_GET['ren_col'];
  403. }
  404. // All done!
  405. unset($_GET['ren_col']);
  406. ---}
  407. ---#
  408. ---# Converting "log_online".
  409. DROP TABLE IF EXISTS {$db_prefix}log_online;
  410. CREATE TABLE {$db_prefix}log_online (
  411. session varchar(32) NOT NULL default '',
  412. log_time int(10) NOT NULL default '0',
  413. id_member mediumint(8) unsigned NOT NULL default '0',
  414. id_spider smallint(5) unsigned NOT NULL default '0',
  415. ip int(10) unsigned NOT NULL default '0',
  416. url text NOT NULL,
  417. PRIMARY KEY (session),
  418. KEY log_time (log_time),
  419. KEY id_member (id_member)
  420. ) ENGINE=MyISAM{$db_collation};
  421. ---#
  422. /******************************************************************************/
  423. --- Adding new board specific features.
  424. /******************************************************************************/
  425. ---# Implementing board redirects.
  426. ALTER TABLE {$db_prefix}boards
  427. ADD COLUMN redirect varchar(255) NOT NULL default '';
  428. ---#
  429. /******************************************************************************/
  430. --- Adding search engine tracking.
  431. /******************************************************************************/
  432. ---# Creating spider table.
  433. CREATE TABLE IF NOT EXISTS {$db_prefix}spiders (
  434. id_spider smallint(5) unsigned NOT NULL auto_increment,
  435. spider_name varchar(255) NOT NULL default '',
  436. user_agent varchar(255) NOT NULL default '',
  437. ip_info varchar(255) NOT NULL default '',
  438. PRIMARY KEY id_spider(id_spider)
  439. ) ENGINE=MyISAM{$db_collation};
  440. INSERT IGNORE INTO {$db_prefix}spiders
  441. (id_spider, spider_name, user_agent, ip_info)
  442. VALUES
  443. (1, 'Google', 'googlebot', ''),
  444. (2, 'Yahoo!', 'slurp', ''),
  445. (3, 'MSN', 'msnbot', ''),
  446. (4, 'Google (Mobile)', 'Googlebot-Mobile', ''),
  447. (5, 'Google (Image)', 'Googlebot-Image', ''),
  448. (6, 'Google (AdSense)', 'Mediapartners-Google', ''),
  449. (7, 'Google (Adwords)', 'AdsBot-Google', ''),
  450. (8, 'Yahoo! (Mobile)', 'YahooSeeker/M1A1-R2D2', ''),
  451. (9, 'Yahoo! (Image)', 'Yahoo-MMCrawler', ''),
  452. (10, 'MSN (Mobile)', 'MSNBOT_Mobile', ''),
  453. (11, 'MSN (Media)', 'msnbot-media', ''),
  454. (12, 'Cuil', 'twiceler', ''),
  455. (13, 'Ask', 'Teoma', ''),
  456. (14, 'Baidu', 'Baiduspider', ''),
  457. (15, 'Gigablast', 'Gigabot', ''),
  458. (16, 'InternetArchive', 'ia_archiver-web.archive.org', ''),
  459. (17, 'Alexa', 'ia_archiver', ''),
  460. (18, 'Omgili', 'omgilibot', ''),
  461. (19, 'EntireWeb', 'Speedy Spider', '');
  462. ---#
  463. ---# Removing a spider.
  464. ---{
  465. upgrade_query("
  466. DELETE FROM {$db_prefix}spiders
  467. WHERE user_agent = 'yahoo'
  468. AND spider_name = 'Yahoo! (Publisher)'
  469. ");
  470. ---}
  471. ---#
  472. ---# Creating spider hit tracking table.
  473. CREATE TABLE IF NOT EXISTS {$db_prefix}log_spider_hits (
  474. id_hit int(10) unsigned NOT NULL auto_increment,
  475. id_spider smallint(5) unsigned NOT NULL default '0',
  476. log_time int(10) unsigned NOT NULL default '0',
  477. url varchar(255) NOT NULL default '',
  478. processed tinyint(3) unsigned NOT NULL default '0',
  479. PRIMARY KEY (id_hit),
  480. KEY id_spider(id_spider),
  481. KEY log_time(log_time),
  482. KEY processed (processed)
  483. ) ENGINE=MyISAM{$db_collation};
  484. ---#
  485. ---# Making some changes to spider hit table...
  486. ALTER TABLE {$db_prefix}log_spider_hits
  487. ADD COLUMN id_hit int(10) unsigned NOT NULL auto_increment,
  488. ADD PRIMARY KEY (id_hit);
  489. ---#
  490. ---# Creating spider statistic table.
  491. CREATE TABLE IF NOT EXISTS {$db_prefix}log_spider_stats (
  492. id_spider smallint(5) unsigned NOT NULL default '0',
  493. page_hits smallint(5) unsigned NOT NULL default '0',
  494. last_seen int(10) unsigned NOT NULL default '0',
  495. stat_date date NOT NULL default '0001-01-01',
  496. PRIMARY KEY (stat_date, id_spider)
  497. ) ENGINE=MyISAM{$db_collation};
  498. ---#
  499. /******************************************************************************/
  500. --- Adding new forum settings.
  501. /******************************************************************************/
  502. ---# Resetting settings_updated.
  503. REPLACE INTO {$db_prefix}settings
  504. (variable, value)
  505. VALUES
  506. ('settings_updated', '0'),
  507. ('last_mod_report_action', '0'),
  508. ('search_floodcontrol_time', '5'),
  509. ('next_task_time', UNIX_TIMESTAMP());
  510. ---#
  511. ---# Changing stats settings.
  512. ---{
  513. $request = upgrade_query("
  514. SELECT value
  515. FROM {$db_prefix}themes
  516. WHERE variable = 'show_sp1_info'");
  517. if (smf_mysql_num_rows($request) != 0)
  518. {
  519. upgrade_query("
  520. DELETE FROM {$db_prefix}themes
  521. WHERE variable = 'show_stats_index'");
  522. upgrade_query("
  523. UPDATE {$db_prefix}themes
  524. SET variable = 'show_stats_index'
  525. WHERE variable = 'show_sp1_info'");
  526. }
  527. upgrade_query("
  528. DELETE FROM {$db_prefix}themes
  529. WHERE variable = 'show_sp1_info'");
  530. ---}
  531. ---#
  532. ---# Enable cache if upgrading from 1.1 and lower.
  533. ---{
  534. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1')
  535. {
  536. $request = upgrade_query("
  537. SELECT value
  538. FROM {$db_prefix}settings
  539. WHERE variable = 'cache_enable'");
  540. list ($cache_enable) = $smcFunc['db_fetch_row']($request);
  541. // No cache before 1.1.
  542. if ($smcFunc['db_num_rows']($request) == 0)
  543. upgrade_query("
  544. INSERT INTO {$db_prefix}settings
  545. (variable, value)
  546. VALUES ('cache_enable', '1')");
  547. elseif (empty($cache_enable))
  548. upgrade_query("
  549. UPDATE {$db_prefix}settings
  550. SET value = '1'
  551. WHERE variable = 'cache_enable'");
  552. }
  553. ---}
  554. ---#
  555. ---# Changing visual verification setting.
  556. ---{
  557. $request = upgrade_query("
  558. SELECT value
  559. FROM {$db_prefix}settings
  560. WHERE variable = 'disable_visual_verification'");
  561. if (smf_mysql_num_rows($request) != 0)
  562. {
  563. list ($oldValue) = smf_mysql_fetch_row($request);
  564. if ($oldValue != 0)
  565. {
  566. // We have changed the medium setting from SMF 1.1.2.
  567. if ($oldValue == 4)
  568. $oldValue = 5;
  569. upgrade_query("
  570. UPDATE {$db_prefix}settings
  571. SET variable = 'visual_verification_type', value = $oldValue
  572. WHERE variable = 'disable_visual_verification'");
  573. }
  574. }
  575. upgrade_query("
  576. DELETE FROM {$db_prefix}settings
  577. WHERE variable = 'disable_visual_verification'");
  578. ---}
  579. ---#
  580. ---# Changing visual verification setting, again.
  581. ---{
  582. $request = upgrade_query("
  583. SELECT value
  584. FROM {$db_prefix}settings
  585. WHERE variable = 'reg_verification'");
  586. if (smf_mysql_num_rows($request) == 0)
  587. {
  588. // Upgrade visual verification again!
  589. if (!empty($modSettings['visual_verification_type']))
  590. {
  591. upgrade_query("
  592. UPDATE {$db_prefix}settings
  593. SET value = value - 1
  594. WHERE variable = 'visual_verification_type'");
  595. $modSettings['visual_verification_type']--;
  596. }
  597. // Never set?
  598. elseif (!isset($modSettings['visual_verification_type']))
  599. {
  600. upgrade_query("
  601. INSERT INTO {$db_prefix}settings
  602. (variable, value)
  603. VALUES
  604. ('visual_verification_type', '3')");
  605. $modSettings['visual_verification_type'] = 3;
  606. }
  607. upgrade_query("
  608. INSERT INTO {$db_prefix}settings
  609. (variable, value)
  610. VALUES
  611. ('reg_verification', '" . (!empty($modSettings['visual_verification_type']) ? 1 : 0) . "')");
  612. }
  613. ---}
  614. ---#
  615. ---# Changing default personal text setting.
  616. UPDATE {$db_prefix}settings
  617. SET variable = 'default_personal_text'
  618. WHERE variable = 'default_personalText';
  619. DELETE FROM {$db_prefix}settings
  620. WHERE variable = 'default_personalText';
  621. ---#
  622. ---# Removing allow hide email setting.
  623. DELETE FROM {$db_prefix}settings
  624. WHERE variable = 'allow_hideEmail'
  625. OR variable = 'allow_hide_email';
  626. ---#
  627. ---# Ensuring stats index setting present...
  628. INSERT IGNORE INTO {$db_prefix}themes
  629. (id_theme, variable, value)
  630. VALUES
  631. (1, 'show_stats_index', '0');
  632. ---#
  633. ---# Ensuring forum width setting present...
  634. INSERT IGNORE INTO {$db_prefix}themes
  635. (id_theme, variable, value)
  636. VALUES
  637. (1, 'forum_width', '90%');
  638. ---#
  639. ---# Replacing old calendar settings...
  640. ---{
  641. // Only try it if one of the "new" settings doesn't yet exist.
  642. if (!isset($modSettings['cal_showholidays']) || !isset($modSettings['cal_showbdays']) || !isset($modSettings['cal_showevents']))
  643. {
  644. // Default to just the calendar setting.
  645. $modSettings['cal_showholidays'] = empty($modSettings['cal_showholidaysoncalendar']) ? 0 : 1;
  646. $modSettings['cal_showbdays'] = empty($modSettings['cal_showbdaysoncalendar']) ? 0 : 1;
  647. $modSettings['cal_showevents'] = empty($modSettings['cal_showeventsoncalendar']) ? 0 : 1;
  648. // Then take into account board index.
  649. if (!empty($modSettings['cal_showholidaysonindex']))
  650. $modSettings['cal_showholidays'] = $modSettings['cal_showholidays'] === 1 ? 2 : 3;
  651. if (!empty($modSettings['cal_showbdaysonindex']))
  652. $modSettings['cal_showbdays'] = $modSettings['cal_showbdays'] === 1 ? 2 : 3;
  653. if (!empty($modSettings['cal_showeventsonindex']))
  654. $modSettings['cal_showevents'] = $modSettings['cal_showevents'] === 1 ? 2 : 3;
  655. // Actually save the settings.
  656. upgrade_query("
  657. INSERT IGNORE INTO {$db_prefix}settings
  658. (variable, value)
  659. VALUES
  660. ('cal_showholidays', $modSettings[cal_showholidays]),
  661. ('cal_showbdays', $modSettings[cal_showbdays]),
  662. ('cal_showevents', $modSettings[cal_showevents])");
  663. }
  664. ---}
  665. ---#
  666. ---# Deleting old calendar settings...
  667. DELETE FROM {$db_prefix}settings
  668. WHERE VARIABLE IN ('cal_showholidaysonindex', 'cal_showbdaysonindex', 'cal_showeventsonindex',
  669. 'cal_showholidaysoncalendar', 'cal_showbdaysoncalendar', 'cal_showeventsoncalendar',
  670. 'cal_holidaycolor', 'cal_bdaycolor', 'cal_eventcolor');
  671. ---#
  672. ---# Adjusting calendar maximum year...
  673. ---{
  674. if (!isset($modSettings['cal_maxyear']) || $modSettings['cal_maxyear'] == '2010')
  675. {
  676. upgrade_query("
  677. REPLACE INTO {$db_prefix}settings
  678. (variable, value)
  679. VALUES
  680. ('cal_maxyear', '2020')");
  681. }
  682. ---}
  683. ---#
  684. ---# Adding advanced signature settings...
  685. ---{
  686. if (empty($modSettings['signature_settings']))
  687. {
  688. if (isset($modSettings['max_signatureLength']))
  689. $modSettings['signature_settings'] = '1,' . $modSettings['max_signatureLength'] . ',0,0,0,0,0,0:';
  690. else
  691. $modSettings['signature_settings'] = '1,300,0,0,0,0,0,0:';
  692. upgrade_query("
  693. INSERT IGNORE INTO {$db_prefix}settings
  694. (variable, value)
  695. VALUES
  696. ('signature_settings', '$modSettings[signature_settings]')");
  697. upgrade_query("
  698. DELETE FROM {$db_prefix}settings
  699. WHERE variable = 'max_signatureLength'");
  700. }
  701. ---}
  702. ---#
  703. ---# Updating spam protection settings.
  704. ---{
  705. if (empty($modSettings['pm_spam_settings']))
  706. {
  707. if (isset($modSettings['max_pm_recipients']))
  708. $modSettings['pm_spam_settings'] = $modSettings['max_pm_recipients'] . ',5,20';
  709. else
  710. $modSettings['pm_spam_settings'] = '10,5,20';
  711. }
  712. elseif (substr_count($modSettings['pm_spam_settings'], ',') == 1)
  713. {
  714. $modSettings['pm_spam_settings'] .= ',20';
  715. }
  716. upgrade_query("
  717. INSERT IGNORE INTO {$db_prefix}settings
  718. (variable, value)
  719. VALUES
  720. ('pm_spam_settings', '$modSettings[pm_spam_settings]')");
  721. upgrade_query("
  722. DELETE FROM {$db_prefix}settings
  723. WHERE variable = 'max_pm_recipients'");
  724. ---}
  725. ---#
  726. ---# Adjusting timezone settings...
  727. ---{
  728. if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
  729. {
  730. $server_offset = mktime(0, 0, 0, 1, 1, 1970);
  731. $timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600);
  732. if (date_default_timezone_set($timezone_id))
  733. upgrade_query("
  734. REPLACE INTO {$db_prefix}settings
  735. (variable, value)
  736. VALUES
  737. ('default_timezone', '$timezone_id')");
  738. }
  739. ---}
  740. ---#
  741. ---# Checking theme layers are correct for default themes.
  742. ---{
  743. $request = upgrade_query("
  744. SELECT id_theme, value, variable
  745. FROM {$db_prefix}themes
  746. WHERE variable = 'theme_layers'
  747. OR variable = 'theme_dir'");
  748. $themeLayerChanges = array();
  749. while ($row = smf_mysql_fetch_assoc($request))
  750. {
  751. $themeLayerChanges[$row['id_theme']][$row['variable']] = $row['value'];
  752. }
  753. smf_mysql_free_result($request);
  754. foreach ($themeLayerChanges as $id_theme => $data)
  755. {
  756. // Has to be a SMF provided theme and have custom layers defined.
  757. if (!isset($data['theme_layers']) || !isset($data['theme_dir']) || !in_array(substr($data['theme_dir'], -7), array('default', 'babylon', 'classic')))
  758. continue;
  759. $layers = explode(',', $data['theme_layers']);
  760. foreach ($layers as $k => $v)
  761. if ($v == 'main')
  762. {
  763. $layers[$k] = 'html,body';
  764. upgrade_query("
  765. UPDATE {$db_prefix}themes
  766. SET value = '" . implode(',', $layers) . "'
  767. WHERE id_theme = $id_theme
  768. AND variable = 'theme_layers'");
  769. break;
  770. }
  771. }
  772. ---}
  773. ---#
  774. ---# Adding index to log_notify table...
  775. ALTER TABLE {$db_prefix}log_notify
  776. ADD INDEX id_topic (id_topic, id_member);
  777. ---#
  778. /******************************************************************************/
  779. --- Adding custom profile fields.
  780. /******************************************************************************/
  781. ---# Creating "custom_fields" table...
  782. CREATE TABLE IF NOT EXISTS {$db_prefix}custom_fields (
  783. id_field smallint(5) NOT NULL auto_increment,
  784. col_name varchar(12) NOT NULL default '',
  785. field_name varchar(40) NOT NULL default '',
  786. field_desc varchar(255) NOT NULL default '',
  787. field_type varchar(8) NOT NULL default 'text',
  788. field_length smallint(5) NOT NULL default '255',
  789. field_options text NOT NULL,
  790. mask varchar(255) NOT NULL default '',
  791. show_reg tinyint(3) NOT NULL default '0',
  792. show_display tinyint(3) NOT NULL default '0',
  793. show_profile varchar(20) NOT NULL default 'forumprofile',
  794. private tinyint(3) NOT NULL default '0',
  795. active tinyint(3) NOT NULL default '1',
  796. bbc tinyint(3) NOT NULL default '0',
  797. default_value varchar(255) NOT NULL default '',
  798. PRIMARY KEY (id_field),
  799. UNIQUE col_name (col_name)
  800. ) ENGINE=MyISAM{$db_collation};
  801. ---#
  802. ---# Adding search ability to custom fields.
  803. ALTER TABLE {$db_prefix}custom_fields
  804. ADD COLUMN can_search tinyint(3) NOT NULL default '0' AFTER bbc;
  805. ---#
  806. ---# Fixing default value field length.
  807. ALTER TABLE {$db_prefix}custom_fields
  808. CHANGE COLUMN default_value default_value varchar(255) NOT NULL default '';
  809. ---#
  810. ---# Enhancing privacy settings for custom fields.
  811. ---{
  812. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1')
  813. {
  814. upgrade_query("
  815. UPDATE {$db_prefix}custom_fields
  816. SET private = 2
  817. WHERE private = 1");
  818. }
  819. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] < '2.0 Beta 4')
  820. {
  821. upgrade_query("
  822. UPDATE {$db_prefix}custom_fields
  823. SET private = 3
  824. WHERE private = 2");
  825. }
  826. ---}
  827. ---#
  828. ---# Checking display fields setup correctly..
  829. ---{
  830. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1' && isset($modSettings['displayFields']) && @unserialize($modSettings['displayFields']) == false)
  831. {
  832. $request = upgrade_query("
  833. SELECT col_name, field_name, bbc
  834. FROM {$db_prefix}custom_fields
  835. WHERE show_display = 1
  836. AND active = 1
  837. AND private != 2");
  838. $fields = array();
  839. while ($row = smf_mysql_fetch_assoc($request))
  840. {
  841. $fields[] = array(
  842. 'c' => strtr($row['col_name'], array('|' => '', ';' => '')),
  843. 'f' => strtr($row['field_name'], array('|' => '', ';' => '')),
  844. 'b' => ($row['bbc'] ? '1' : '0')
  845. );
  846. }
  847. smf_mysql_free_result($request);
  848. upgrade_query("
  849. UPDATE {$db_prefix}settings
  850. SET value = '" . smf_mysql_real_escape_string(serialize($fields)) . "'
  851. WHERE variable = 'displayFields'");
  852. }
  853. ---}
  854. ---#
  855. ---# Adding new custom fields columns.
  856. ALTER TABLE {$db_prefix}custom_fields
  857. ADD enclose text NOT NULL;
  858. ALTER TABLE {$db_prefix}custom_fields
  859. ADD placement tinyint(3) NOT NULL default '0';
  860. ---#
  861. /******************************************************************************/
  862. --- Adding email digest functionality.
  863. /******************************************************************************/
  864. ---# Creating "log_digest" table...
  865. CREATE TABLE IF NOT EXISTS {$db_prefix}log_digest (
  866. id_topic mediumint(8) unsigned NOT NULL default '0',
  867. id_msg int(10) unsigned NOT NULL default '0',
  868. note_type varchar(10) NOT NULL default 'post',
  869. daily tinyint(3) unsigned NOT NULL default '0',
  870. exclude mediumint(8) unsigned NOT NULL default '0'
  871. ) ENGINE=MyISAM{$db_collation};
  872. ---#
  873. ---# Adding digest option to "members" table...
  874. ALTER TABLE {$db_prefix}members
  875. CHANGE COLUMN notifyOnce notify_regularity tinyint(4) unsigned NOT NULL default '1';
  876. ---#
  877. /******************************************************************************/
  878. --- Making changes to the package manager.
  879. /******************************************************************************/
  880. ---# Creating "log_packages" table...
  881. CREATE TABLE IF NOT EXISTS {$db_prefix}log_packages (
  882. id_install int(10) NOT NULL auto_increment,
  883. filename varchar(255) NOT NULL default '',
  884. package_id varchar(255) NOT NULL default '',
  885. name varchar(255) NOT NULL default '',
  886. version varchar(255) NOT NULL default '',
  887. id_member_installed mediumint(8) NOT NULL default '0',
  888. member_installed varchar(255) NOT NULL default '',
  889. time_installed int(10) NOT NULL default '0',
  890. id_member_removed mediumint(8) NOT NULL default '0',
  891. member_removed varchar(255) NOT NULL default '',
  892. time_removed int(10) NOT NULL default '0',
  893. install_state tinyint(3) NOT NULL default '1',
  894. failed_steps text NOT NULL,
  895. themes_installed varchar(255) NOT NULL default '',
  896. db_changes text NOT NULL,
  897. PRIMARY KEY (id_install),
  898. KEY filename (filename(15))
  899. ) ENGINE=MyISAM{$db_collation};
  900. ---#
  901. ---# Adding extra "log_packages" columns...
  902. ALTER TABLE {$db_prefix}log_packages
  903. ADD db_changes text NOT NULL AFTER themes_installed;
  904. ---#
  905. ---# Changing URL to SMF package server...
  906. UPDATE {$db_prefix}package_servers
  907. SET url = 'http://custom.simplemachines.org/packages/mods'
  908. WHERE url = 'http://mods.simplemachines.org';
  909. ---#
  910. /******************************************************************************/
  911. --- Creating mail queue functionality.
  912. /******************************************************************************/
  913. ---# Creating "mail_queue" table...
  914. CREATE TABLE IF NOT EXISTS {$db_prefix}mail_queue (
  915. id_mail int(10) unsigned NOT NULL auto_increment,
  916. time_sent int(10) NOT NULL default '0',
  917. recipient varchar(255) NOT NULL default '',
  918. body text NOT NULL,
  919. subject varchar(255) NOT NULL default '',
  920. headers text NOT NULL,
  921. send_html tinyint(3) NOT NULL default '0',
  922. priority tinyint(3) NOT NULL default '1',
  923. PRIMARY KEY (id_mail),
  924. KEY time_sent (time_sent),
  925. KEY mail_priority (priority, id_mail)
  926. ) ENGINE=MyISAM{$db_collation};
  927. ---#
  928. ---# Adding new mail queue settings...
  929. ---{
  930. if (!isset($modSettings['mail_next_send']))
  931. {
  932. upgrade_query("
  933. INSERT INTO {$db_prefix}settings
  934. (variable, value)
  935. VALUES
  936. ('mail_next_send', '0'),
  937. ('mail_recent', '0000000000|0')");
  938. }
  939. ---}
  940. ---#
  941. ---# Change mail queue indexes...
  942. ALTER TABLE {$db_prefix}mail_queue
  943. DROP INDEX priority;
  944. ALTER TABLE {$db_prefix}mail_queue
  945. ADD INDEX mail_priority (priority, id_mail);
  946. ---#
  947. ---# Adding type to mail queue...
  948. ALTER TABLE {$db_prefix}mail_queue
  949. ADD private tinyint(1) NOT NULL default '0';
  950. ---#
  951. /******************************************************************************/
  952. --- Creating moderation center tables.
  953. /******************************************************************************/
  954. ---# Creating "log_reported" table...
  955. CREATE TABLE IF NOT EXISTS {$db_prefix}log_reported (
  956. id_report mediumint(8) unsigned NOT NULL auto_increment,
  957. id_msg int(10) unsigned NOT NULL default '0',
  958. id_topic mediumint(8) unsigned NOT NULL default '0',
  959. id_board smallint(5) unsigned NOT NULL default '0',
  960. id_member mediumint(8) unsigned NOT NULL default '0',
  961. membername varchar(255) NOT NULL default '',
  962. subject varchar(255) NOT NULL default '',
  963. body text NOT NULL,
  964. time_started int(10) NOT NULL default '0',
  965. time_updated int(10) NOT NULL default '0',
  966. num_reports mediumint(6) NOT NULL default '0',
  967. closed tinyint(3) NOT NULL default '0',
  968. ignore_all tinyint(3) NOT NULL default '0',
  969. PRIMARY KEY (id_report),
  970. KEY id_member (id_member),
  971. KEY id_topic (id_topic),
  972. KEY closed (closed),
  973. KEY time_started (time_started),
  974. KEY id_msg (id_msg)
  975. ) ENGINE=MyISAM{$db_collation};
  976. ---#
  977. ---# Creating "log_reported_comments" table...
  978. CREATE TABLE IF NOT EXISTS {$db_prefix}log_reported_comments (
  979. id_comment mediumint(8) unsigned NOT NULL auto_increment,
  980. id_report mediumint(8) NOT NULL default '0',
  981. id_member mediumint(8) NOT NULL,
  982. membername varchar(255) NOT NULL default '',
  983. comment varchar(255) NOT NULL default '',
  984. time_sent int(10) NOT NULL,
  985. PRIMARY KEY (id_comment),
  986. KEY id_report (id_report),
  987. KEY id_member (id_member),
  988. KEY time_sent (time_sent)
  989. ) ENGINE=MyISAM{$db_collation};
  990. ---#
  991. ---# Adding moderator center permissions...
  992. ---{
  993. // Don't do this twice!
  994. if (@$modSettings['smfVersion'] < '2.0')
  995. {
  996. // Try find people who probably should see the moderation center.
  997. $request = upgrade_query("
  998. SELECT id_group, add_deny, permission
  999. FROM {$db_prefix}permissions
  1000. WHERE permission = 'calendar_edit_any'");
  1001. $inserts = array();
  1002. while ($row = smf_mysql_fetch_assoc($request))
  1003. {
  1004. $inserts[] = "($row[id_group], 'access_mod_center', $row[add_deny])";
  1005. }
  1006. smf_mysql_free_result($request);
  1007. if (!empty($inserts))
  1008. upgrade_query("
  1009. INSERT IGNORE INTO {$db_prefix}permissions
  1010. (id_group, permission, add_deny)
  1011. VALUES
  1012. " . implode(',', $inserts));
  1013. }
  1014. ---}
  1015. ---#
  1016. ---# Adding moderation center preferences...
  1017. ALTER TABLE {$db_prefix}members
  1018. ADD mod_prefs varchar(20) NOT NULL default '';
  1019. ---#
  1020. /******************************************************************************/
  1021. --- Adding user warnings.
  1022. /******************************************************************************/
  1023. ---# Creating member notices table...
  1024. CREATE TABLE IF NOT EXISTS {$db_prefix}log_member_notices (
  1025. id_notice mediumint(8) unsigned NOT NULL auto_increment,
  1026. subject varchar(255) NOT NULL default '',
  1027. body text NOT NULL,
  1028. PRIMARY KEY (id_notice)
  1029. ) ENGINE=MyISAM{$db_collation};
  1030. ---#
  1031. ---# Creating comments table...
  1032. CREATE TABLE IF NOT EXISTS {$db_prefix}log_comments (
  1033. id_comment mediumint(8) unsigned NOT NULL auto_increment,
  1034. id_member mediumint(8) unsigned NOT NULL default '0',
  1035. member_name varchar(80) NOT NULL default '',
  1036. comment_type varchar(8) NOT NULL default 'warning',
  1037. id_recipient mediumint(8) unsigned NOT NULL default '0',
  1038. recipient_name varchar(255) NOT NULL default '',
  1039. log_time int(10) NOT NULL default '0',
  1040. id_notice mediumint(8) unsigned NOT NULL default '0',
  1041. counter tinyint(3) NOT NULL default '0',
  1042. body text NOT NULL,
  1043. PRIMARY KEY (id_comment),
  1044. KEY id_recipient (id_recipient),
  1045. KEY log_time (log_time),
  1046. KEY comment_type (comment_type(8))
  1047. ) ENGINE=MyISAM{$db_collation};
  1048. ---#
  1049. ---# Adding user warning column...
  1050. ALTER TABLE {$db_prefix}members
  1051. ADD warning tinyint(4) NOT NULL default '0';
  1052. ALTER TABLE {$db_prefix}members
  1053. ADD INDEX warning (warning);
  1054. ---#
  1055. ---# Ensuring warning settings are present...
  1056. ---{
  1057. // Only do this if not already done.
  1058. if (empty($modSettings['warning_settings']))
  1059. {
  1060. upgrade_query("
  1061. INSERT IGNORE INTO {$db_prefix}settings
  1062. (variable, value)
  1063. VALUES
  1064. ('warning_settings', '1,20,0'),
  1065. ('warning_watch', '10'),
  1066. ('warning_moderate', '35'),
  1067. ('warning_mute', '60')");
  1068. }
  1069. ---}
  1070. ---#
  1071. /******************************************************************************/
  1072. --- Enhancing membergroups.
  1073. /******************************************************************************/
  1074. ---# Creating "log_group_requests" table...
  1075. CREATE TABLE IF NOT EXISTS {$db_prefix}log_group_requests (
  1076. id_request mediumint(8) unsigned NOT NULL auto_increment,
  1077. id_member mediumint(8) unsigned NOT NULL default '0',
  1078. id_group smallint(5) unsigned NOT NULL default '0',
  1079. time_applied int(10) unsigned NOT NULL default '0',
  1080. reason text NOT NULL,
  1081. PRIMARY KEY (id_request),
  1082. UNIQUE id_member (id_member, id_group)
  1083. ) ENGINE=MyISAM{$db_collation};
  1084. ---#
  1085. ---# Adding new membergroup table columns...
  1086. ALTER TABLE {$db_prefix}membergroups
  1087. ADD description text NOT NULL AFTER group_name;
  1088. ALTER TABLE {$db_prefix}membergroups
  1089. ADD group_type tinyint(3) NOT NULL default '0';
  1090. ALTER TABLE {$db_prefix}membergroups
  1091. ADD hidden tinyint(3) NOT NULL default '0';
  1092. ---#
  1093. ---# Creating "group_moderators" table...
  1094. CREATE TABLE IF NOT EXISTS {$db_prefix}group_moderators (
  1095. id_group smallint(5) unsigned NOT NULL default '0',
  1096. id_member mediumint(8) unsigned NOT NULL default '0',
  1097. PRIMARY KEY (id_group, id_member)
  1098. ) ENGINE=MyISAM{$db_collation};
  1099. ---#
  1100. /******************************************************************************/
  1101. --- Updating attachment data...
  1102. /******************************************************************************/
  1103. ---# Altering attachment table.
  1104. ALTER TABLE {$db_prefix}attachments
  1105. ADD COLUMN fileext varchar(8) NOT NULL default '',
  1106. ADD COLUMN mime_type varchar(20) NOT NULL default '';
  1107. ALTER TABLE {$db_prefix}attachments
  1108. ADD COLUMN id_folder tinyint(3) NOT NULL default '1';
  1109. ---#
  1110. ---# Adding file hash.
  1111. ALTER TABLE {$db_prefix}attachments
  1112. ADD COLUMN file_hash varchar(40) NOT NULL default '';
  1113. ---#
  1114. ---# Populate the attachment extension.
  1115. UPDATE {$db_prefix}attachments
  1116. SET fileext = LOWER(SUBSTRING(filename, 1 - (INSTR(REVERSE(filename), '.'))))
  1117. WHERE fileext = ''
  1118. AND INSTR(filename, '.')
  1119. AND attachment_type != 3;
  1120. ---#
  1121. ---# Updating thumbnail attachments JPG.
  1122. UPDATE {$db_prefix}attachments
  1123. SET fileext = 'jpg'
  1124. WHERE attachment_type = 3
  1125. AND fileext = ''
  1126. AND RIGHT(filename, 9) = 'JPG_thumb';
  1127. ---#
  1128. ---# Updating thumbnail attachments PNG.
  1129. UPDATE {$db_prefix}attachments
  1130. SET fileext = 'png'
  1131. WHERE attachment_type = 3
  1132. AND fileext = ''
  1133. AND RIGHT(filename, 9) = 'PNG_thumb';
  1134. ---#
  1135. ---# Calculating attachment mime types.
  1136. ---{
  1137. // Don't ever bother doing this twice.
  1138. if (@$modSettings['smfVersion'] < '2.0' || @$modSettings['smfVersion'] === '2.0 a')
  1139. {
  1140. $request = upgrade_query("
  1141. SELECT MAX(id_attach)
  1142. FROM {$db_prefix}attachments");
  1143. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  1144. $smcFunc['db_free_result']($request);
  1145. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  1146. $step_progress['name'] = 'Calculating MIME Types';
  1147. $step_progress['current'] = $_GET['a'];
  1148. if (!function_exists('getAttachmentFilename'))
  1149. {
  1150. function getAttachmentFilename($filename, $attachment_id)
  1151. {
  1152. global $modSettings;
  1153. $clean_name = strtr($filename, 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
  1154. $clean_name = strtr($clean_name, array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u'));
  1155. $clean_name = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $clean_name);
  1156. $enc_name = $attachment_id . '_' . strtr($clean_name, '.', '_') . md5($clean_name);
  1157. $clean_name = preg_replace('~\.[\.]+~', '.', $clean_name);
  1158. if ($attachment_id == false)
  1159. return $clean_name;
  1160. if (file_exists($modSettings['attachmentUploadDir'] . '/' . $enc_name))
  1161. $filename = $modSettings['attachmentUploadDir'] . '/' . $enc_name;
  1162. else
  1163. $filename = $modSettings['attachmentUploadDir'] . '/' . $clean_name;
  1164. return $filename;
  1165. }
  1166. }
  1167. $ext_updates = array();
  1168. // What headers are valid results for getimagesize?
  1169. $validTypes = array(
  1170. 1 => 'gif',
  1171. 2 => 'jpeg',
  1172. 3 => 'png',
  1173. 5 => 'psd',
  1174. 6 => 'bmp',
  1175. 7 => 'tiff',
  1176. 8 => 'tiff',
  1177. 9 => 'jpeg',
  1178. 14 => 'iff',
  1179. );
  1180. $is_done = false;
  1181. while (!$is_done)
  1182. {
  1183. nextSubStep($substep);
  1184. $request = upgrade_query("
  1185. SELECT id_attach, filename, fileext
  1186. FROM {$db_prefix}attachments
  1187. WHERE fileext != ''
  1188. AND mime_type = ''
  1189. LIMIT $_GET[a], 100");
  1190. // Finished?
  1191. if ($smcFunc['db_num_rows']($request) == 0)
  1192. $is_done = true;
  1193. while ($row = $smcFunc['db_fetch_assoc']($request))
  1194. {
  1195. $filename = getAttachmentFilename($row['filename'], $row['id_attach']);
  1196. if (!file_exists($filename))
  1197. continue;
  1198. // Is it an image?
  1199. $size = @getimagesize($filename);
  1200. // Nothing valid?
  1201. if (empty($size) || empty($size[0]))
  1202. continue;
  1203. // Got the mime?
  1204. elseif (!empty($size['mime']))
  1205. $mime = $size['mime'];
  1206. // Otherwise is it valid?
  1207. elseif (!isset($validTypes[$size[2]]))
  1208. continue;
  1209. else
  1210. $mime = 'image/' . $validTypes[$size[2]];
  1211. // Let's try keep updates to a minimum.
  1212. if (!isset($ext_updates[$row['fileext'] . $size['mime']]))
  1213. $ext_updates[$row['fileext'] . $size['mime']] = array(
  1214. 'fileext' => $row['fileext'],
  1215. 'mime' => $mime,
  1216. 'files' => array(),
  1217. );
  1218. $ext_updates[$row['fileext'] . $size['mime']]['files'][] = $row['id_attach'];
  1219. }
  1220. $smcFunc['db_free_result']($request);
  1221. // Do the updates?
  1222. foreach ($ext_updates as $key => $update)
  1223. {
  1224. upgrade_query("
  1225. UPDATE {$db_prefix}attachments
  1226. SET mime_type = '$update[mime]'
  1227. WHERE id_attach IN (" . implode(',', $update['files']) . ")");
  1228. // Remove it.
  1229. unset($ext_updates[$key]);
  1230. }
  1231. $_GET['a'] += 100;
  1232. $step_progress['current'] = $_GET['a'];
  1233. }
  1234. unset($_GET['a']);
  1235. }
  1236. ---}
  1237. ---#
  1238. /******************************************************************************/
  1239. --- Adding Post Moderation.
  1240. /******************************************************************************/
  1241. ---# Creating "approval_queue" table...
  1242. CREATE TABLE IF NOT EXISTS {$db_prefix}approval_queue (
  1243. id_msg int(10) unsigned NOT NULL default '0',
  1244. id_attach int(10) unsigned NOT NULL default '0',
  1245. id_event smallint(5) unsigned NOT NULL default '0'
  1246. ) ENGINE=MyISAM{$db_collation};
  1247. ---#
  1248. ---# Adding approved column to attachments table...
  1249. ALTER TABLE {$db_prefix}attachments
  1250. ADD approved tinyint(3) NOT NULL default '1';
  1251. ---#
  1252. ---# Adding approved column to messages table...
  1253. ALTER TABLE {$db_prefix}messages
  1254. ADD approved tinyint(3) NOT NULL default '1';
  1255. ALTER TABLE {$db_prefix}messages
  1256. ADD INDEX approved (approved);
  1257. ---#
  1258. ---# Adding unapproved count column to topics table...
  1259. ALTER TABLE {$db_prefix}topics
  1260. ADD unapproved_posts smallint(5) NOT NULL default '0';
  1261. ---#
  1262. ---# Adding approved column to topics table...
  1263. ALTER TABLE {$db_prefix}topics
  1264. ADD approved tinyint(3) NOT NULL default '1',
  1265. ADD INDEX approved (approved);
  1266. ---#
  1267. ---# Adding approved columns to boards table...
  1268. ALTER TABLE {$db_prefix}boards
  1269. ADD unapproved_posts smallint(5) NOT NULL default '0',
  1270. ADD unapproved_topics smallint(5) NOT NULL default '0';
  1271. ---#
  1272. ---# Adding post moderation permissions...
  1273. ---{
  1274. // We *cannot* do this twice!
  1275. if (@$modSettings['smfVersion'] < '2.0')
  1276. {
  1277. // Anyone who can currently edit posts we assume can approve them...
  1278. $request = upgrade_query("
  1279. SELECT id_group, id_board, add_deny, permission
  1280. FROM {$db_prefix}board_permissions
  1281. WHERE permission = 'modify_any'");
  1282. $inserts = array();
  1283. while ($row = smf_mysql_fetch_assoc($request))
  1284. {
  1285. $inserts[] = "($row[id_group], $row[id_board], 'approve_posts', $row[add_deny])";
  1286. }
  1287. smf_mysql_free_result($request);
  1288. if (!empty($inserts))
  1289. upgrade_query("
  1290. INSERT IGNORE INTO {$db_prefix}board_permissions
  1291. (id_group, id_board, permission, add_deny)
  1292. VALUES
  1293. " . implode(',', $inserts));
  1294. }
  1295. ---}
  1296. ---#
  1297. /******************************************************************************/
  1298. --- Upgrading the error log.
  1299. /******************************************************************************/
  1300. ---# Adding columns to log_errors table...
  1301. ALTER TABLE {$db_prefix}log_errors
  1302. ADD error_type char(15) NOT NULL default 'general';
  1303. ALTER TABLE {$db_prefix}log_errors
  1304. ADD file varchar(255) NOT NULL default '',
  1305. ADD line mediumint(8) unsigned NOT NULL default '0';
  1306. ---#
  1307. ---# Updating error log table...
  1308. ---{
  1309. $request = upgrade_query("
  1310. SELECT COUNT(*)
  1311. FROM {$db_prefix}log_errors");
  1312. list($totalActions) = smf_mysql_fetch_row($request);
  1313. smf_mysql_free_result($request);
  1314. $_GET['m'] = !empty($_GET['m']) ? (int) $_GET['m'] : '0';
  1315. $step_progress['total'] = $totalActions;
  1316. $step_progress['current'] = $_GET['m'];
  1317. while ($_GET['m'] < $totalActions)
  1318. {
  1319. nextSubStep($substep);
  1320. $request = upgrade_query("
  1321. SELECT id_error, message, file, line
  1322. FROM {$db_prefix}log_errors
  1323. LIMIT $_GET[m], 500");
  1324. while($row = smf_mysql_fetch_assoc($request))
  1325. {
  1326. preg_match('~<br />(%1\$s: )?([\w\. \\\\/\-_:]+)<br />(%2\$s: )?([\d]+)~', $row['message'], $matches);
  1327. if (!empty($matches[2]) && !empty($matches[4]) && empty($row['file']) && empty($row['line']))
  1328. {
  1329. $row['file'] = addslashes(str_replace('\\', '/', $matches[2]));
  1330. $row['line'] = (int) $matches[4];
  1331. $row['message'] = addslashes(preg_replace('~<br />(%1\$s: )?([\w\. \\\\/\-_:]+)<br />(%2\$s: )?([\d]+)~', '', $row['message']));
  1332. }
  1333. else
  1334. continue;
  1335. upgrade_query("
  1336. UPDATE {$db_prefix}log_errors
  1337. SET file = SUBSTRING('$row[file]', 1, 255),
  1338. line = $row[line],
  1339. message = SUBSTRING('$row[message]', 1, 65535)
  1340. WHERE id_error = $row[id_error]
  1341. LIMIT 1");
  1342. }
  1343. $_GET['m'] += 500;
  1344. $step_progress['current'] = $_GET['m'];
  1345. }
  1346. unset($_GET['m']);
  1347. ---}
  1348. ---#
  1349. /******************************************************************************/
  1350. --- Adding Scheduled Tasks Data.
  1351. /******************************************************************************/
  1352. ---# Creating Scheduled Task Table...
  1353. CREATE TABLE IF NOT EXISTS {$db_prefix}scheduled_tasks (
  1354. id_task smallint(5) NOT NULL auto_increment,
  1355. next_time int(10) NOT NULL default '0',
  1356. time_offset int(10) NOT NULL default '0',
  1357. time_regularity smallint(5) NOT NULL default '0',
  1358. time_unit varchar(1) NOT NULL default 'h',
  1359. disabled tinyint(3) NOT NULL default '0',
  1360. task varchar(24) NOT NULL default '',
  1361. PRIMARY KEY (id_task),
  1362. KEY next_time (next_time),
  1363. KEY disabled (disabled),
  1364. UNIQUE task (task)
  1365. ) ENGINE=MyISAM{$db_collation};
  1366. ---#
  1367. ---# Populating Scheduled Task Table...
  1368. INSERT IGNORE INTO {$db_prefix}scheduled_tasks
  1369. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  1370. VALUES
  1371. (0, 0, 2, 'h', 0, 'approval_notification'),
  1372. (0, 0, 7, 'd', 0, 'auto_optimize'),
  1373. (0, 60, 1, 'd', 0, 'daily_maintenance'),
  1374. (0, 0, 1, 'd', 0, 'daily_digest'),
  1375. (0, 0, 1, 'w', 0, 'weekly_digest'),
  1376. (0, 0, 1, 'd', 1, 'birthdayemails'),
  1377. (0, 120, 1, 'd', 0, 'paid_subscriptions');
  1378. ---#
  1379. ---# Adding the simple machines scheduled task.
  1380. ---{
  1381. // Randomise the time.
  1382. $randomTime = 82800 + rand(0, 86399);
  1383. upgrade_query("
  1384. INSERT IGNORE INTO {$db_prefix}scheduled_tasks
  1385. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  1386. VALUES
  1387. (0, {$randomTime}, 1, 'd', 0, 'fetchSMfiles')");
  1388. ---}
  1389. ---#
  1390. ---# Deleting old scheduled task items...
  1391. DELETE FROM {$db_prefix}scheduled_tasks
  1392. WHERE task = 'clean_cache';
  1393. ---#
  1394. ---# Moving auto optimise settings to scheduled task...
  1395. ---{
  1396. if (!isset($modSettings['next_task_time']) && isset($modSettings['autoOptLastOpt']))
  1397. {
  1398. // Try move over the regularity...
  1399. if (isset($modSettings['autoOptDatabase']))
  1400. {
  1401. $disabled = empty($modSettings['autoOptDatabase']) ? 1 : 0;
  1402. $regularity = $disabled ? 7 : $modSettings['autoOptDatabase'];
  1403. $next_time = $modSettings['autoOptLastOpt'] + 3600 * 24 * $modSettings['autoOptDatabase'];
  1404. // Update the task accordingly.
  1405. upgrade_query("
  1406. UPDATE {$db_prefix}scheduled_tasks
  1407. SET disabled = $disabled, time_regularity = $regularity, next_time = $next_time
  1408. WHERE task = 'auto_optimize'");
  1409. }
  1410. // Delete the old settings!
  1411. upgrade_query("
  1412. DELETE FROM {$db_prefix}settings
  1413. WHERE VARIABLE IN ('autoOptLastOpt', 'autoOptDatabase')");
  1414. }
  1415. ---}
  1416. ---#
  1417. ---# Creating Scheduled Task Log Table...
  1418. CREATE TABLE IF NOT EXISTS {$db_prefix}log_scheduled_tasks (
  1419. id_log mediumint(8) NOT NULL auto_increment,
  1420. id_task smallint(5) NOT NULL default '0',
  1421. time_run int(10) NOT NULL default '0',
  1422. time_taken float NOT NULL default '0',
  1423. PRIMARY KEY (id_log)
  1424. ) ENGINE=MyISAM{$db_collation};
  1425. ---#
  1426. ---# Adding new scheduled task setting...
  1427. ---{
  1428. if (!isset($modSettings['next_task_time']))
  1429. {
  1430. upgrade_query("
  1431. INSERT INTO {$db_prefix}settings
  1432. (variable, value)
  1433. VALUES
  1434. ('next_task_time', '0')");
  1435. }
  1436. ---}
  1437. ---#
  1438. ---# Setting the birthday email template if not set...
  1439. ---{
  1440. if (!isset($modSettings['birthday_email']))
  1441. {
  1442. upgrade_query("
  1443. INSERT INTO {$db_prefix}settings
  1444. (variable, value)
  1445. VALUES
  1446. ('birthday_email', 'happy_birthday')");
  1447. }
  1448. ---}
  1449. ---#
  1450. /******************************************************************************/
  1451. --- Adding permission profiles for boards.
  1452. /******************************************************************************/
  1453. ---# Creating "permission_profiles" table...
  1454. CREATE TABLE IF NOT EXISTS {$db_prefix}permission_profiles (
  1455. id_profile smallint(5) NOT NULL auto_increment,
  1456. profile_name varchar(255) NOT NULL default '',
  1457. PRIMARY KEY (id_profile)
  1458. ) ENGINE=MyISAM{$db_collation};
  1459. ---#
  1460. ---# Adding profile columns to boards table...
  1461. ALTER TABLE {$db_prefix}boards
  1462. ADD id_profile smallint(5) unsigned NOT NULL default '1' AFTER member_groups;
  1463. ---#
  1464. ---# Adding profile columns to board permission table...
  1465. ALTER TABLE {$db_prefix}board_permissions
  1466. ADD id_profile smallint(5) unsigned NOT NULL default '1' AFTER id_group;
  1467. ALTER TABLE {$db_prefix}board_permissions
  1468. DROP PRIMARY KEY;
  1469. ALTER TABLE {$db_prefix}board_permissions
  1470. ADD PRIMARY KEY (id_group, id_profile, permission);
  1471. ---#
  1472. ---# Cleaning up some 2.0 Beta 1 permission profile bits...
  1473. ---{
  1474. $request = upgrade_query("
  1475. SELECT id_profile
  1476. FROM {$db_prefix}permission_profiles
  1477. WHERE profile_name = ''");
  1478. $profiles = array();
  1479. while ($row = smf_mysql_fetch_assoc($request))
  1480. $profiles[] = $row['id_profile'];
  1481. smf_mysql_free_result($request);
  1482. if (!empty($profiles))
  1483. {
  1484. $request = upgrade_query("
  1485. SELECT id_profile, name
  1486. FROM {$db_prefix}boards
  1487. WHERE id_profile IN (" . implode(',', $profiles) . ")");
  1488. $done_ids = array();
  1489. while ($row = smf_mysql_fetch_assoc($request))
  1490. {
  1491. if (isset($done_ids[$row['id_profile']]))
  1492. continue;
  1493. $done_ids[$row['id_profile']] = true;
  1494. $row['name'] = smf_mysql_real_escape_string($row['name']);
  1495. upgrade_query("
  1496. UPDATE {$db_prefix}permission_profiles
  1497. SET profile_name = '$row[name]'
  1498. WHERE id_profile = $row[id_profile]");
  1499. }
  1500. smf_mysql_free_result($request);
  1501. }
  1502. ---}
  1503. ---#
  1504. ---# Migrating old board profiles to profile system
  1505. ---{
  1506. // Doing this twice would be awful!
  1507. $request = upgrade_query("
  1508. SELECT COUNT(*)
  1509. FROM {$db_prefix}permission_profiles");
  1510. list ($profileCount) = smf_mysql_fetch_row($request);
  1511. smf_mysql_free_result($request);
  1512. if ($profileCount == 0)
  1513. {
  1514. // Everything starts off invalid.
  1515. upgrade_query("
  1516. UPDATE {$db_prefix}board_permissions
  1517. SET id_profile = 0");
  1518. // Insert a boat load of default profile permissions.
  1519. upgrade_query("
  1520. INSERT INTO {$db_prefix}permission_profiles
  1521. (id_profile, profile_name)
  1522. VALUES
  1523. (1, 'default'),
  1524. (2, 'no_polls'),
  1525. (3, 'reply_only'),
  1526. (4, 'read_only')");
  1527. // Update the default permissions, this is easy!
  1528. upgrade_query("
  1529. UPDATE {$db_prefix}board_permissions
  1530. SET id_profile = 1
  1531. WHERE id_board = 0");
  1532. // Load all the other permissions
  1533. $request = upgrade_query("
  1534. SELECT id_board, id_group, permission, add_deny
  1535. FROM {$db_prefix}board_permissions
  1536. WHERE id_profile = 0");
  1537. $all_perms = array();
  1538. while ($row = smf_mysql_fetch_assoc($request))
  1539. $all_perms[$row['id_board']][$row['id_group']][$row['permission']] = $row['add_deny'];
  1540. smf_mysql_free_result($request);
  1541. // Now we have the profile profiles for this installation. We now need to go through each board and work out what the permission profile should be!
  1542. $request = upgrade_query("
  1543. SELECT id_board, name, permission_mode
  1544. FROM {$db_prefix}boards");
  1545. $board_updates = array();
  1546. while ($row = smf_mysql_fetch_assoc($request))
  1547. {
  1548. $row['name'] = addslashes($row['name']);
  1549. // Is it a truely local permission board? If so this is a new profile!
  1550. if ($row['permission_mode'] == 1)
  1551. {
  1552. // I know we could cache this, but I think we need to be practical - this is slow but guaranteed to work.
  1553. upgrade_query("
  1554. INSERT INTO {$db_prefix}permission_profiles
  1555. (profile_name)
  1556. VALUES
  1557. ('$row[name]')");
  1558. $board_updates[smf_mysql_insert_id()][] = $row['id_board'];
  1559. }
  1560. // Otherwise, dear god, this is an old school "simple" permission...
  1561. elseif ($row['permission_mode'] > 1 && $row['permission_mode'] < 5)
  1562. {
  1563. $board_updates[$row['permission_mode']][] = $row['id_board'];
  1564. }
  1565. // Otherwise this is easy. It becomes default.
  1566. else
  1567. $board_updates[1][] = $row['id_board'];
  1568. }
  1569. smf_mysql_free_result($request);
  1570. // Update the board tables.
  1571. foreach ($board_updates as $profile => $boards)
  1572. {
  1573. if (empty($boards))
  1574. continue;
  1575. $boards = implode(',', $boards);
  1576. upgrade_query("
  1577. UPDATE {$db_prefix}boards
  1578. SET id_profile = $profile
  1579. WHERE id_board IN ($boards)");
  1580. // If it's a custom profile then update this too.
  1581. if ($profile > 4)
  1582. upgrade_query("
  1583. UPDATE {$db_prefix}board_permissions
  1584. SET id_profile = $profile
  1585. WHERE id_board IN ($boards)
  1586. AND id_profile = 0");
  1587. }
  1588. // Just in case we have any random permissions that didn't have boards.
  1589. upgrade_query("
  1590. DELETE FROM {$db_prefix}board_permissions
  1591. WHERE id_profile = 0");
  1592. }
  1593. ---}
  1594. ---#
  1595. ---# Removing old board permissions column...
  1596. ALTER TABLE {$db_prefix}board_permissions
  1597. DROP COLUMN id_board;
  1598. ---#
  1599. ---# Check the predefined profiles all have the right permissions.
  1600. ---{
  1601. // What are all the permissions people can have.
  1602. $mod_permissions = array(
  1603. 'moderate_board', 'post_new', 'post_reply_own', 'post_reply_any', 'poll_post', 'poll_add_any',
  1604. 'poll_remove_any', 'poll_view', 'poll_vote', 'poll_lock_any', 'poll_edit_any', 'report_any',
  1605. 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own', 'make_sticky',
  1606. 'lock_any', 'remove_any', 'move_any', 'merge_any', 'split_any', 'delete_any', 'modify_any', 'approve_posts',
  1607. 'post_attachment', 'view_attachments', 'post_unapproved_replies_any', 'post_unapproved_replies_own',
  1608. 'post_unapproved_attachments', 'post_unapproved_topics',
  1609. );
  1610. $no_poll_reg = array(
  1611. 'post_new', 'post_reply_own', 'post_reply_any', 'poll_view', 'poll_vote', 'report_any',
  1612. 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own',
  1613. 'post_attachment', 'view_attachments', 'remove_own', 'post_unapproved_replies_any', 'post_unapproved_replies_own',
  1614. 'post_unapproved_attachments', 'post_unapproved_topics',
  1615. );
  1616. $reply_only_reg = array(
  1617. 'post_reply_own', 'post_reply_any', 'poll_view', 'poll_vote', 'report_any',
  1618. 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own',
  1619. 'post_attachment', 'view_attachments', 'remove_own', 'post_unapproved_replies_any', 'post_unapproved_replies_own',
  1620. 'post_unapproved_attachments',
  1621. );
  1622. $read_only_reg = array(
  1623. 'poll_view', 'poll_vote', 'report_any', 'send_topic', 'mark_any_notify', 'mark_notify', 'view_attachments',
  1624. );
  1625. // Clear all the current predefined profiles.
  1626. upgrade_query("
  1627. DELETE FROM {$db_prefix}board_permissions
  1628. WHERE id_profile IN (2,3,4)");
  1629. // Get all the membergroups - cheating to use the fact id_group = 1 exists to get a group of 0.
  1630. $request = upgrade_query("
  1631. SELECT IF(id_group = 1, 0, id_group) AS id_group
  1632. FROM {$db_prefix}membergroups
  1633. WHERE id_group != 0
  1634. AND min_posts = -1");
  1635. $inserts = array();
  1636. while ($row = smf_mysql_fetch_assoc($request))
  1637. {
  1638. if ($row['id_group'] == 2 || $row['id_group'] == 3)
  1639. {
  1640. foreach ($mod_permissions as $permission)
  1641. {
  1642. $inserts[] = "($row[id_group], 2, '$permission')";
  1643. $inserts[] = "($row[id_group], 3, '$permission')";
  1644. $inserts[] = "($row[id_group], 4, '$permission')";
  1645. }
  1646. }
  1647. else
  1648. {
  1649. foreach ($no_poll_reg as $permission)
  1650. $inserts[] = "($row[id_group], 2, '$permission')";
  1651. foreach ($reply_only_reg as $permission)
  1652. $inserts[] = "($row[id_group], 3, '$permission')";
  1653. foreach ($read_only_reg as $permission)
  1654. $inserts[] = "($row[id_group], 4, '$permission')";
  1655. }
  1656. }
  1657. smf_mysql_free_result($request);
  1658. upgrade_query("
  1659. INSERT INTO {$db_prefix}board_permissions
  1660. (id_group, id_profile, permission)
  1661. VALUES (-1, 2, 'poll_view'),
  1662. (-1, 3, 'poll_view'),
  1663. (-1, 4, 'poll_view'),
  1664. " . implode(', ', $inserts));
  1665. ---}
  1666. ---#
  1667. ---# Adding inherited permissions...
  1668. ALTER TABLE {$db_prefix}membergroups
  1669. ADD id_parent smallint(5) NOT NULL default '-2';
  1670. ---#
  1671. ---# Make sure admins and moderators don't inherit...
  1672. UPDATE {$db_prefix}membergroups
  1673. SET id_parent = -2
  1674. WHERE id_group = 1
  1675. OR id_group = 3;
  1676. ---#
  1677. ---# Deleting old permission settings...
  1678. DELETE FROM {$db_prefix}settings
  1679. WHERE VARIABLE IN ('permission_enable_by_board', 'autoOptDatabase');
  1680. ---#
  1681. ---# Removing old permission_mode column...
  1682. ALTER TABLE {$db_prefix}boards
  1683. DROP COLUMN permission_mode;
  1684. ---#
  1685. /******************************************************************************/
  1686. --- Adding Some Additional Functionality.
  1687. /******************************************************************************/
  1688. ---# Adding column to hold the boards being ignored ...
  1689. ALTER TABLE {$db_prefix}members
  1690. ADD ignore_boards text NOT NULL;
  1691. ---#
  1692. ---# Purge flood control ...
  1693. DELETE FROM {$db_prefix}log_floodcontrol;
  1694. ---#
  1695. ---# Adding advanced flood control ...
  1696. ALTER TABLE {$db_prefix}log_floodcontrol
  1697. ADD log_type varchar(8) NOT NULL default 'post';
  1698. ---#
  1699. ---# Sorting out flood control keys ...
  1700. ALTER TABLE {$db_prefix}log_floodcontrol
  1701. DROP PRIMARY KEY,
  1702. ADD PRIMARY KEY (ip(16), log_type(8));
  1703. ---#
  1704. ---# Adding guest voting ...
  1705. ALTER TABLE {$db_prefix}polls
  1706. ADD guest_vote tinyint(3) NOT NULL default '0';
  1707. DELETE FROM {$db_prefix}log_polls
  1708. WHERE id_member < 0;
  1709. ALTER TABLE {$db_prefix}log_polls
  1710. DROP PRIMARY KEY;
  1711. ALTER TABLE {$db_prefix}log_polls
  1712. ADD INDEX id_poll (id_poll, id_member, id_choice);
  1713. ---#
  1714. ---# Implementing admin feature toggles.
  1715. ---{
  1716. if (!isset($modSettings['admin_features']))
  1717. {
  1718. // Work out what they used to have enabled.
  1719. $enabled_features = array('rg');
  1720. if (!empty($modSettings['cal_enabled']))
  1721. $enabled_features[] = 'cd';
  1722. if (!empty($modSettings['karmaMode']))
  1723. $enabled_features[] = 'k';
  1724. if (!empty($modSettings['modlog_enabled']))
  1725. $enabled_features[] = 'ml';
  1726. if (!empty($modSettings['paid_enabled']))
  1727. $enabled_features[] = 'ps';
  1728. $enabled_features = implode(',', $enabled_features);
  1729. upgrade_query("
  1730. INSERT INTO {$db_prefix}settings
  1731. (variable, value)
  1732. VALUES
  1733. ('admin_features', '$enabled_features')");
  1734. }
  1735. ---}
  1736. ---#
  1737. ---# Adding advanced password brute force protection to "members" table...
  1738. ALTER TABLE {$db_prefix}members
  1739. ADD passwd_flood varchar(12) NOT NULL default '';
  1740. ---#
  1741. /******************************************************************************/
  1742. --- Adding some columns to moderation log
  1743. /******************************************************************************/
  1744. ---# Add the columns and the keys to log_actions ...
  1745. ALTER TABLE {$db_prefix}log_actions
  1746. ADD id_board smallint(5) unsigned NOT NULL default '0',
  1747. ADD id_topic mediumint(8) unsigned NOT NULL default '0',
  1748. ADD id_msg int(10) unsigned NOT NULL default '0',
  1749. ADD KEY id_board (id_board),
  1750. ADD KEY id_msg (id_msg);
  1751. ---#
  1752. ---# Add the user log...
  1753. ALTER TABLE {$db_prefix}log_actions
  1754. ADD id_log tinyint(3) unsigned NOT NULL default '1',
  1755. ADD KEY id_log (id_log);
  1756. ---#
  1757. ---# Update the information already in log_actions
  1758. ---{
  1759. $request = upgrade_query("
  1760. SELECT COUNT(*)
  1761. FROM {$db_prefix}log_actions");
  1762. list($totalActions) = smf_mysql_fetch_row($request);
  1763. smf_mysql_free_result($request);
  1764. $_GET['m'] = !empty($_GET['m']) ? (int) $_GET['m'] : '0';
  1765. $step_progress['total'] = $totalActions;
  1766. $step_progress['current'] = $_GET['m'];
  1767. while ($_GET['m'] < $totalActions)
  1768. {
  1769. nextSubStep($substep);
  1770. $mrequest = upgrade_query("
  1771. SELECT id_action, extra, id_board, id_topic, id_msg
  1772. FROM {$db_prefix}log_actions
  1773. LIMIT $_GET[m], 500");
  1774. while ($row = smf_mysql_fetch_assoc($mrequest))
  1775. {
  1776. if (!empty($row['id_board']) || !empty($row['id_topic']) || !empty($row['id_msg']))
  1777. continue;
  1778. $row['extra'] = @unserialize($row['extra']);
  1779. // Corrupt?
  1780. $row['extra'] = is_array($row['extra']) ? $row['extra'] : array();
  1781. if (!empty($row['extra']['board']))
  1782. {
  1783. $board_id = (int) $row['extra']['board'];
  1784. unset($row['extra']['board']);
  1785. }
  1786. else
  1787. $board_id = '0';
  1788. if (!empty($row['extra']['board_to']) && empty($board_id))
  1789. {
  1790. $board_id = (int) $row['extra']['board_to'];
  1791. unset($row['extra']['board_to']);
  1792. }
  1793. if (!empty($row['extra']['topic']))
  1794. {
  1795. $topic_id = (int) $row['extra']['topic'];
  1796. unset($row['extra']['topic']);
  1797. if (empty($board_id))
  1798. {
  1799. $trequest = upgrade_query("
  1800. SELECT id_board
  1801. FROM {$db_prefix}topics
  1802. WHERE id_topic=$topic_id
  1803. LIMIT 1");
  1804. if (smf_mysql_num_rows($trequest))
  1805. list($board_id) = smf_mysql_fetch_row($trequest);
  1806. smf_mysql_free_result($trequest);
  1807. }
  1808. }
  1809. else
  1810. $topic_id = '0';
  1811. if(!empty($row['extra']['message']))
  1812. {
  1813. $msg_id = (int) $row['extra']['message'];
  1814. unset($row['extra']['message']);
  1815. if (empty($topic_id) || empty($board_id))
  1816. {
  1817. $trequest = upgrade_query("
  1818. SELECT id_board, id_topic
  1819. FROM {$db_prefix}messages
  1820. WHERE id_msg=$msg_id
  1821. LIMIT 1");
  1822. if (smf_mysql_num_rows($trequest))
  1823. list($board_id, $topic_id) = smf_mysql_fetch_row($trequest);
  1824. smf_mysql_free_result($trequest);
  1825. }
  1826. }
  1827. else
  1828. $msg_id = '0';
  1829. $row['extra'] = addslashes(serialize($row['extra']));
  1830. upgrade_query("UPDATE {$db_prefix}log_actions SET id_board=$board_id, id_topic=$topic_id, id_msg=$msg_id, extra='$row[extra]' WHERE id_action=$row[id_action]");
  1831. }
  1832. $_GET['m'] += 500;
  1833. $step_progress['current'] = $_GET['m'];
  1834. }
  1835. unset($_GET['m']);
  1836. ---}
  1837. ---#
  1838. /******************************************************************************/
  1839. --- Create a repository for the javascript files from Simple Machines...
  1840. /******************************************************************************/
  1841. ---# Creating repository table ...
  1842. CREATE TABLE IF NOT EXISTS {$db_prefix}admin_info_files (
  1843. id_file tinyint(4) unsigned NOT NULL auto_increment,
  1844. filename varchar(255) NOT NULL default '',
  1845. path varchar(255) NOT NULL default '',
  1846. parameters varchar(255) NOT NULL default '',
  1847. data text NOT NULL,
  1848. filetype varchar(255) NOT NULL default '',
  1849. PRIMARY KEY (id_file),
  1850. KEY filename (filename(30))
  1851. ) ENGINE=MyISAM{$db_collation};
  1852. ---#
  1853. ---# Add in the files to get from Simple Machines...
  1854. INSERT IGNORE INTO {$db_prefix}admin_info_files
  1855. (id_file, filename, path, parameters)
  1856. VALUES
  1857. (1, 'current-version.js', '/smf/', 'version=%3$s'),
  1858. (2, 'detailed-version.js', '/smf/', 'language=%1$s&version=%3$s'),
  1859. (3, 'latest-news.js', '/smf/', 'language=%1$s&format=%2$s'),
  1860. (4, 'latest-packages.js', '/smf/', 'language=%1$s&version=%3$s'),
  1861. (5, 'latest-smileys.js', '/smf/', 'language=%1$s&version=%3$s'),
  1862. (6, 'latest-support.js', '/smf/', 'language=%1$s&version=%3$s'),
  1863. (7, 'latest-themes.js', '/smf/', 'language=%1$s&version=%3$s');
  1864. ---#
  1865. ---# Ensure that the table has the filetype column
  1866. ALTER TABLE {$db_prefix}admin_info_files
  1867. ADD filetype varchar(255) NOT NULL default '';
  1868. ---#
  1869. ---# Set the filetype for the files
  1870. UPDATE {$db_prefix}admin_info_files
  1871. SET filetype='text/javascript'
  1872. WHERE id_file IN (1,2,3,4,5,6,7);
  1873. ---#
  1874. ---# Ensure that the files from Simple Machines get updated
  1875. UPDATE {$db_prefix}scheduled_tasks
  1876. SET next_time = UNIX_TIMESTAMP()
  1877. WHERE id_task = 7
  1878. LIMIT 1;
  1879. ---#
  1880. /******************************************************************************/
  1881. --- Adding new personal messaging functionality.
  1882. /******************************************************************************/
  1883. ---# Adding personal message rules table...
  1884. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_rules (
  1885. id_rule int(10) unsigned NOT NULL auto_increment,
  1886. id_member int(10) unsigned NOT NULL default '0',
  1887. rule_name varchar(60) NOT NULL,
  1888. criteria text NOT NULL,
  1889. actions text NOT NULL,
  1890. delete_pm tinyint(3) unsigned NOT NULL default '0',
  1891. is_or tinyint(3) unsigned NOT NULL default '0',
  1892. PRIMARY KEY (id_rule),
  1893. KEY id_member (id_member),
  1894. KEY delete_pm (delete_pm)
  1895. ) ENGINE=MyISAM{$db_collation};
  1896. ---#
  1897. ---# Adding new message status columns...
  1898. ALTER TABLE {$db_prefix}members
  1899. ADD COLUMN new_pm tinyint(3) NOT NULL default '0';
  1900. ALTER TABLE {$db_prefix}members
  1901. ADD COLUMN pm_prefs mediumint(8) NOT NULL default '0';
  1902. ALTER TABLE {$db_prefix}pm_recipients
  1903. ADD COLUMN is_new tinyint(3) NOT NULL default '0';
  1904. ---#
  1905. ---# Set the new status to be correct....
  1906. ---{
  1907. // Don't do this twice!
  1908. if (@$modSettings['smfVersion'] < '2.0')
  1909. {
  1910. // Set all unread messages as new.
  1911. upgrade_query("
  1912. UPDATE {$db_prefix}pm_recipients
  1913. SET is_new = 1
  1914. WHERE is_read = 0");
  1915. // Also set members to have a new pm if they have any unread.
  1916. upgrade_query("
  1917. UPDATE {$db_prefix}members
  1918. SET new_pm = 1
  1919. WHERE unread_messages > 0");
  1920. }
  1921. ---}
  1922. ---#
  1923. ---# Adding personal message tracking column...
  1924. ALTER TABLE {$db_prefix}personal_messages
  1925. ADD id_pm_head int(10) unsigned default '0' NOT NULL AFTER id_pm,
  1926. ADD INDEX id_pm_head (id_pm_head);
  1927. ---#
  1928. ---# Adding personal message tracking column...
  1929. UPDATE {$db_prefix}personal_messages
  1930. SET id_pm_head = id_pm
  1931. WHERE id_pm_head = 0;
  1932. ---#
  1933. /******************************************************************************/
  1934. --- Adding Open ID support.
  1935. /******************************************************************************/
  1936. ---# Adding Open ID Assocation table...
  1937. CREATE TABLE IF NOT EXISTS {$db_prefix}openid_assoc (
  1938. server_url text NOT NULL,
  1939. handle varchar(255) NOT NULL default '',
  1940. secret text NOT NULL,
  1941. issued int(10) NOT NULL default '0',
  1942. expires int(10) NOT NULL default '0',
  1943. assoc_type varchar(64) NOT NULL,
  1944. PRIMARY KEY (server_url(125), handle(125)),
  1945. KEY expires (expires)
  1946. ) ENGINE=MyISAM{$db_collation};
  1947. ---#
  1948. ---# Adding column to hold Open ID URL...
  1949. ALTER TABLE {$db_prefix}members
  1950. ADD openid_uri text NOT NULL;
  1951. ---#
  1952. /******************************************************************************/
  1953. --- Adding paid subscriptions.
  1954. /******************************************************************************/
  1955. ---# Creating subscriptions table...
  1956. CREATE TABLE IF NOT EXISTS {$db_prefix}subscriptions(
  1957. id_subscribe mediumint(8) unsigned NOT NULL auto_increment,
  1958. name varchar(60) NOT NULL default '',
  1959. description varchar(255) NOT NULL default '',
  1960. cost text NOT NULL,
  1961. length varchar(6) NOT NULL default '',
  1962. id_group smallint(5) NOT NULL default '0',
  1963. add_groups varchar(40) NOT NULL default '',
  1964. active tinyint(3) NOT NULL default '1',
  1965. repeatable tinyint(3) NOT NULL default '0',
  1966. allow_partial tinyint(3) NOT NULL default '0',
  1967. reminder tinyint(3) NOT NULL default '0',
  1968. email_complete text NOT NULL,
  1969. PRIMARY KEY (id_subscribe),
  1970. KEY active (active)
  1971. ) ENGINE=MyISAM{$db_collation};
  1972. ---#
  1973. ---# Creating log_subscribed table...
  1974. CREATE TABLE IF NOT EXISTS {$db_prefix}log_subscribed(
  1975. id_sublog int(10) unsigned NOT NULL auto_increment,
  1976. id_subscribe mediumint(8) unsigned NOT NULL default '0',
  1977. id_member int(10) NOT NULL default '0',
  1978. old_id_group smallint(5) NOT NULL default '0',
  1979. start_time int(10) NOT NULL default '0',
  1980. end_time int(10) NOT NULL default '0',
  1981. status tinyint(3) NOT NULL default '0',
  1982. payments_pending tinyint(3) NOT NULL default '0',
  1983. pending_details text NOT NULL,
  1984. reminder_sent tinyint(3) NOT NULL default '0',
  1985. vendor_ref varchar(255) NOT NULL default '',
  1986. PRIMARY KEY (id_sublog),
  1987. UNIQUE KEY id_subscribe (id_subscribe, id_member),
  1988. KEY end_time (end_time),
  1989. KEY reminder_sent (reminder_sent),
  1990. KEY payments_pending (payments_pending),
  1991. KEY id_member (id_member)
  1992. ) ENGINE=MyISAM{$db_collation};
  1993. ---#
  1994. ---# Clean up any pre-2.0 mod settings.
  1995. UPDATE {$db_prefix}settings
  1996. SET variable = 'paid_currency_code'
  1997. WHERE variable = 'currency_code';
  1998. UPDATE {$db_prefix}settings
  1999. SET variable = 'paid_currency_symbol'
  2000. WHERE variable = 'currency_symbol';
  2001. DELETE FROM {$db_prefix}settings
  2002. WHERE variable = 'currency_code'
  2003. OR variable = 'currency_symbol';
  2004. ---#
  2005. ---# Clean up any pre-2.0 mod settings (part 2).
  2006. ---{
  2007. $request = upgrade_query("
  2008. SHOW COLUMNS
  2009. FROM {$db_prefix}subscriptions");
  2010. $new_cols = array('repeatable', 'reminder', 'email_complete', 'allow_partial');
  2011. $new_cols = array_flip($new_cols);
  2012. while ($request && $row = smf_mysql_fetch_row($request))
  2013. {
  2014. $row[0] = strtolower($row[0]);
  2015. if (isset($new_cols[$row[0]]))
  2016. unset($new_cols[$row[0]]);
  2017. }
  2018. if ($request)
  2019. smf_mysql_free_result($request);
  2020. if (isset($new_cols['repeatable']))
  2021. upgrade_query("
  2022. ALTER TABLE {$db_prefix}subscriptions
  2023. ADD COLUMN Repeatable tinyint(3) NOT NULL default '0'");
  2024. if (isset($new_cols['reminder']))
  2025. upgrade_query("
  2026. ALTER TABLE {$db_prefix}subscriptions
  2027. ADD COLUMN reminder tinyint(3) NOT NULL default '0'");
  2028. if (isset($new_cols['email_complete']))
  2029. upgrade_query("
  2030. ALTER TABLE {$db_prefix}subscriptions
  2031. ADD COLUMN email_complete text NOT NULL");
  2032. if (isset($new_cols['allowpartial']))
  2033. upgrade_query("
  2034. ALTER TABLE {$db_prefix}subscriptions
  2035. ADD COLUMN allow_partial tinyint(3) NOT NULL default '0'");
  2036. $request = upgrade_query("
  2037. SHOW COLUMNS
  2038. FROM {$db_prefix}log_subscribed");
  2039. $new_cols = array('reminder_sent', 'vendor_ref', 'payments_pending', 'pending_details');
  2040. $new_cols = array_flip($new_cols);
  2041. while ($request && $row = smf_mysql_fetch_row($request))
  2042. {
  2043. if (isset($new_cols[$row[0]]))
  2044. unset($new_cols[$row[0]]);
  2045. }
  2046. if ($request)
  2047. smf_mysql_free_result($request);
  2048. if (isset($new_cols['reminder_sent']))
  2049. upgrade_query("
  2050. ALTER TABLE {$db_prefix}log_subscribed
  2051. ADD COLUMN reminder_sent tinyint(3) NOT NULL default '0'");
  2052. if (isset($new_cols['vendor_ref']))
  2053. upgrade_query("
  2054. ALTER TABLE {$db_prefix}log_subscribed
  2055. ADD COLUMN vendor_ref varchar(255) NOT NULL default ''");
  2056. if (isset($new_cols['payments_pending']))
  2057. upgrade_query("
  2058. ALTER TABLE {$db_prefix}log_subscribed
  2059. ADD COLUMN payments_pending tinyint(3) NOT NULL default '0'");
  2060. if (isset($new_cols['pending_details']))
  2061. {
  2062. upgrade_query("
  2063. UPDATE {$db_prefix}log_subscribed
  2064. SET status = 0
  2065. WHERE status = 1");
  2066. upgrade_query("
  2067. UPDATE {$db_prefix}log_subscribed
  2068. SET status = 1
  2069. WHERE status = 2");
  2070. upgrade_query("
  2071. ALTER TABLE {$db_prefix}log_subscribed
  2072. ADD COLUMN pending_details text NOT NULL");
  2073. }
  2074. ---}
  2075. ---#
  2076. ---# Confirming paid subscription keys are in place ...
  2077. ALTER TABLE {$db_prefix}log_subscribed
  2078. ADD KEY reminder_sent (reminder_sent),
  2079. ADD KEY end_time (end_time),
  2080. ADD KEY payments_pending (payments_pending),
  2081. ADD KEY status (status);
  2082. ---#
  2083. /******************************************************************************/
  2084. --- Adding weekly maintenance task.
  2085. /******************************************************************************/
  2086. ---# Adding scheduled task...
  2087. INSERT IGNORE INTO {$db_prefix}scheduled_tasks (next_time, time_offset, time_regularity, time_unit, disabled, task) VALUES (0, 0, 1, 'w', 0, 'weekly_maintenance');
  2088. ---#
  2089. /******************************************************************************/
  2090. --- Adding log pruning.
  2091. /******************************************************************************/
  2092. ---# Adding pruning option...
  2093. INSERT IGNORE INTO {$db_prefix}settings (variable, value) VALUES ('pruningOptions', '30,180,180,180,30,0');
  2094. ---#
  2095. /******************************************************************************/
  2096. --- Adding restore topic from recycle.
  2097. /******************************************************************************/
  2098. ---# Adding restore from recycle feature...
  2099. ALTER TABLE {$db_prefix}topics
  2100. ADD COLUMN id_previous_board smallint(5) NOT NULL default '0',
  2101. ADD COLUMN id_previous_topic mediumint(8) NOT NULL default '0';
  2102. ---#
  2103. /******************************************************************************/
  2104. --- Providing more room for apf options.
  2105. /******************************************************************************/
  2106. ---# Changing field_options column to a larger field type...
  2107. ALTER TABLE {$db_prefix}custom_fields
  2108. CHANGE field_options field_options text NOT NULL;
  2109. ---#
  2110. /******************************************************************************/
  2111. --- Providing more room for ignoring boards.
  2112. /******************************************************************************/
  2113. ---# Changing ignore_boards column to a larger field type...
  2114. ALTER TABLE {$db_prefix}members
  2115. CHANGE ignore_boards ignore_boards text NOT NULL;
  2116. ---#
  2117. /******************************************************************************/
  2118. --- Allow for longer calendar event/holiday titles.
  2119. /******************************************************************************/
  2120. ---# Changing event title column to a larger field type...
  2121. ALTER TABLE {$db_prefix}calendar
  2122. CHANGE title title varchar(255) NOT NULL default '';
  2123. ---#
  2124. ---# Changing holidays title column to a larger field type...
  2125. ALTER TABLE {$db_prefix}calendar_holidays
  2126. CHANGE title title varchar(255) NOT NULL default '';
  2127. ---#
  2128. /******************************************************************************/
  2129. --- Adding extra columns to polls.
  2130. /******************************************************************************/
  2131. ---# Adding reset poll timestamp and guest voters counter...
  2132. ALTER TABLE {$db_prefix}polls
  2133. ADD COLUMN reset_poll int(10) unsigned NOT NULL default '0' AFTER guest_vote,
  2134. ADD COLUMN num_guest_voters int(10) unsigned NOT NULL default '0' AFTER guest_vote;
  2135. ---#
  2136. ---# Fixing guest voter tallys on existing polls...
  2137. ---{
  2138. $request = upgrade_query("
  2139. SELECT p.id_poll, count(lp.id_member) as guest_voters
  2140. FROM {$db_prefix}polls AS p
  2141. LEFT JOIN {$db_prefix}log_polls AS lp ON (lp.id_poll = p.id_poll AND lp.id_member = 0)
  2142. WHERE lp.id_member = 0
  2143. AND p.num_guest_voters = 0
  2144. GROUP BY p.id_poll");
  2145. while ($request && $row = $smcFunc['db_fetch_assoc']($request))
  2146. upgrade_query("
  2147. UPDATE {$db_prefix}polls
  2148. SET num_guest_voters = ". $row['guest_voters']. "
  2149. WHERE id_poll = " . $row['id_poll'] . "
  2150. AND num_guest_voters = 0");
  2151. ---}
  2152. ---#
  2153. /******************************************************************************/
  2154. --- Changing all tinytext columns to varchar(255).
  2155. /******************************************************************************/
  2156. ---# Changing all tinytext columns to varchar(255)...
  2157. ---{
  2158. // The array holding all the changes.
  2159. $nameChanges = array(
  2160. 'admin_info_files' => array(
  2161. 'filename' => 'filename filename varchar(255) NOT NULL default \'\'',
  2162. 'path' => 'path path varchar(255) NOT NULL default \'\'',
  2163. 'parameters' => 'parameters parameters varchar(255) NOT NULL default \'\'',
  2164. 'filetype' => 'filetype filetype varchar(255) NOT NULL default \'\'',
  2165. ),
  2166. 'attachments' => array(
  2167. 'filename' => 'filename filename varchar(255) NOT NULL default \'\'',
  2168. ),
  2169. 'ban_groups' => array(
  2170. 'reason' => 'reason reason varchar(255) NOT NULL default \'\'',
  2171. ),
  2172. 'ban_items' => array(
  2173. 'hostname' => 'hostname hostname varchar(255) NOT NULL default \'\'',
  2174. 'email_address' => 'email_address email_address varchar(255) NOT NULL default \'\'',
  2175. ),
  2176. 'boards' => array(
  2177. 'name' => 'name name varchar(255) NOT NULL default \'\'',
  2178. ),
  2179. 'categories' => array(
  2180. 'name' => 'name name varchar(255) NOT NULL default \'\'',
  2181. ),
  2182. 'custom_fields' => array(
  2183. 'field_desc' => 'field_desc field_desc varchar(255) NOT NULL default \'\'',
  2184. 'mask' => 'mask mask varchar(255) NOT NULL default \'\'',
  2185. 'default_value' => 'default_value default_value varchar(255) NOT NULL default \'\'',
  2186. ),
  2187. 'log_banned' => array(
  2188. 'email' => 'email email varchar(255) NOT NULL default \'\'',
  2189. ),
  2190. 'log_comments' => array(
  2191. 'recipient_name' => 'recipient_name recipient_name varchar(255) NOT NULL default \'\'',
  2192. ),
  2193. 'log_errors' => array(
  2194. 'file' => 'file file varchar(255) NOT NULL default \'\'',
  2195. ),
  2196. 'log_member_notices' => array(
  2197. 'subject' => 'subject subject varchar(255) NOT NULL default \'\'',
  2198. ),
  2199. 'log_packages' => array(
  2200. 'filename' => 'filename filename varchar(255) NOT NULL default \'\'',
  2201. 'package_id' => 'package_id package_id varchar(255) NOT NULL default \'\'',
  2202. 'name' => 'name name varchar(255) NOT NULL default \'\'',
  2203. 'version' => 'version version varchar(255) NOT NULL default \'\'',
  2204. 'member_installed' => 'member_installed member_installed varchar(255) NOT NULL default \'\'',
  2205. 'member_removed' => 'member_removed member_removed varchar(255) NOT NULL default \'\'',
  2206. 'themes_installed' => 'themes_installed themes_installed varchar(255) NOT NULL default \'\'',
  2207. ),
  2208. 'log_reported' => array(
  2209. 'membername' => 'membername membername varchar(255) NOT NULL default \'\'',
  2210. 'subject' => 'subject subject varchar(255) NOT NULL default \'\'',
  2211. ),
  2212. 'log_reported_comments' => array(
  2213. 'membername' => 'membername membername varchar(255) NOT NULL default \'\'',
  2214. 'comment' => 'comment comment varchar(255) NOT NULL default \'\'',
  2215. ),
  2216. 'log_spider_hits' => array(
  2217. 'url' => 'url url varchar(255) NOT NULL default \'\'',
  2218. ),
  2219. 'log_subscribed' => array(
  2220. 'vendor_ref' => 'vendor_ref vendor_ref varchar(255) NOT NULL default \'\'',
  2221. ),
  2222. 'mail_queue' => array(
  2223. 'recipient' => 'recipient recipient varchar(255) NOT NULL default \'\'',
  2224. 'subject' => 'subject subject varchar(255) NOT NULL default \'\'',
  2225. ),
  2226. 'membergroups' => array(
  2227. 'stars' => 'stars stars varchar(255) NOT NULL default \'\'',
  2228. ),
  2229. 'members' => array(
  2230. 'lngfile' => 'lngfile lngfile varchar(255) NOT NULL default \'\'',
  2231. 'real_name' => 'real_name real_name varchar(255) NOT NULL default \'\'',
  2232. 'pm_ignore_list' => 'pm_ignore_list pm_ignore_list varchar(255) NOT NULL default \'\'',
  2233. 'email_address' => 'email_address email_address varchar(255) NOT NULL default \'\'',
  2234. 'personal_text' => 'personal_text personal_text varchar(255) NOT NULL default \'\'',
  2235. 'website_title' => 'website_title website_title varchar(255) NOT NULL default \'\'',
  2236. 'website_url' => 'website_url website_url varchar(255) NOT NULL default \'\'',
  2237. 'location' => 'location location varchar(255) NOT NULL default \'\'',
  2238. 'icq' => 'icq icq varchar(255) NOT NULL default \'\'',
  2239. 'aim' => 'aim aim varchar(255) NOT NULL default \'\'',
  2240. 'msn' => 'msn msn varchar(255) NOT NULL default \'\'',
  2241. 'avatar' => 'avatar avatar varchar(255) NOT NULL default \'\'',
  2242. 'usertitle' => 'usertitle usertitle varchar(255) NOT NULL default \'\'',
  2243. 'member_ip' => 'member_ip member_ip varchar(255) NOT NULL default \'\'',
  2244. 'member_ip2' => 'member_ip2 member_ip2 varchar(255) NOT NULL default \'\'',
  2245. 'secret_question' => 'secret_question secret_question varchar(255) NOT NULL default \'\'',
  2246. 'additional_groups' => 'additional_groups additional_groups varchar(255) NOT NULL default \'\'',
  2247. ),
  2248. 'messages' => array(
  2249. 'subject' => 'subject subject varchar(255) NOT NULL default \'\'',
  2250. 'poster_name' => 'poster_name poster_name varchar(255) NOT NULL default \'\'',
  2251. 'poster_email' => 'poster_email poster_email varchar(255) NOT NULL default \'\'',
  2252. 'poster_ip' => 'poster_ip poster_ip varchar(255) NOT NULL default \'\'',
  2253. 'modified_name' => 'modified_name modified_name varchar(255) NOT NULL default \'\'',
  2254. ),
  2255. 'openid_assoc' => array(
  2256. 'handle' => 'handle handle varchar(255) NOT NULL default \'\'',
  2257. ),
  2258. 'package_servers' => array(
  2259. 'name' => 'name name varchar(255) NOT NULL default \'\'',
  2260. 'url' => 'url url varchar(255) NOT NULL default \'\'',
  2261. ),
  2262. 'permission_profiles' => array(
  2263. 'profile_name' => 'profile_name profile_name varchar(255) NOT NULL default \'\'',
  2264. ),
  2265. 'personal_messages' => array(
  2266. 'from_name' => 'from_name from_name varchar(255) NOT NULL default \'\'',
  2267. 'subject' => 'subject subject varchar(255) NOT NULL default \'\'',
  2268. ),
  2269. 'polls' => array(
  2270. 'question' => 'question question varchar(255) NOT NULL default \'\'',
  2271. 'poster_name' => 'poster_name poster_name varchar(255) NOT NULL default \'\'',
  2272. ),
  2273. 'poll_choices' => array(
  2274. 'label' => 'label label varchar(255) NOT NULL default \'\'',
  2275. ),
  2276. 'settings' => array(
  2277. 'variable' => 'variable variable varchar(255) NOT NULL default \'\'',
  2278. ),
  2279. 'spiders' => array(
  2280. 'spider_name' => 'spider_name spider_name varchar(255) NOT NULL default \'\'',
  2281. 'user_agent' => 'user_agent user_agent varchar(255) NOT NULL default \'\'',
  2282. 'ip_info' => 'ip_info ip_info varchar(255) NOT NULL default \'\'',
  2283. ),
  2284. 'subscriptions' => array(
  2285. 'description' => 'description description varchar(255) NOT NULL default \'\'',
  2286. ),
  2287. 'themes' => array(
  2288. 'variable' => 'variable variable varchar(255) NOT NULL default \'\'',
  2289. ),
  2290. );
  2291. $_GET['ren_col'] = isset($_GET['ren_col']) ? (int) $_GET['ren_col'] : 0;
  2292. $step_progress['name'] = 'Changing tinytext columns to varchar(255)';
  2293. $step_progress['current'] = $_GET['ren_col'];
  2294. $step_progress['total'] = count($nameChanges);
  2295. $count = 0;
  2296. // Now do every table...
  2297. foreach ($nameChanges as $table_name => $table)
  2298. {
  2299. // Already done this?
  2300. $count++;
  2301. if ($_GET['ren_col'] > $count)
  2302. continue;
  2303. $_GET['ren_col'] = $count;
  2304. // Check the table exists!
  2305. $request = upgrade_query("
  2306. SHOW TABLES
  2307. LIKE '{$db_prefix}$table_name'");
  2308. if (smf_mysql_num_rows($request) == 0)
  2309. {
  2310. smf_mysql_free_result($request);
  2311. continue;
  2312. }
  2313. smf_mysql_free_result($request);
  2314. // Converting is intensive, so make damn sure that we need to do it.
  2315. $request = upgrade_query("
  2316. SHOW FIELDS
  2317. FROM `{$db_prefix}$table_name`");
  2318. $tinytextColumns = array();
  2319. while($row = smf_mysql_fetch_assoc($request))
  2320. {
  2321. // Tinytext detected so store column name.
  2322. if ($row['Type'] == 'tinytext')
  2323. $tinytextColumns[$row['Field']] = $row['Field'];
  2324. }
  2325. smf_mysql_free_result($request);
  2326. // Check each column!
  2327. $actualChanges = array();
  2328. foreach ($table as $colname => $coldef)
  2329. {
  2330. // Column was not detected as tinytext so skip it
  2331. // Either it was already converted or was changed eg text (so do not break it)
  2332. if (!isset($tinytextColumns[$colname]))
  2333. continue;
  2334. $change = array(
  2335. 'table' => $table_name,
  2336. 'name' => $colname,
  2337. 'type' => 'column',
  2338. 'method' => 'change_remove',
  2339. 'text' => 'CHANGE ' . $coldef,
  2340. );
  2341. if (protected_alter($change, $substep, true) == false)
  2342. $actualChanges[] = ' CHANGE COLUMN ' . $coldef;
  2343. }
  2344. // Do the query - if it needs doing.
  2345. if (!empty($actualChanges))
  2346. {
  2347. $change = array(
  2348. 'table' => $table_name,
  2349. 'name' => 'na',
  2350. 'type' => 'table',
  2351. 'method' => 'full_change',
  2352. 'text' => implode(', ', $actualChanges),
  2353. );
  2354. // Here we go - hold on!
  2355. protected_alter($change, $substep);
  2356. }
  2357. // Update where we are!
  2358. $step_progress['current'] = $_GET['ren_col'];
  2359. }
  2360. // All done!
  2361. unset($_GET['ren_col']);
  2362. ---}
  2363. ---#
  2364. /******************************************************************************/
  2365. --- Adding new personal message setting.
  2366. /******************************************************************************/
  2367. ---# Adding column that stores the PM receiving setting...
  2368. ALTER TABLE {$db_prefix}members
  2369. ADD COLUMN pm_receive_from tinyint(4) unsigned NOT NULL default '1';
  2370. ---#
  2371. ---# Enable the buddy and ignore lists if we have not done so thus far...
  2372. ---{
  2373. // Don't do this if we've done this already.
  2374. if (empty($modSettings['dont_repeat_buddylists']))
  2375. {
  2376. // Make sure the pm_receive_from column has the right default value - early adoptors might have a '0' set here.
  2377. upgrade_query("
  2378. ALTER TABLE {$db_prefix}members
  2379. CHANGE pm_receive_from pm_receive_from tinyint(3) unsigned NOT NULL default '1'");
  2380. // Update previous ignore lists if they're set to ignore all.
  2381. upgrade_query("
  2382. UPDATE {$db_prefix}members
  2383. SET pm_receive_from = 3, pm_ignore_list = ''
  2384. WHERE pm_ignore_list = '*'");
  2385. // Ignore posts made by ignored users by default.
  2386. upgrade_query("
  2387. REPLACE INTO {$db_prefix}themes
  2388. (id_member, id_theme, variable, value)
  2389. VALUES
  2390. (-1, 1, 'posts_apply_ignore_list', '1')");
  2391. // Enable buddy and ignore lists, and make sure not to skip this step next time we run this.
  2392. upgrade_query("
  2393. REPLACE INTO {$db_prefix}settings
  2394. (variable, value)
  2395. VALUES
  2396. ('enable_buddylist', '1'),
  2397. ('dont_repeat_buddylists', '1')");
  2398. }
  2399. // And yet, and yet... We might have a small hiccup here...
  2400. if (!empty($modSettings['dont_repeat_buddylists']) && !isset($modSettings['enable_buddylist']))
  2401. {
  2402. // Correct RC3 adopters setting here...
  2403. if (isset($modSettings['enable_buddylists']))
  2404. {
  2405. upgrade_query("
  2406. REPLACE INTO {$db_prefix}settings
  2407. (variable, value)
  2408. VALUES
  2409. ('enable_buddylist', '" . $modSettings['enable_buddylists'] . "')");
  2410. }
  2411. else
  2412. {
  2413. // This should never happen :)
  2414. upgrade_query("
  2415. REPLACE INTO {$db_prefix}settings
  2416. (variable, value)
  2417. VALUES
  2418. ('enable_buddylist', '1')");
  2419. }
  2420. }
  2421. ---}
  2422. ---#
  2423. /******************************************************************************/
  2424. --- Adding settings for attachments and avatars.
  2425. /******************************************************************************/
  2426. ---# Add new security settings for attachments and avatars...
  2427. ---{
  2428. // Don't do this if we've done this already.
  2429. if (!isset($modSettings['attachment_image_reencode']))
  2430. {
  2431. // Enable image re-encoding by default.
  2432. upgrade_query("
  2433. REPLACE INTO {$db_prefix}settings
  2434. (variable, value)
  2435. VALUES
  2436. ('attachment_image_reencode', '1')");
  2437. }
  2438. if (!isset($modSettings['attachment_image_paranoid']))
  2439. {
  2440. // Disable draconic checks by default.
  2441. upgrade_query("
  2442. REPLACE INTO {$db_prefix}settings
  2443. (variable, value)
  2444. VALUES
  2445. ('attachment_image_paranoid', '0')");
  2446. }
  2447. if (!isset($modSettings['avatar_reencode']))
  2448. {
  2449. // Enable image re-encoding by default.
  2450. upgrade_query("
  2451. REPLACE INTO {$db_prefix}settings
  2452. (variable, value)
  2453. VALUES
  2454. ('avatar_reencode', '1')");
  2455. }
  2456. if (!isset($modSettings['avatar_paranoid']))
  2457. {
  2458. // Disable draconic checks by default.
  2459. upgrade_query("
  2460. REPLACE INTO {$db_prefix}settings
  2461. (variable, value)
  2462. VALUES
  2463. ('avatar_paranoid', '0')");
  2464. }
  2465. ---}
  2466. ---#
  2467. ---# Add other attachment settings...
  2468. ---{
  2469. if (!isset($modSettings['attachment_thumb_png']))
  2470. {
  2471. // Make image attachment thumbnail as PNG by default.
  2472. upgrade_query("
  2473. REPLACE INTO {$db_prefix}settings
  2474. (variable, value)
  2475. VALUES
  2476. ('attachment_thumb_png', '1')");
  2477. }
  2478. ---}
  2479. ---#
  2480. /******************************************************************************/
  2481. --- Installing new default theme...
  2482. /******************************************************************************/
  2483. ---# Installing theme settings...
  2484. ---{
  2485. // This is Grudge's secret "I'm not a developer" theme install code - keep this quiet ;)
  2486. // Firstly, I'm going out of my way to not do this twice!
  2487. if ((!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '2.0 RC5' || $modSettings['smfVersion'] === '2.0 a') && empty($modSettings['dont_repeat_theme_core']))
  2488. {
  2489. // Check it's not already here, just in case.
  2490. $theme_request = upgrade_query("
  2491. SELECT id_theme
  2492. FROM {$db_prefix}themes
  2493. WHERE variable = 'theme_dir'
  2494. AND value LIKE '%core'");
  2495. // Only do the upgrade if it doesn't find the theme already.
  2496. if (smf_mysql_num_rows($theme_request) == 0)
  2497. {
  2498. // Try to get some settings from the current default theme.
  2499. $request = upgrade_query("
  2500. SELECT t1.value AS theme_dir, t2.value AS theme_url, t3.value AS images_url
  2501. FROM ({$db_prefix}themes AS t1, {$db_prefix}themes AS t2, {$db_prefix}themes AS t3)
  2502. WHERE t1.id_theme = 1
  2503. AND t1.id_member = 0
  2504. AND t1.variable = 'theme_dir'
  2505. AND t2.id_theme = 1
  2506. AND t2.id_member = 0
  2507. AND t2.variable = 'theme_url'
  2508. AND t3.id_theme = 1
  2509. AND t3.id_member = 0
  2510. AND t3.variable = 'images_url'
  2511. LIMIT 1");
  2512. if (smf_mysql_num_rows($request) != 0)
  2513. {
  2514. $curve = smf_mysql_fetch_assoc($request);
  2515. if (substr_count($curve['theme_dir'], 'default') === 1)
  2516. $core['theme_dir'] = strtr($curve['theme_dir'], array('default' => 'core'));
  2517. if (substr_count($curve['theme_url'], 'default') === 1)
  2518. $core['theme_url'] = strtr($curve['theme_url'], array('default' => 'core'));
  2519. if (substr_count($curve['images_url'], 'default') === 1)
  2520. $core['images_url'] = strtr($curve['images_url'], array('default' => 'core'));
  2521. }
  2522. smf_mysql_free_result($request);
  2523. if (!isset($core['theme_dir']))
  2524. $core['theme_dir'] = addslashes($GLOBALS['boarddir']) . '/Themes/core';
  2525. if (!isset($core['theme_url']))
  2526. $core['theme_url'] = $GLOBALS['boardurl'] . '/Themes/core';
  2527. if (!isset($core['images_url']))
  2528. $core['images_url'] = $GLOBALS['boardurl'] . '/Themes/core/images';
  2529. // Get an available id_theme first...
  2530. $request = upgrade_query("
  2531. SELECT MAX(id_theme) + 1
  2532. FROM {$db_prefix}themes");
  2533. list ($id_core_theme) = smf_mysql_fetch_row($request);
  2534. smf_mysql_free_result($request);
  2535. // Insert the core theme into the tables.
  2536. upgrade_query("
  2537. INSERT INTO {$db_prefix}themes
  2538. (id_member, id_theme, variable, value)
  2539. VALUES
  2540. (0, $id_core_theme, 'name', 'Core Theme'),
  2541. (0, $id_core_theme, 'theme_url', '$core[theme_url]'),
  2542. (0, $id_core_theme, 'images_url', '$core[images_url]'),
  2543. (0, $id_core_theme, 'theme_dir', '$core[theme_dir]')");
  2544. // Update the name of the default theme in the database.
  2545. upgrade_query("
  2546. UPDATE {$db_prefix}themes
  2547. SET value = 'SMF Default Theme - Curve'
  2548. WHERE id_theme = 1
  2549. AND variable = 'name'");
  2550. // If known themes aren't set, let's just pick all themes available.
  2551. if (empty($modSettings['knownThemes']))
  2552. {
  2553. $request = upgrade_query("
  2554. SELECT DISTINCT id_theme
  2555. FROM {$db_prefix}themes");
  2556. $themes = array();
  2557. while ($row = smf_mysql_fetch_assoc($request))
  2558. $themes[] = $row['id_theme'];
  2559. $modSettings['knownThemes'] = implode(',', $themes);
  2560. upgrade_query("
  2561. UPDATE {$db_prefix}settings
  2562. SET value = '$modSettings[knownThemes]'
  2563. WHERE variable = 'knownThemes'");
  2564. }
  2565. // Known themes.
  2566. $allThemes = explode(',', $modSettings['knownThemes']);
  2567. $allThemes[] = $id_core_theme;
  2568. $newSettings = array();
  2569. $newSettings[] = "('knownThemes', '" . implode(',', $allThemes) . "')";
  2570. upgrade_query("
  2571. REPLACE INTO {$db_prefix}settings
  2572. (variable, value)
  2573. VALUES
  2574. " . implode(', ', $newSettings));
  2575. // The other themes used to use core as their base theme.
  2576. if (isset($core['theme_dir']) && isset($core['theme_url']))
  2577. {
  2578. $coreBasedThemes = array_diff($allThemes, array(1));
  2579. // Exclude the themes that already have a base_theme_dir.
  2580. $request = upgrade_query("
  2581. SELECT DISTINCT id_theme
  2582. FROM {$db_prefix}themes
  2583. WHERE variable = 'base_theme_dir'");
  2584. while ($row = smf_mysql_fetch_assoc($request))
  2585. $coreBasedThemes = array_diff($coreBasedThemes, array($row['id_theme']));
  2586. smf_mysql_free_result($request);
  2587. // Only base themes if there are templates that need a fall-back.
  2588. $insertRows = array();
  2589. $request = upgrade_query("
  2590. SELECT id_theme, value AS theme_dir
  2591. FROM {$db_prefix}themes
  2592. WHERE id_theme IN (" . implode(', ', $coreBasedThemes) . ")
  2593. AND id_member = 0
  2594. AND variable = 'theme_dir'");
  2595. while ($row = smf_mysql_fetch_assoc($request))
  2596. {
  2597. if (!file_exists($row['theme_dir'] . '/BoardIndex.template.php') || !file_exists($row['theme_dir'] . '/Display.template.php') || !file_exists($row['theme_dir'] . '/index.template.php') || !file_exists($row['theme_dir'] . '/MessageIndex.template.php') || !file_exists($row['theme_dir'] . '/Settings.template.php'))
  2598. {
  2599. $insertRows[] = "(0, $row[id_theme], 'base_theme_dir', '" . addslashes($core['theme_dir']) . "')";
  2600. $insertRows[] = "(0, $row[id_theme], 'base_theme_url', '" . addslashes($core['theme_url']) . "')";
  2601. }
  2602. }
  2603. smf_mysql_free_result($request);
  2604. if (!empty($insertRows))
  2605. upgrade_query("
  2606. INSERT IGNORE INTO {$db_prefix}themes
  2607. (id_member, id_theme, variable, value)
  2608. VALUES
  2609. " . implode(',
  2610. ', $insertRows));
  2611. }
  2612. }
  2613. smf_mysql_free_result($theme_request);
  2614. // This ain't running twice either.
  2615. upgrade_query("
  2616. REPLACE INTO {$db_prefix}settings
  2617. (variable, value)
  2618. VALUES
  2619. ('dont_repeat_theme_core', '1')");
  2620. }
  2621. ---}
  2622. ---#
  2623. /******************************************************************************/
  2624. --- Installing new smileys sets...
  2625. /******************************************************************************/
  2626. ---# Installing new smiley sets...
  2627. ---{
  2628. // Don't do this twice!
  2629. if (empty($modSettings['installed_new_smiley_sets_20']))
  2630. {
  2631. // First, the entries.
  2632. upgrade_query("
  2633. UPDATE {$db_prefix}settings
  2634. SET value = CONCAT(value, ',aaron,akyhne')
  2635. WHERE variable = 'smiley_sets_known'");
  2636. // Second, the names.
  2637. upgrade_query("
  2638. UPDATE {$db_prefix}settings
  2639. SET value = CONCAT(value, '\nAaron\nAkyhne')
  2640. WHERE variable = 'smiley_sets_names'");
  2641. // This ain't running twice either.
  2642. upgrade_query("
  2643. REPLACE INTO {$db_prefix}settings
  2644. (variable, value)
  2645. VALUES
  2646. ('installed_new_smiley_sets_20', '1')");
  2647. }
  2648. ---}
  2649. ---#
  2650. /******************************************************************************/
  2651. --- Adding new indexes to the topics table.
  2652. /******************************************************************************/
  2653. ---# Adding index member_started...
  2654. ALTER TABLE {$db_prefix}topics
  2655. ADD INDEX member_started (id_member_started, id_board);
  2656. ---#
  2657. ---# Adding index last_message_sticky...
  2658. ALTER TABLE {$db_prefix}topics
  2659. ADD INDEX last_message_sticky (id_board, is_sticky, id_last_msg);
  2660. ---#
  2661. ---# Adding index board_news...
  2662. ALTER TABLE {$db_prefix}topics
  2663. ADD INDEX board_news (id_board, id_first_msg);
  2664. ---#
  2665. /******************************************************************************/
  2666. --- Adding new indexes to members table.
  2667. /******************************************************************************/
  2668. ---# Adding index on total_time_logged_in...
  2669. ALTER TABLE {$db_prefix}members
  2670. ADD INDEX total_time_logged_in (total_time_logged_in);
  2671. ---#
  2672. ---# Adding index on id_theme...
  2673. ALTER TABLE {$db_prefix}members
  2674. ADD INDEX id_theme (id_theme);
  2675. ---#
  2676. ---# Dropping index on real_name(30) ...
  2677. ---{
  2678. // Detect existing index with limited length
  2679. $request = upgrade_query("
  2680. SHOW INDEXES
  2681. FROM {$db_prefix}members"
  2682. );
  2683. // Drop the existing index before we recreate it.
  2684. while ($row = smf_mysql_fetch_assoc($request))
  2685. {
  2686. if ($row['Key_name'] === 'real_name' && $row['Sub_part'] == 30)
  2687. {
  2688. upgrade_query("
  2689. ALTER TABLE {$db_prefix}members
  2690. DROP INDEX real_name"
  2691. );
  2692. break;
  2693. }
  2694. }
  2695. smf_mysql_free_result($request);
  2696. ---}
  2697. ---#
  2698. ---# Adding index on real_name...
  2699. ALTER TABLE {$db_prefix}members
  2700. ADD INDEX real_name (real_name);
  2701. ---#
  2702. ---# Dropping index member_name(30)...
  2703. ---{
  2704. // Detect existing index with limited length
  2705. $request = upgrade_query("
  2706. SHOW INDEXES
  2707. FROM {$db_prefix}members"
  2708. );
  2709. // Drop the existing index before we recreate it.
  2710. while ($row = smf_mysql_fetch_assoc($request))
  2711. {
  2712. if ($row['Key_name'] === 'member_name' && $row['Sub_part'] == 30)
  2713. {
  2714. upgrade_query("
  2715. ALTER TABLE {$db_prefix}members
  2716. DROP INDEX member_name"
  2717. );
  2718. break;
  2719. }
  2720. }
  2721. smf_mysql_free_result($request);
  2722. ---}
  2723. ---#
  2724. ---# Adding index on member_name...
  2725. ALTER TABLE {$db_prefix}members
  2726. ADD INDEX member_name (member_name);
  2727. ---#
  2728. /******************************************************************************/
  2729. --- Adding new indexes to messages table.
  2730. /******************************************************************************/
  2731. ---# Adding index id_member_msg...
  2732. ALTER TABLE {$db_prefix}messages
  2733. ADD INDEX id_member_msg (id_member, approved, id_msg);
  2734. ---#
  2735. ---# Adding index current_topic...
  2736. ALTER TABLE {$db_prefix}messages
  2737. ADD INDEX current_topic (id_topic, id_msg, id_member, approved);
  2738. ---#
  2739. ---# Adding index related_ip...
  2740. ALTER TABLE {$db_prefix}messages
  2741. ADD INDEX related_ip (id_member, poster_ip, id_msg);
  2742. ---#
  2743. /******************************************************************************/
  2744. --- Adding new indexes to attachments table.
  2745. /******************************************************************************/
  2746. ---# Adding index on attachment_type...
  2747. ALTER TABLE {$db_prefix}attachments
  2748. ADD INDEX attachment_type (attachment_type);
  2749. ---#
  2750. /******************************************************************************/
  2751. --- Dropping unnecessary indexes...
  2752. /******************************************************************************/
  2753. ---# Removing index on hits...
  2754. ALTER TABLE {$db_prefix}log_activity
  2755. DROP INDEX hits;
  2756. ---#
  2757. /******************************************************************************/
  2758. --- Adding extra columns to reported post comments
  2759. /******************************************************************************/
  2760. ---# Adding email address and member ip columns...
  2761. ALTER TABLE {$db_prefix}log_reported_comments
  2762. ADD COLUMN member_ip varchar(255) NOT NULL default '' AFTER membername,
  2763. ADD COLUMN email_address varchar(255) NOT NULL default '' AFTER membername;
  2764. ---#
  2765. /******************************************************************************/
  2766. --- Adjusting group types.
  2767. /******************************************************************************/
  2768. ---# Fixing the group types.
  2769. ---{
  2770. // Get the admin group type.
  2771. $request = upgrade_query("
  2772. SELECT group_type
  2773. FROM {$db_prefix}membergroups
  2774. WHERE id_group = 1
  2775. LIMIT 1");
  2776. list ($admin_group_type) = smf_mysql_fetch_row($request);
  2777. smf_mysql_free_result($request);
  2778. // Not protected means we haven't updated yet!
  2779. if ($admin_group_type != 1)
  2780. {
  2781. // Increase by one.
  2782. upgrade_query("
  2783. UPDATE {$db_prefix}membergroups
  2784. SET group_type = group_type + 1
  2785. WHERE group_type > 0");
  2786. }
  2787. ---}
  2788. ---#
  2789. ---# Changing the group type for Administrator group.
  2790. UPDATE {$db_prefix}membergroups
  2791. SET group_type = 1
  2792. WHERE id_group = 1;
  2793. ---#
  2794. /******************************************************************************/
  2795. --- Final clean up...
  2796. /******************************************************************************/
  2797. ---# Sorting the boards...
  2798. ALTER TABLE {$db_prefix}categories
  2799. ORDER BY cat_order;
  2800. ALTER TABLE {$db_prefix}boards
  2801. ORDER BY board_order;
  2802. ---#