upgrade_2-0_mysql.sql 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030
  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. (20, 'Yandex', 'yandex', '');
  463. ---#
  464. ---# Removing a spider.
  465. ---{
  466. upgrade_query("
  467. DELETE FROM {$db_prefix}spiders
  468. WHERE user_agent = 'yahoo'
  469. AND spider_name = 'Yahoo! (Publisher)'
  470. ");
  471. ---}
  472. ---#
  473. ---# Creating spider hit tracking table.
  474. CREATE TABLE IF NOT EXISTS {$db_prefix}log_spider_hits (
  475. id_hit int(10) unsigned NOT NULL auto_increment,
  476. id_spider smallint(5) unsigned NOT NULL default '0',
  477. log_time int(10) unsigned NOT NULL default '0',
  478. url varchar(255) NOT NULL default '',
  479. processed tinyint(3) unsigned NOT NULL default '0',
  480. PRIMARY KEY (id_hit),
  481. KEY id_spider(id_spider),
  482. KEY log_time(log_time),
  483. KEY processed (processed)
  484. ) ENGINE=MyISAM{$db_collation};
  485. ---#
  486. ---# Making some changes to spider hit table...
  487. ALTER TABLE {$db_prefix}log_spider_hits
  488. ADD COLUMN id_hit int(10) unsigned NOT NULL auto_increment,
  489. ADD PRIMARY KEY (id_hit);
  490. ---#
  491. ---# Creating spider statistic table.
  492. CREATE TABLE IF NOT EXISTS {$db_prefix}log_spider_stats (
  493. id_spider smallint(5) unsigned NOT NULL default '0',
  494. page_hits smallint(5) unsigned NOT NULL default '0',
  495. last_seen int(10) unsigned NOT NULL default '0',
  496. stat_date date NOT NULL default '0001-01-01',
  497. PRIMARY KEY (stat_date, id_spider)
  498. ) ENGINE=MyISAM{$db_collation};
  499. ---#
  500. /******************************************************************************/
  501. --- Adding new forum settings.
  502. /******************************************************************************/
  503. ---# Resetting settings_updated.
  504. REPLACE INTO {$db_prefix}settings
  505. (variable, value)
  506. VALUES
  507. ('settings_updated', '0'),
  508. ('last_mod_report_action', '0'),
  509. ('search_floodcontrol_time', '5'),
  510. ('next_task_time', UNIX_TIMESTAMP());
  511. ---#
  512. ---# Changing stats settings.
  513. ---{
  514. $request = upgrade_query("
  515. SELECT value
  516. FROM {$db_prefix}themes
  517. WHERE variable = 'show_sp1_info'");
  518. if (smf_mysql_num_rows($request) != 0)
  519. {
  520. upgrade_query("
  521. DELETE FROM {$db_prefix}themes
  522. WHERE variable = 'show_stats_index'");
  523. upgrade_query("
  524. UPDATE {$db_prefix}themes
  525. SET variable = 'show_stats_index'
  526. WHERE variable = 'show_sp1_info'");
  527. }
  528. upgrade_query("
  529. DELETE FROM {$db_prefix}themes
  530. WHERE variable = 'show_sp1_info'");
  531. ---}
  532. ---#
  533. ---# Enable cache if upgrading from 1.1 and lower.
  534. ---{
  535. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1')
  536. {
  537. $request = upgrade_query("
  538. SELECT value
  539. FROM {$db_prefix}settings
  540. WHERE variable = 'cache_enable'");
  541. list ($cache_enable) = $smcFunc['db_fetch_row']($request);
  542. // No cache before 1.1.
  543. if ($smcFunc['db_num_rows']($request) == 0)
  544. upgrade_query("
  545. INSERT INTO {$db_prefix}settings
  546. (variable, value)
  547. VALUES ('cache_enable', '1')");
  548. elseif (empty($cache_enable))
  549. upgrade_query("
  550. UPDATE {$db_prefix}settings
  551. SET value = '1'
  552. WHERE variable = 'cache_enable'");
  553. }
  554. ---}
  555. ---#
  556. ---# Changing visual verification setting.
  557. ---{
  558. $request = upgrade_query("
  559. SELECT value
  560. FROM {$db_prefix}settings
  561. WHERE variable = 'disable_visual_verification'");
  562. if (smf_mysql_num_rows($request) != 0)
  563. {
  564. list ($oldValue) = smf_mysql_fetch_row($request);
  565. if ($oldValue != 0)
  566. {
  567. // We have changed the medium setting from SMF 1.1.2.
  568. if ($oldValue == 4)
  569. $oldValue = 5;
  570. upgrade_query("
  571. UPDATE {$db_prefix}settings
  572. SET variable = 'visual_verification_type', value = $oldValue
  573. WHERE variable = 'disable_visual_verification'");
  574. }
  575. }
  576. upgrade_query("
  577. DELETE FROM {$db_prefix}settings
  578. WHERE variable = 'disable_visual_verification'");
  579. ---}
  580. ---#
  581. ---# Changing visual verification setting, again.
  582. ---{
  583. $request = upgrade_query("
  584. SELECT value
  585. FROM {$db_prefix}settings
  586. WHERE variable = 'reg_verification'");
  587. if (smf_mysql_num_rows($request) == 0)
  588. {
  589. // Upgrade visual verification again!
  590. if (!empty($modSettings['visual_verification_type']))
  591. {
  592. upgrade_query("
  593. UPDATE {$db_prefix}settings
  594. SET value = value - 1
  595. WHERE variable = 'visual_verification_type'");
  596. $modSettings['visual_verification_type']--;
  597. }
  598. // Never set?
  599. elseif (!isset($modSettings['visual_verification_type']))
  600. {
  601. upgrade_query("
  602. INSERT INTO {$db_prefix}settings
  603. (variable, value)
  604. VALUES
  605. ('visual_verification_type', '3')");
  606. $modSettings['visual_verification_type'] = 3;
  607. }
  608. upgrade_query("
  609. INSERT INTO {$db_prefix}settings
  610. (variable, value)
  611. VALUES
  612. ('reg_verification', '" . (!empty($modSettings['visual_verification_type']) ? 1 : 0) . "')");
  613. }
  614. ---}
  615. ---#
  616. ---# Changing default personal text setting.
  617. UPDATE {$db_prefix}settings
  618. SET variable = 'default_personal_text'
  619. WHERE variable = 'default_personalText';
  620. DELETE FROM {$db_prefix}settings
  621. WHERE variable = 'default_personalText';
  622. ---#
  623. ---# Removing allow hide email setting.
  624. DELETE FROM {$db_prefix}settings
  625. WHERE variable = 'allow_hideEmail'
  626. OR variable = 'allow_hide_email';
  627. ---#
  628. ---# Ensuring stats index setting present...
  629. INSERT IGNORE INTO {$db_prefix}themes
  630. (id_theme, variable, value)
  631. VALUES
  632. (1, 'show_stats_index', '0');
  633. ---#
  634. ---# Ensuring forum width setting present...
  635. INSERT IGNORE INTO {$db_prefix}themes
  636. (id_theme, variable, value)
  637. VALUES
  638. (1, 'forum_width', '90%');
  639. ---#
  640. ---# Replacing old calendar settings...
  641. ---{
  642. // Only try it if one of the "new" settings doesn't yet exist.
  643. if (!isset($modSettings['cal_showholidays']) || !isset($modSettings['cal_showbdays']) || !isset($modSettings['cal_showevents']))
  644. {
  645. // Default to just the calendar setting.
  646. $modSettings['cal_showholidays'] = empty($modSettings['cal_showholidaysoncalendar']) ? 0 : 1;
  647. $modSettings['cal_showbdays'] = empty($modSettings['cal_showbdaysoncalendar']) ? 0 : 1;
  648. $modSettings['cal_showevents'] = empty($modSettings['cal_showeventsoncalendar']) ? 0 : 1;
  649. // Then take into account board index.
  650. if (!empty($modSettings['cal_showholidaysonindex']))
  651. $modSettings['cal_showholidays'] = $modSettings['cal_showholidays'] === 1 ? 2 : 3;
  652. if (!empty($modSettings['cal_showbdaysonindex']))
  653. $modSettings['cal_showbdays'] = $modSettings['cal_showbdays'] === 1 ? 2 : 3;
  654. if (!empty($modSettings['cal_showeventsonindex']))
  655. $modSettings['cal_showevents'] = $modSettings['cal_showevents'] === 1 ? 2 : 3;
  656. // Actually save the settings.
  657. upgrade_query("
  658. INSERT IGNORE INTO {$db_prefix}settings
  659. (variable, value)
  660. VALUES
  661. ('cal_showholidays', $modSettings[cal_showholidays]),
  662. ('cal_showbdays', $modSettings[cal_showbdays]),
  663. ('cal_showevents', $modSettings[cal_showevents])");
  664. }
  665. ---}
  666. ---#
  667. ---# Deleting old calendar settings...
  668. DELETE FROM {$db_prefix}settings
  669. WHERE VARIABLE IN ('cal_showholidaysonindex', 'cal_showbdaysonindex', 'cal_showeventsonindex',
  670. 'cal_showholidaysoncalendar', 'cal_showbdaysoncalendar', 'cal_showeventsoncalendar',
  671. 'cal_holidaycolor', 'cal_bdaycolor', 'cal_eventcolor');
  672. ---#
  673. ---# Adjusting calendar maximum year...
  674. ---{
  675. if (!isset($modSettings['cal_maxyear']) || $modSettings['cal_maxyear'] == '2010')
  676. {
  677. upgrade_query("
  678. REPLACE INTO {$db_prefix}settings
  679. (variable, value)
  680. VALUES
  681. ('cal_maxyear', '2020')");
  682. }
  683. ---}
  684. ---#
  685. ---# Adding advanced signature settings...
  686. ---{
  687. if (empty($modSettings['signature_settings']))
  688. {
  689. if (isset($modSettings['max_signatureLength']))
  690. $modSettings['signature_settings'] = '1,' . $modSettings['max_signatureLength'] . ',0,0,0,0,0,0:';
  691. else
  692. $modSettings['signature_settings'] = '1,300,0,0,0,0,0,0:';
  693. upgrade_query("
  694. INSERT IGNORE INTO {$db_prefix}settings
  695. (variable, value)
  696. VALUES
  697. ('signature_settings', '$modSettings[signature_settings]')");
  698. upgrade_query("
  699. DELETE FROM {$db_prefix}settings
  700. WHERE variable = 'max_signatureLength'");
  701. }
  702. ---}
  703. ---#
  704. ---# Updating spam protection settings.
  705. ---{
  706. if (empty($modSettings['pm_spam_settings']))
  707. {
  708. if (isset($modSettings['max_pm_recipients']))
  709. $modSettings['pm_spam_settings'] = $modSettings['max_pm_recipients'] . ',5,20';
  710. else
  711. $modSettings['pm_spam_settings'] = '10,5,20';
  712. }
  713. elseif (substr_count($modSettings['pm_spam_settings'], ',') == 1)
  714. {
  715. $modSettings['pm_spam_settings'] .= ',20';
  716. }
  717. upgrade_query("
  718. INSERT IGNORE INTO {$db_prefix}settings
  719. (variable, value)
  720. VALUES
  721. ('pm_spam_settings', '$modSettings[pm_spam_settings]')");
  722. upgrade_query("
  723. DELETE FROM {$db_prefix}settings
  724. WHERE variable = 'max_pm_recipients'");
  725. ---}
  726. ---#
  727. ---# Adjusting timezone settings...
  728. ---{
  729. if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
  730. {
  731. $server_offset = mktime(0, 0, 0, 1, 1, 1970);
  732. $timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600);
  733. if (date_default_timezone_set($timezone_id))
  734. upgrade_query("
  735. REPLACE INTO {$db_prefix}settings
  736. (variable, value)
  737. VALUES
  738. ('default_timezone', '$timezone_id')");
  739. }
  740. ---}
  741. ---#
  742. ---# Checking theme layers are correct for default themes.
  743. ---{
  744. $request = upgrade_query("
  745. SELECT id_theme, value, variable
  746. FROM {$db_prefix}themes
  747. WHERE variable = 'theme_layers'
  748. OR variable = 'theme_dir'");
  749. $themeLayerChanges = array();
  750. while ($row = smf_mysql_fetch_assoc($request))
  751. {
  752. $themeLayerChanges[$row['id_theme']][$row['variable']] = $row['value'];
  753. }
  754. smf_mysql_free_result($request);
  755. foreach ($themeLayerChanges as $id_theme => $data)
  756. {
  757. // Has to be a SMF provided theme and have custom layers defined.
  758. if (!isset($data['theme_layers']) || !isset($data['theme_dir']) || !in_array(substr($data['theme_dir'], -7), array('default', 'babylon', 'classic')))
  759. continue;
  760. $layers = explode(',', $data['theme_layers']);
  761. foreach ($layers as $k => $v)
  762. if ($v == 'main')
  763. {
  764. $layers[$k] = 'html,body';
  765. upgrade_query("
  766. UPDATE {$db_prefix}themes
  767. SET value = '" . implode(',', $layers) . "'
  768. WHERE id_theme = $id_theme
  769. AND variable = 'theme_layers'");
  770. break;
  771. }
  772. }
  773. ---}
  774. ---#
  775. ---# Adding index to log_notify table...
  776. ALTER TABLE {$db_prefix}log_notify
  777. ADD INDEX id_topic (id_topic, id_member);
  778. ---#
  779. /******************************************************************************/
  780. --- Adding custom profile fields.
  781. /******************************************************************************/
  782. ---# Creating "custom_fields" table...
  783. CREATE TABLE IF NOT EXISTS {$db_prefix}custom_fields (
  784. id_field smallint(5) NOT NULL auto_increment,
  785. col_name varchar(12) NOT NULL default '',
  786. field_name varchar(40) NOT NULL default '',
  787. field_desc varchar(255) NOT NULL default '',
  788. field_type varchar(8) NOT NULL default 'text',
  789. field_length smallint(5) NOT NULL default '255',
  790. field_options text NOT NULL,
  791. mask varchar(255) NOT NULL default '',
  792. show_reg tinyint(3) NOT NULL default '0',
  793. show_display tinyint(3) NOT NULL default '0',
  794. show_profile varchar(20) NOT NULL default 'forumprofile',
  795. private tinyint(3) NOT NULL default '0',
  796. active tinyint(3) NOT NULL default '1',
  797. bbc tinyint(3) NOT NULL default '0',
  798. default_value varchar(255) NOT NULL default '',
  799. PRIMARY KEY (id_field),
  800. UNIQUE col_name (col_name)
  801. ) ENGINE=MyISAM{$db_collation};
  802. ---#
  803. ---# Adding search ability to custom fields.
  804. ALTER TABLE {$db_prefix}custom_fields
  805. ADD COLUMN can_search tinyint(3) NOT NULL default '0' AFTER bbc;
  806. ---#
  807. ---# Fixing default value field length.
  808. ALTER TABLE {$db_prefix}custom_fields
  809. CHANGE COLUMN default_value default_value varchar(255) NOT NULL default '';
  810. ---#
  811. ---# Enhancing privacy settings for custom fields.
  812. ---{
  813. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1')
  814. {
  815. upgrade_query("
  816. UPDATE {$db_prefix}custom_fields
  817. SET private = 2
  818. WHERE private = 1");
  819. }
  820. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] < '2.0 Beta 4')
  821. {
  822. upgrade_query("
  823. UPDATE {$db_prefix}custom_fields
  824. SET private = 3
  825. WHERE private = 2");
  826. }
  827. ---}
  828. ---#
  829. ---# Checking display fields setup correctly..
  830. ---{
  831. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1' && isset($modSettings['displayFields']) && @unserialize($modSettings['displayFields']) == false)
  832. {
  833. $request = upgrade_query("
  834. SELECT col_name, field_name, bbc
  835. FROM {$db_prefix}custom_fields
  836. WHERE show_display = 1
  837. AND active = 1
  838. AND private != 2");
  839. $fields = array();
  840. while ($row = smf_mysql_fetch_assoc($request))
  841. {
  842. $fields[] = array(
  843. 'c' => strtr($row['col_name'], array('|' => '', ';' => '')),
  844. 'f' => strtr($row['field_name'], array('|' => '', ';' => '')),
  845. 'b' => ($row['bbc'] ? '1' : '0')
  846. );
  847. }
  848. smf_mysql_free_result($request);
  849. upgrade_query("
  850. UPDATE {$db_prefix}settings
  851. SET value = '" . smf_mysql_real_escape_string(serialize($fields)) . "'
  852. WHERE variable = 'displayFields'");
  853. }
  854. ---}
  855. ---#
  856. ---# Adding new custom fields columns.
  857. ALTER TABLE {$db_prefix}custom_fields
  858. ADD enclose text NOT NULL;
  859. ALTER TABLE {$db_prefix}custom_fields
  860. ADD placement tinyint(3) NOT NULL default '0';
  861. ---#
  862. /******************************************************************************/
  863. --- Adding email digest functionality.
  864. /******************************************************************************/
  865. ---# Creating "log_digest" table...
  866. CREATE TABLE IF NOT EXISTS {$db_prefix}log_digest (
  867. id_topic mediumint(8) unsigned NOT NULL default '0',
  868. id_msg int(10) unsigned NOT NULL default '0',
  869. note_type varchar(10) NOT NULL default 'post',
  870. daily tinyint(3) unsigned NOT NULL default '0',
  871. exclude mediumint(8) unsigned NOT NULL default '0'
  872. ) ENGINE=MyISAM{$db_collation};
  873. ---#
  874. ---# Adding digest option to "members" table...
  875. ALTER TABLE {$db_prefix}members
  876. CHANGE COLUMN notifyOnce notify_regularity tinyint(4) unsigned NOT NULL default '1';
  877. ---#
  878. /******************************************************************************/
  879. --- Making changes to the package manager.
  880. /******************************************************************************/
  881. ---# Creating "log_packages" table...
  882. CREATE TABLE IF NOT EXISTS {$db_prefix}log_packages (
  883. id_install int(10) NOT NULL auto_increment,
  884. filename varchar(255) NOT NULL default '',
  885. package_id varchar(255) NOT NULL default '',
  886. name varchar(255) NOT NULL default '',
  887. version varchar(255) NOT NULL default '',
  888. id_member_installed mediumint(8) NOT NULL default '0',
  889. member_installed varchar(255) NOT NULL default '',
  890. time_installed int(10) NOT NULL default '0',
  891. id_member_removed mediumint(8) NOT NULL default '0',
  892. member_removed varchar(255) NOT NULL default '',
  893. time_removed int(10) NOT NULL default '0',
  894. install_state tinyint(3) NOT NULL default '1',
  895. failed_steps text NOT NULL,
  896. themes_installed varchar(255) NOT NULL default '',
  897. db_changes text NOT NULL,
  898. PRIMARY KEY (id_install),
  899. KEY filename (filename(15))
  900. ) ENGINE=MyISAM{$db_collation};
  901. ---#
  902. ---# Adding extra "log_packages" columns...
  903. ALTER TABLE {$db_prefix}log_packages
  904. ADD db_changes text NOT NULL AFTER themes_installed;
  905. ---#
  906. ---# Changing URL to SMF package server...
  907. UPDATE {$db_prefix}package_servers
  908. SET url = 'http://custom.simplemachines.org/packages/mods'
  909. WHERE url = 'http://mods.simplemachines.org';
  910. ---#
  911. /******************************************************************************/
  912. --- Creating mail queue functionality.
  913. /******************************************************************************/
  914. ---# Creating "mail_queue" table...
  915. CREATE TABLE IF NOT EXISTS {$db_prefix}mail_queue (
  916. id_mail int(10) unsigned NOT NULL auto_increment,
  917. time_sent int(10) NOT NULL default '0',
  918. recipient varchar(255) NOT NULL default '',
  919. body text NOT NULL,
  920. subject varchar(255) NOT NULL default '',
  921. headers text NOT NULL,
  922. send_html tinyint(3) NOT NULL default '0',
  923. priority tinyint(3) NOT NULL default '1',
  924. PRIMARY KEY (id_mail),
  925. KEY time_sent (time_sent),
  926. KEY mail_priority (priority, id_mail)
  927. ) ENGINE=MyISAM{$db_collation};
  928. ---#
  929. ---# Adding new mail queue settings...
  930. ---{
  931. if (!isset($modSettings['mail_next_send']))
  932. {
  933. upgrade_query("
  934. INSERT INTO {$db_prefix}settings
  935. (variable, value)
  936. VALUES
  937. ('mail_next_send', '0'),
  938. ('mail_recent', '0000000000|0')");
  939. }
  940. ---}
  941. ---#
  942. ---# Change mail queue indexes...
  943. ALTER TABLE {$db_prefix}mail_queue
  944. DROP INDEX priority;
  945. ALTER TABLE {$db_prefix}mail_queue
  946. ADD INDEX mail_priority (priority, id_mail);
  947. ---#
  948. ---# Adding type to mail queue...
  949. ALTER TABLE {$db_prefix}mail_queue
  950. ADD private tinyint(1) NOT NULL default '0';
  951. ---#
  952. /******************************************************************************/
  953. --- Creating moderation center tables.
  954. /******************************************************************************/
  955. ---# Creating "log_reported" table...
  956. CREATE TABLE IF NOT EXISTS {$db_prefix}log_reported (
  957. id_report mediumint(8) unsigned NOT NULL auto_increment,
  958. id_msg int(10) unsigned NOT NULL default '0',
  959. id_topic mediumint(8) unsigned NOT NULL default '0',
  960. id_board smallint(5) unsigned NOT NULL default '0',
  961. id_member mediumint(8) unsigned NOT NULL default '0',
  962. membername varchar(255) NOT NULL default '',
  963. subject varchar(255) NOT NULL default '',
  964. body text NOT NULL,
  965. time_started int(10) NOT NULL default '0',
  966. time_updated int(10) NOT NULL default '0',
  967. num_reports mediumint(6) NOT NULL default '0',
  968. closed tinyint(3) NOT NULL default '0',
  969. ignore_all tinyint(3) NOT NULL default '0',
  970. PRIMARY KEY (id_report),
  971. KEY id_member (id_member),
  972. KEY id_topic (id_topic),
  973. KEY closed (closed),
  974. KEY time_started (time_started),
  975. KEY id_msg (id_msg)
  976. ) ENGINE=MyISAM{$db_collation};
  977. ---#
  978. ---# Creating "log_reported_comments" table...
  979. CREATE TABLE IF NOT EXISTS {$db_prefix}log_reported_comments (
  980. id_comment mediumint(8) unsigned NOT NULL auto_increment,
  981. id_report mediumint(8) NOT NULL default '0',
  982. id_member mediumint(8) NOT NULL,
  983. membername varchar(255) NOT NULL default '',
  984. comment varchar(255) NOT NULL default '',
  985. time_sent int(10) NOT NULL,
  986. PRIMARY KEY (id_comment),
  987. KEY id_report (id_report),
  988. KEY id_member (id_member),
  989. KEY time_sent (time_sent)
  990. ) ENGINE=MyISAM{$db_collation};
  991. ---#
  992. ---# Adding moderator center permissions...
  993. ---{
  994. // Don't do this twice!
  995. if (@$modSettings['smfVersion'] < '2.0')
  996. {
  997. // Try find people who probably should see the moderation center.
  998. $request = upgrade_query("
  999. SELECT id_group, add_deny, permission
  1000. FROM {$db_prefix}permissions
  1001. WHERE permission = 'calendar_edit_any'");
  1002. $inserts = array();
  1003. while ($row = smf_mysql_fetch_assoc($request))
  1004. {
  1005. $inserts[] = "($row[id_group], 'access_mod_center', $row[add_deny])";
  1006. }
  1007. smf_mysql_free_result($request);
  1008. if (!empty($inserts))
  1009. upgrade_query("
  1010. INSERT IGNORE INTO {$db_prefix}permissions
  1011. (id_group, permission, add_deny)
  1012. VALUES
  1013. " . implode(',', $inserts));
  1014. }
  1015. ---}
  1016. ---#
  1017. ---# Adding moderation center preferences...
  1018. ALTER TABLE {$db_prefix}members
  1019. ADD mod_prefs varchar(20) NOT NULL default '';
  1020. ---#
  1021. /******************************************************************************/
  1022. --- Adding user warnings.
  1023. /******************************************************************************/
  1024. ---# Creating member notices table...
  1025. CREATE TABLE IF NOT EXISTS {$db_prefix}log_member_notices (
  1026. id_notice mediumint(8) unsigned NOT NULL auto_increment,
  1027. subject varchar(255) NOT NULL default '',
  1028. body text NOT NULL,
  1029. PRIMARY KEY (id_notice)
  1030. ) ENGINE=MyISAM{$db_collation};
  1031. ---#
  1032. ---# Creating comments table...
  1033. CREATE TABLE IF NOT EXISTS {$db_prefix}log_comments (
  1034. id_comment mediumint(8) unsigned NOT NULL auto_increment,
  1035. id_member mediumint(8) unsigned NOT NULL default '0',
  1036. member_name varchar(80) NOT NULL default '',
  1037. comment_type varchar(8) NOT NULL default 'warning',
  1038. id_recipient mediumint(8) unsigned NOT NULL default '0',
  1039. recipient_name varchar(255) NOT NULL default '',
  1040. log_time int(10) NOT NULL default '0',
  1041. id_notice mediumint(8) unsigned NOT NULL default '0',
  1042. counter tinyint(3) NOT NULL default '0',
  1043. body text NOT NULL,
  1044. PRIMARY KEY (id_comment),
  1045. KEY id_recipient (id_recipient),
  1046. KEY log_time (log_time),
  1047. KEY comment_type (comment_type(8))
  1048. ) ENGINE=MyISAM{$db_collation};
  1049. ---#
  1050. ---# Adding user warning column...
  1051. ALTER TABLE {$db_prefix}members
  1052. ADD warning tinyint(4) NOT NULL default '0';
  1053. ALTER TABLE {$db_prefix}members
  1054. ADD INDEX warning (warning);
  1055. ---#
  1056. ---# Ensuring warning settings are present...
  1057. ---{
  1058. // Only do this if not already done.
  1059. if (empty($modSettings['warning_settings']))
  1060. {
  1061. upgrade_query("
  1062. INSERT IGNORE INTO {$db_prefix}settings
  1063. (variable, value)
  1064. VALUES
  1065. ('warning_settings', '1,20,0'),
  1066. ('warning_watch', '10'),
  1067. ('warning_moderate', '35'),
  1068. ('warning_mute', '60')");
  1069. }
  1070. ---}
  1071. ---#
  1072. /******************************************************************************/
  1073. --- Enhancing membergroups.
  1074. /******************************************************************************/
  1075. ---# Creating "log_group_requests" table...
  1076. CREATE TABLE IF NOT EXISTS {$db_prefix}log_group_requests (
  1077. id_request mediumint(8) unsigned NOT NULL auto_increment,
  1078. id_member mediumint(8) unsigned NOT NULL default '0',
  1079. id_group smallint(5) unsigned NOT NULL default '0',
  1080. time_applied int(10) unsigned NOT NULL default '0',
  1081. reason text NOT NULL,
  1082. PRIMARY KEY (id_request),
  1083. UNIQUE id_member (id_member, id_group)
  1084. ) ENGINE=MyISAM{$db_collation};
  1085. ---#
  1086. ---# Adding new membergroup table columns...
  1087. ALTER TABLE {$db_prefix}membergroups
  1088. ADD description text NOT NULL AFTER group_name;
  1089. ALTER TABLE {$db_prefix}membergroups
  1090. ADD group_type tinyint(3) NOT NULL default '0';
  1091. ALTER TABLE {$db_prefix}membergroups
  1092. ADD hidden tinyint(3) NOT NULL default '0';
  1093. ---#
  1094. ---# Creating "group_moderators" table...
  1095. CREATE TABLE IF NOT EXISTS {$db_prefix}group_moderators (
  1096. id_group smallint(5) unsigned NOT NULL default '0',
  1097. id_member mediumint(8) unsigned NOT NULL default '0',
  1098. PRIMARY KEY (id_group, id_member)
  1099. ) ENGINE=MyISAM{$db_collation};
  1100. ---#
  1101. /******************************************************************************/
  1102. --- Updating attachment data...
  1103. /******************************************************************************/
  1104. ---# Altering attachment table.
  1105. ALTER TABLE {$db_prefix}attachments
  1106. ADD COLUMN fileext varchar(8) NOT NULL default '',
  1107. ADD COLUMN mime_type varchar(20) NOT NULL default '';
  1108. ALTER TABLE {$db_prefix}attachments
  1109. ADD COLUMN id_folder tinyint(3) NOT NULL default '1';
  1110. ---#
  1111. ---# Adding file hash.
  1112. ALTER TABLE {$db_prefix}attachments
  1113. ADD COLUMN file_hash varchar(40) NOT NULL default '';
  1114. ---#
  1115. ---# Populate the attachment extension.
  1116. UPDATE {$db_prefix}attachments
  1117. SET fileext = LOWER(SUBSTRING(filename, 1 - (INSTR(REVERSE(filename), '.'))))
  1118. WHERE fileext = ''
  1119. AND INSTR(filename, '.')
  1120. AND attachment_type != 3;
  1121. ---#
  1122. ---# Updating thumbnail attachments JPG.
  1123. UPDATE {$db_prefix}attachments
  1124. SET fileext = 'jpg'
  1125. WHERE attachment_type = 3
  1126. AND fileext = ''
  1127. AND RIGHT(filename, 9) = 'JPG_thumb';
  1128. ---#
  1129. ---# Updating thumbnail attachments PNG.
  1130. UPDATE {$db_prefix}attachments
  1131. SET fileext = 'png'
  1132. WHERE attachment_type = 3
  1133. AND fileext = ''
  1134. AND RIGHT(filename, 9) = 'PNG_thumb';
  1135. ---#
  1136. ---# Calculating attachment mime types.
  1137. ---{
  1138. // Don't ever bother doing this twice.
  1139. if (@$modSettings['smfVersion'] < '2.0' || @$modSettings['smfVersion'] === '2.0 a')
  1140. {
  1141. $request = upgrade_query("
  1142. SELECT MAX(id_attach)
  1143. FROM {$db_prefix}attachments");
  1144. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  1145. $smcFunc['db_free_result']($request);
  1146. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  1147. $step_progress['name'] = 'Calculating MIME Types';
  1148. $step_progress['current'] = $_GET['a'];
  1149. if (!function_exists('getAttachmentFilename'))
  1150. {
  1151. function getAttachmentFilename($filename, $attachment_id)
  1152. {
  1153. global $modSettings;
  1154. $clean_name = strtr($filename, 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
  1155. $clean_name = strtr($clean_name, array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u'));
  1156. $clean_name = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $clean_name);
  1157. $enc_name = $attachment_id . '_' . strtr($clean_name, '.', '_') . md5($clean_name);
  1158. $clean_name = preg_replace('~\.[\.]+~', '.', $clean_name);
  1159. if ($attachment_id == false)
  1160. return $clean_name;
  1161. if (file_exists($modSettings['attachmentUploadDir'] . '/' . $enc_name))
  1162. $filename = $modSettings['attachmentUploadDir'] . '/' . $enc_name;
  1163. else
  1164. $filename = $modSettings['attachmentUploadDir'] . '/' . $clean_name;
  1165. return $filename;
  1166. }
  1167. }
  1168. $ext_updates = array();
  1169. // What headers are valid results for getimagesize?
  1170. $validTypes = array(
  1171. 1 => 'gif',
  1172. 2 => 'jpeg',
  1173. 3 => 'png',
  1174. 5 => 'psd',
  1175. 6 => 'bmp',
  1176. 7 => 'tiff',
  1177. 8 => 'tiff',
  1178. 9 => 'jpeg',
  1179. 14 => 'iff',
  1180. );
  1181. $is_done = false;
  1182. while (!$is_done)
  1183. {
  1184. nextSubStep($substep);
  1185. $request = upgrade_query("
  1186. SELECT id_attach, filename, fileext
  1187. FROM {$db_prefix}attachments
  1188. WHERE fileext != ''
  1189. AND mime_type = ''
  1190. LIMIT $_GET[a], 100");
  1191. // Finished?
  1192. if ($smcFunc['db_num_rows']($request) == 0)
  1193. $is_done = true;
  1194. while ($row = $smcFunc['db_fetch_assoc']($request))
  1195. {
  1196. $filename = getAttachmentFilename($row['filename'], $row['id_attach']);
  1197. if (!file_exists($filename))
  1198. continue;
  1199. // Is it an image?
  1200. $size = @getimagesize($filename);
  1201. // Nothing valid?
  1202. if (empty($size) || empty($size[0]))
  1203. continue;
  1204. // Got the mime?
  1205. elseif (!empty($size['mime']))
  1206. $mime = $size['mime'];
  1207. // Otherwise is it valid?
  1208. elseif (!isset($validTypes[$size[2]]))
  1209. continue;
  1210. else
  1211. $mime = 'image/' . $validTypes[$size[2]];
  1212. // Let's try keep updates to a minimum.
  1213. if (!isset($ext_updates[$row['fileext'] . $size['mime']]))
  1214. $ext_updates[$row['fileext'] . $size['mime']] = array(
  1215. 'fileext' => $row['fileext'],
  1216. 'mime' => $mime,
  1217. 'files' => array(),
  1218. );
  1219. $ext_updates[$row['fileext'] . $size['mime']]['files'][] = $row['id_attach'];
  1220. }
  1221. $smcFunc['db_free_result']($request);
  1222. // Do the updates?
  1223. foreach ($ext_updates as $key => $update)
  1224. {
  1225. upgrade_query("
  1226. UPDATE {$db_prefix}attachments
  1227. SET mime_type = '$update[mime]'
  1228. WHERE id_attach IN (" . implode(',', $update['files']) . ")");
  1229. // Remove it.
  1230. unset($ext_updates[$key]);
  1231. }
  1232. $_GET['a'] += 100;
  1233. $step_progress['current'] = $_GET['a'];
  1234. }
  1235. unset($_GET['a']);
  1236. }
  1237. ---}
  1238. ---#
  1239. /******************************************************************************/
  1240. --- Adding Post Moderation.
  1241. /******************************************************************************/
  1242. ---# Creating "approval_queue" table...
  1243. CREATE TABLE IF NOT EXISTS {$db_prefix}approval_queue (
  1244. id_msg int(10) unsigned NOT NULL default '0',
  1245. id_attach int(10) unsigned NOT NULL default '0',
  1246. id_event smallint(5) unsigned NOT NULL default '0'
  1247. ) ENGINE=MyISAM{$db_collation};
  1248. ---#
  1249. ---# Adding approved column to attachments table...
  1250. ALTER TABLE {$db_prefix}attachments
  1251. ADD approved tinyint(3) NOT NULL default '1';
  1252. ---#
  1253. ---# Adding approved column to messages table...
  1254. ALTER TABLE {$db_prefix}messages
  1255. ADD approved tinyint(3) NOT NULL default '1';
  1256. ALTER TABLE {$db_prefix}messages
  1257. ADD INDEX approved (approved);
  1258. ---#
  1259. ---# Adding unapproved count column to topics table...
  1260. ALTER TABLE {$db_prefix}topics
  1261. ADD unapproved_posts smallint(5) NOT NULL default '0';
  1262. ---#
  1263. ---# Adding approved column to topics table...
  1264. ALTER TABLE {$db_prefix}topics
  1265. ADD approved tinyint(3) NOT NULL default '1',
  1266. ADD INDEX approved (approved);
  1267. ---#
  1268. ---# Adding approved columns to boards table...
  1269. ALTER TABLE {$db_prefix}boards
  1270. ADD unapproved_posts smallint(5) NOT NULL default '0',
  1271. ADD unapproved_topics smallint(5) NOT NULL default '0';
  1272. ---#
  1273. ---# Adding post moderation permissions...
  1274. ---{
  1275. // We *cannot* do this twice!
  1276. if (@$modSettings['smfVersion'] < '2.0')
  1277. {
  1278. // Anyone who can currently edit posts we assume can approve them...
  1279. $request = upgrade_query("
  1280. SELECT id_group, id_board, add_deny, permission
  1281. FROM {$db_prefix}board_permissions
  1282. WHERE permission = 'modify_any'");
  1283. $inserts = array();
  1284. while ($row = smf_mysql_fetch_assoc($request))
  1285. {
  1286. $inserts[] = "($row[id_group], $row[id_board], 'approve_posts', $row[add_deny])";
  1287. }
  1288. smf_mysql_free_result($request);
  1289. if (!empty($inserts))
  1290. upgrade_query("
  1291. INSERT IGNORE INTO {$db_prefix}board_permissions
  1292. (id_group, id_board, permission, add_deny)
  1293. VALUES
  1294. " . implode(',', $inserts));
  1295. }
  1296. ---}
  1297. ---#
  1298. /******************************************************************************/
  1299. --- Upgrading the error log.
  1300. /******************************************************************************/
  1301. ---# Adding columns to log_errors table...
  1302. ALTER TABLE {$db_prefix}log_errors
  1303. ADD error_type char(15) NOT NULL default 'general';
  1304. ALTER TABLE {$db_prefix}log_errors
  1305. ADD file varchar(255) NOT NULL default '',
  1306. ADD line mediumint(8) unsigned NOT NULL default '0';
  1307. ---#
  1308. ---# Updating error log table...
  1309. ---{
  1310. $request = upgrade_query("
  1311. SELECT COUNT(*)
  1312. FROM {$db_prefix}log_errors");
  1313. list($totalActions) = smf_mysql_fetch_row($request);
  1314. smf_mysql_free_result($request);
  1315. $_GET['m'] = !empty($_GET['m']) ? (int) $_GET['m'] : '0';
  1316. $step_progress['total'] = $totalActions;
  1317. $step_progress['current'] = $_GET['m'];
  1318. while ($_GET['m'] < $totalActions)
  1319. {
  1320. nextSubStep($substep);
  1321. $request = upgrade_query("
  1322. SELECT id_error, message, file, line
  1323. FROM {$db_prefix}log_errors
  1324. LIMIT $_GET[m], 500");
  1325. while($row = smf_mysql_fetch_assoc($request))
  1326. {
  1327. preg_match('~<br />(%1\$s: )?([\w\. \\\\/\-_:]+)<br />(%2\$s: )?([\d]+)~', $row['message'], $matches);
  1328. if (!empty($matches[2]) && !empty($matches[4]) && empty($row['file']) && empty($row['line']))
  1329. {
  1330. $row['file'] = addslashes(str_replace('\\', '/', $matches[2]));
  1331. $row['line'] = (int) $matches[4];
  1332. $row['message'] = addslashes(preg_replace('~<br />(%1\$s: )?([\w\. \\\\/\-_:]+)<br />(%2\$s: )?([\d]+)~', '', $row['message']));
  1333. }
  1334. else
  1335. continue;
  1336. upgrade_query("
  1337. UPDATE {$db_prefix}log_errors
  1338. SET file = SUBSTRING('$row[file]', 1, 255),
  1339. line = $row[line],
  1340. message = SUBSTRING('$row[message]', 1, 65535)
  1341. WHERE id_error = $row[id_error]
  1342. LIMIT 1");
  1343. }
  1344. $_GET['m'] += 500;
  1345. $step_progress['current'] = $_GET['m'];
  1346. }
  1347. unset($_GET['m']);
  1348. ---}
  1349. ---#
  1350. /******************************************************************************/
  1351. --- Adding Scheduled Tasks Data.
  1352. /******************************************************************************/
  1353. ---# Creating Scheduled Task Table...
  1354. CREATE TABLE IF NOT EXISTS {$db_prefix}scheduled_tasks (
  1355. id_task smallint(5) NOT NULL auto_increment,
  1356. next_time int(10) NOT NULL default '0',
  1357. time_offset int(10) NOT NULL default '0',
  1358. time_regularity smallint(5) NOT NULL default '0',
  1359. time_unit varchar(1) NOT NULL default 'h',
  1360. disabled tinyint(3) NOT NULL default '0',
  1361. task varchar(24) NOT NULL default '',
  1362. PRIMARY KEY (id_task),
  1363. KEY next_time (next_time),
  1364. KEY disabled (disabled),
  1365. UNIQUE task (task)
  1366. ) ENGINE=MyISAM{$db_collation};
  1367. ---#
  1368. ---# Populating Scheduled Task Table...
  1369. INSERT IGNORE INTO {$db_prefix}scheduled_tasks
  1370. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  1371. VALUES
  1372. (0, 0, 2, 'h', 0, 'approval_notification'),
  1373. (0, 0, 7, 'd', 0, 'auto_optimize'),
  1374. (0, 60, 1, 'd', 0, 'daily_maintenance'),
  1375. (0, 0, 1, 'd', 0, 'daily_digest'),
  1376. (0, 0, 1, 'w', 0, 'weekly_digest'),
  1377. (0, 0, 1, 'd', 1, 'birthdayemails'),
  1378. (0, 120, 1, 'd', 0, 'paid_subscriptions');
  1379. ---#
  1380. ---# Adding the simple machines scheduled task.
  1381. ---{
  1382. // Randomise the time.
  1383. $randomTime = 82800 + rand(0, 86399);
  1384. upgrade_query("
  1385. INSERT IGNORE INTO {$db_prefix}scheduled_tasks
  1386. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  1387. VALUES
  1388. (0, {$randomTime}, 1, 'd', 0, 'fetchSMfiles')");
  1389. ---}
  1390. ---#
  1391. ---# Deleting old scheduled task items...
  1392. DELETE FROM {$db_prefix}scheduled_tasks
  1393. WHERE task = 'clean_cache';
  1394. ---#
  1395. ---# Moving auto optimise settings to scheduled task...
  1396. ---{
  1397. if (!isset($modSettings['next_task_time']) && isset($modSettings['autoOptLastOpt']))
  1398. {
  1399. // Try move over the regularity...
  1400. if (isset($modSettings['autoOptDatabase']))
  1401. {
  1402. $disabled = empty($modSettings['autoOptDatabase']) ? 1 : 0;
  1403. $regularity = $disabled ? 7 : $modSettings['autoOptDatabase'];
  1404. $next_time = $modSettings['autoOptLastOpt'] + 3600 * 24 * $modSettings['autoOptDatabase'];
  1405. // Update the task accordingly.
  1406. upgrade_query("
  1407. UPDATE {$db_prefix}scheduled_tasks
  1408. SET disabled = $disabled, time_regularity = $regularity, next_time = $next_time
  1409. WHERE task = 'auto_optimize'");
  1410. }
  1411. // Delete the old settings!
  1412. upgrade_query("
  1413. DELETE FROM {$db_prefix}settings
  1414. WHERE VARIABLE IN ('autoOptLastOpt', 'autoOptDatabase')");
  1415. }
  1416. ---}
  1417. ---#
  1418. ---# Creating Scheduled Task Log Table...
  1419. CREATE TABLE IF NOT EXISTS {$db_prefix}log_scheduled_tasks (
  1420. id_log mediumint(8) NOT NULL auto_increment,
  1421. id_task smallint(5) NOT NULL default '0',
  1422. time_run int(10) NOT NULL default '0',
  1423. time_taken float NOT NULL default '0',
  1424. PRIMARY KEY (id_log)
  1425. ) ENGINE=MyISAM{$db_collation};
  1426. ---#
  1427. ---# Adding new scheduled task setting...
  1428. ---{
  1429. if (!isset($modSettings['next_task_time']))
  1430. {
  1431. upgrade_query("
  1432. INSERT INTO {$db_prefix}settings
  1433. (variable, value)
  1434. VALUES
  1435. ('next_task_time', '0')");
  1436. }
  1437. ---}
  1438. ---#
  1439. ---# Setting the birthday email template if not set...
  1440. ---{
  1441. if (!isset($modSettings['birthday_email']))
  1442. {
  1443. upgrade_query("
  1444. INSERT INTO {$db_prefix}settings
  1445. (variable, value)
  1446. VALUES
  1447. ('birthday_email', 'happy_birthday')");
  1448. }
  1449. ---}
  1450. ---#
  1451. /******************************************************************************/
  1452. --- Adding permission profiles for boards.
  1453. /******************************************************************************/
  1454. ---# Creating "permission_profiles" table...
  1455. CREATE TABLE IF NOT EXISTS {$db_prefix}permission_profiles (
  1456. id_profile smallint(5) NOT NULL auto_increment,
  1457. profile_name varchar(255) NOT NULL default '',
  1458. PRIMARY KEY (id_profile)
  1459. ) ENGINE=MyISAM{$db_collation};
  1460. ---#
  1461. ---# Adding profile columns to boards table...
  1462. ALTER TABLE {$db_prefix}boards
  1463. ADD id_profile smallint(5) unsigned NOT NULL default '1' AFTER member_groups;
  1464. ---#
  1465. ---# Adding profile columns to board permission table...
  1466. ALTER TABLE {$db_prefix}board_permissions
  1467. ADD id_profile smallint(5) unsigned NOT NULL default '1' AFTER id_group;
  1468. ALTER TABLE {$db_prefix}board_permissions
  1469. DROP PRIMARY KEY;
  1470. ALTER TABLE {$db_prefix}board_permissions
  1471. ADD PRIMARY KEY (id_group, id_profile, permission);
  1472. ---#
  1473. ---# Cleaning up some 2.0 Beta 1 permission profile bits...
  1474. ---{
  1475. $request = upgrade_query("
  1476. SELECT id_profile
  1477. FROM {$db_prefix}permission_profiles
  1478. WHERE profile_name = ''");
  1479. $profiles = array();
  1480. while ($row = smf_mysql_fetch_assoc($request))
  1481. $profiles[] = $row['id_profile'];
  1482. smf_mysql_free_result($request);
  1483. if (!empty($profiles))
  1484. {
  1485. $request = upgrade_query("
  1486. SELECT id_profile, name
  1487. FROM {$db_prefix}boards
  1488. WHERE id_profile IN (" . implode(',', $profiles) . ")");
  1489. $done_ids = array();
  1490. while ($row = smf_mysql_fetch_assoc($request))
  1491. {
  1492. if (isset($done_ids[$row['id_profile']]))
  1493. continue;
  1494. $done_ids[$row['id_profile']] = true;
  1495. $row['name'] = smf_mysql_real_escape_string($row['name']);
  1496. upgrade_query("
  1497. UPDATE {$db_prefix}permission_profiles
  1498. SET profile_name = '$row[name]'
  1499. WHERE id_profile = $row[id_profile]");
  1500. }
  1501. smf_mysql_free_result($request);
  1502. }
  1503. ---}
  1504. ---#
  1505. ---# Migrating old board profiles to profile system
  1506. ---{
  1507. // Doing this twice would be awful!
  1508. $request = upgrade_query("
  1509. SELECT COUNT(*)
  1510. FROM {$db_prefix}permission_profiles");
  1511. list ($profileCount) = smf_mysql_fetch_row($request);
  1512. smf_mysql_free_result($request);
  1513. if ($profileCount == 0)
  1514. {
  1515. // Everything starts off invalid.
  1516. upgrade_query("
  1517. UPDATE {$db_prefix}board_permissions
  1518. SET id_profile = 0");
  1519. // Insert a boat load of default profile permissions.
  1520. upgrade_query("
  1521. INSERT INTO {$db_prefix}permission_profiles
  1522. (id_profile, profile_name)
  1523. VALUES
  1524. (1, 'default'),
  1525. (2, 'no_polls'),
  1526. (3, 'reply_only'),
  1527. (4, 'read_only')");
  1528. // Update the default permissions, this is easy!
  1529. upgrade_query("
  1530. UPDATE {$db_prefix}board_permissions
  1531. SET id_profile = 1
  1532. WHERE id_board = 0");
  1533. // Load all the other permissions
  1534. $request = upgrade_query("
  1535. SELECT id_board, id_group, permission, add_deny
  1536. FROM {$db_prefix}board_permissions
  1537. WHERE id_profile = 0");
  1538. $all_perms = array();
  1539. while ($row = smf_mysql_fetch_assoc($request))
  1540. $all_perms[$row['id_board']][$row['id_group']][$row['permission']] = $row['add_deny'];
  1541. smf_mysql_free_result($request);
  1542. // 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!
  1543. $request = upgrade_query("
  1544. SELECT id_board, name, permission_mode
  1545. FROM {$db_prefix}boards");
  1546. $board_updates = array();
  1547. while ($row = smf_mysql_fetch_assoc($request))
  1548. {
  1549. $row['name'] = addslashes($row['name']);
  1550. // Is it a truely local permission board? If so this is a new profile!
  1551. if ($row['permission_mode'] == 1)
  1552. {
  1553. // I know we could cache this, but I think we need to be practical - this is slow but guaranteed to work.
  1554. upgrade_query("
  1555. INSERT INTO {$db_prefix}permission_profiles
  1556. (profile_name)
  1557. VALUES
  1558. ('$row[name]')");
  1559. $board_updates[smf_mysql_insert_id()][] = $row['id_board'];
  1560. }
  1561. // Otherwise, dear god, this is an old school "simple" permission...
  1562. elseif ($row['permission_mode'] > 1 && $row['permission_mode'] < 5)
  1563. {
  1564. $board_updates[$row['permission_mode']][] = $row['id_board'];
  1565. }
  1566. // Otherwise this is easy. It becomes default.
  1567. else
  1568. $board_updates[1][] = $row['id_board'];
  1569. }
  1570. smf_mysql_free_result($request);
  1571. // Update the board tables.
  1572. foreach ($board_updates as $profile => $boards)
  1573. {
  1574. if (empty($boards))
  1575. continue;
  1576. $boards = implode(',', $boards);
  1577. upgrade_query("
  1578. UPDATE {$db_prefix}boards
  1579. SET id_profile = $profile
  1580. WHERE id_board IN ($boards)");
  1581. // If it's a custom profile then update this too.
  1582. if ($profile > 4)
  1583. upgrade_query("
  1584. UPDATE {$db_prefix}board_permissions
  1585. SET id_profile = $profile
  1586. WHERE id_board IN ($boards)
  1587. AND id_profile = 0");
  1588. }
  1589. // Just in case we have any random permissions that didn't have boards.
  1590. upgrade_query("
  1591. DELETE FROM {$db_prefix}board_permissions
  1592. WHERE id_profile = 0");
  1593. }
  1594. ---}
  1595. ---#
  1596. ---# Removing old board permissions column...
  1597. ALTER TABLE {$db_prefix}board_permissions
  1598. DROP COLUMN id_board;
  1599. ---#
  1600. ---# Check the predefined profiles all have the right permissions.
  1601. ---{
  1602. // What are all the permissions people can have.
  1603. $mod_permissions = array(
  1604. 'moderate_board', 'post_new', 'post_reply_own', 'post_reply_any', 'poll_post', 'poll_add_any',
  1605. 'poll_remove_any', 'poll_view', 'poll_vote', 'poll_lock_any', 'poll_edit_any', 'report_any',
  1606. 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own', 'make_sticky',
  1607. 'lock_any', 'remove_any', 'move_any', 'merge_any', 'split_any', 'delete_any', 'modify_any', 'approve_posts',
  1608. 'post_attachment', 'view_attachments', 'post_unapproved_replies_any', 'post_unapproved_replies_own',
  1609. 'post_unapproved_attachments', 'post_unapproved_topics',
  1610. );
  1611. $no_poll_reg = array(
  1612. 'post_new', 'post_reply_own', 'post_reply_any', 'poll_view', 'poll_vote', 'report_any',
  1613. 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own',
  1614. 'post_attachment', 'view_attachments', 'remove_own', 'post_unapproved_replies_any', 'post_unapproved_replies_own',
  1615. 'post_unapproved_attachments', 'post_unapproved_topics',
  1616. );
  1617. $reply_only_reg = array(
  1618. 'post_reply_own', 'post_reply_any', 'poll_view', 'poll_vote', 'report_any',
  1619. 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own',
  1620. 'post_attachment', 'view_attachments', 'remove_own', 'post_unapproved_replies_any', 'post_unapproved_replies_own',
  1621. 'post_unapproved_attachments',
  1622. );
  1623. $read_only_reg = array(
  1624. 'poll_view', 'poll_vote', 'report_any', 'send_topic', 'mark_any_notify', 'mark_notify', 'view_attachments',
  1625. );
  1626. // Clear all the current predefined profiles.
  1627. upgrade_query("
  1628. DELETE FROM {$db_prefix}board_permissions
  1629. WHERE id_profile IN (2,3,4)");
  1630. // Get all the membergroups - cheating to use the fact id_group = 1 exists to get a group of 0.
  1631. $request = upgrade_query("
  1632. SELECT IF(id_group = 1, 0, id_group) AS id_group
  1633. FROM {$db_prefix}membergroups
  1634. WHERE id_group != 0
  1635. AND min_posts = -1");
  1636. $inserts = array();
  1637. while ($row = smf_mysql_fetch_assoc($request))
  1638. {
  1639. if ($row['id_group'] == 2 || $row['id_group'] == 3)
  1640. {
  1641. foreach ($mod_permissions as $permission)
  1642. {
  1643. $inserts[] = "($row[id_group], 2, '$permission')";
  1644. $inserts[] = "($row[id_group], 3, '$permission')";
  1645. $inserts[] = "($row[id_group], 4, '$permission')";
  1646. }
  1647. }
  1648. else
  1649. {
  1650. foreach ($no_poll_reg as $permission)
  1651. $inserts[] = "($row[id_group], 2, '$permission')";
  1652. foreach ($reply_only_reg as $permission)
  1653. $inserts[] = "($row[id_group], 3, '$permission')";
  1654. foreach ($read_only_reg as $permission)
  1655. $inserts[] = "($row[id_group], 4, '$permission')";
  1656. }
  1657. }
  1658. smf_mysql_free_result($request);
  1659. upgrade_query("
  1660. INSERT INTO {$db_prefix}board_permissions
  1661. (id_group, id_profile, permission)
  1662. VALUES (-1, 2, 'poll_view'),
  1663. (-1, 3, 'poll_view'),
  1664. (-1, 4, 'poll_view'),
  1665. " . implode(', ', $inserts));
  1666. ---}
  1667. ---#
  1668. ---# Adding inherited permissions...
  1669. ALTER TABLE {$db_prefix}membergroups
  1670. ADD id_parent smallint(5) NOT NULL default '-2';
  1671. ---#
  1672. ---# Make sure admins and moderators don't inherit...
  1673. UPDATE {$db_prefix}membergroups
  1674. SET id_parent = -2
  1675. WHERE id_group = 1
  1676. OR id_group = 3;
  1677. ---#
  1678. ---# Deleting old permission settings...
  1679. DELETE FROM {$db_prefix}settings
  1680. WHERE VARIABLE IN ('permission_enable_by_board', 'autoOptDatabase');
  1681. ---#
  1682. ---# Removing old permission_mode column...
  1683. ALTER TABLE {$db_prefix}boards
  1684. DROP COLUMN permission_mode;
  1685. ---#
  1686. /******************************************************************************/
  1687. --- Adding Some Additional Functionality.
  1688. /******************************************************************************/
  1689. ---# Adding column to hold the boards being ignored ...
  1690. ALTER TABLE {$db_prefix}members
  1691. ADD ignore_boards text NOT NULL;
  1692. ---#
  1693. ---# Purge flood control ...
  1694. DELETE FROM {$db_prefix}log_floodcontrol;
  1695. ---#
  1696. ---# Adding advanced flood control ...
  1697. ALTER TABLE {$db_prefix}log_floodcontrol
  1698. ADD log_type varchar(8) NOT NULL default 'post';
  1699. ---#
  1700. ---# Sorting out flood control keys ...
  1701. ALTER TABLE {$db_prefix}log_floodcontrol
  1702. DROP PRIMARY KEY,
  1703. ADD PRIMARY KEY (ip(16), log_type(8));
  1704. ---#
  1705. ---# Adding guest voting ...
  1706. ALTER TABLE {$db_prefix}polls
  1707. ADD guest_vote tinyint(3) NOT NULL default '0';
  1708. DELETE FROM {$db_prefix}log_polls
  1709. WHERE id_member < 0;
  1710. ALTER TABLE {$db_prefix}log_polls
  1711. DROP PRIMARY KEY;
  1712. ALTER TABLE {$db_prefix}log_polls
  1713. ADD INDEX id_poll (id_poll, id_member, id_choice);
  1714. ---#
  1715. ---# Implementing admin feature toggles.
  1716. ---{
  1717. if (!isset($modSettings['admin_features']))
  1718. {
  1719. // Work out what they used to have enabled.
  1720. if (!empty($modSettings['karmaMode']))
  1721. $enabled_features[] = 'k';
  1722. $enabled_features = implode(',', $enabled_features);
  1723. upgrade_query("
  1724. INSERT INTO {$db_prefix}settings
  1725. (variable, value)
  1726. VALUES
  1727. ('admin_features', '$enabled_features')");
  1728. }
  1729. ---}
  1730. ---#
  1731. ---# Adding advanced password brute force protection to "members" table...
  1732. ALTER TABLE {$db_prefix}members
  1733. ADD passwd_flood varchar(12) NOT NULL default '';
  1734. ---#
  1735. /******************************************************************************/
  1736. --- Adding some columns to moderation log
  1737. /******************************************************************************/
  1738. ---# Add the columns and the keys to log_actions ...
  1739. ALTER TABLE {$db_prefix}log_actions
  1740. ADD id_board smallint(5) unsigned NOT NULL default '0',
  1741. ADD id_topic mediumint(8) unsigned NOT NULL default '0',
  1742. ADD id_msg int(10) unsigned NOT NULL default '0',
  1743. ADD KEY id_board (id_board),
  1744. ADD KEY id_msg (id_msg);
  1745. ---#
  1746. ---# Add the user log...
  1747. ALTER TABLE {$db_prefix}log_actions
  1748. ADD id_log tinyint(3) unsigned NOT NULL default '1',
  1749. ADD KEY id_log (id_log);
  1750. ---#
  1751. ---# Update the information already in log_actions
  1752. ---{
  1753. $request = upgrade_query("
  1754. SELECT COUNT(*)
  1755. FROM {$db_prefix}log_actions");
  1756. list($totalActions) = smf_mysql_fetch_row($request);
  1757. smf_mysql_free_result($request);
  1758. $_GET['m'] = !empty($_GET['m']) ? (int) $_GET['m'] : '0';
  1759. $step_progress['total'] = $totalActions;
  1760. $step_progress['current'] = $_GET['m'];
  1761. while ($_GET['m'] < $totalActions)
  1762. {
  1763. nextSubStep($substep);
  1764. $mrequest = upgrade_query("
  1765. SELECT id_action, extra, id_board, id_topic, id_msg
  1766. FROM {$db_prefix}log_actions
  1767. LIMIT $_GET[m], 500");
  1768. while ($row = smf_mysql_fetch_assoc($mrequest))
  1769. {
  1770. if (!empty($row['id_board']) || !empty($row['id_topic']) || !empty($row['id_msg']))
  1771. continue;
  1772. $row['extra'] = @unserialize($row['extra']);
  1773. // Corrupt?
  1774. $row['extra'] = is_array($row['extra']) ? $row['extra'] : array();
  1775. if (!empty($row['extra']['board']))
  1776. {
  1777. $board_id = (int) $row['extra']['board'];
  1778. unset($row['extra']['board']);
  1779. }
  1780. else
  1781. $board_id = '0';
  1782. if (!empty($row['extra']['board_to']) && empty($board_id))
  1783. {
  1784. $board_id = (int) $row['extra']['board_to'];
  1785. unset($row['extra']['board_to']);
  1786. }
  1787. if (!empty($row['extra']['topic']))
  1788. {
  1789. $topic_id = (int) $row['extra']['topic'];
  1790. unset($row['extra']['topic']);
  1791. if (empty($board_id))
  1792. {
  1793. $trequest = upgrade_query("
  1794. SELECT id_board
  1795. FROM {$db_prefix}topics
  1796. WHERE id_topic=$topic_id
  1797. LIMIT 1");
  1798. if (smf_mysql_num_rows($trequest))
  1799. list($board_id) = smf_mysql_fetch_row($trequest);
  1800. smf_mysql_free_result($trequest);
  1801. }
  1802. }
  1803. else
  1804. $topic_id = '0';
  1805. if(!empty($row['extra']['message']))
  1806. {
  1807. $msg_id = (int) $row['extra']['message'];
  1808. unset($row['extra']['message']);
  1809. if (empty($topic_id) || empty($board_id))
  1810. {
  1811. $trequest = upgrade_query("
  1812. SELECT id_board, id_topic
  1813. FROM {$db_prefix}messages
  1814. WHERE id_msg=$msg_id
  1815. LIMIT 1");
  1816. if (smf_mysql_num_rows($trequest))
  1817. list($board_id, $topic_id) = smf_mysql_fetch_row($trequest);
  1818. smf_mysql_free_result($trequest);
  1819. }
  1820. }
  1821. else
  1822. $msg_id = '0';
  1823. $row['extra'] = addslashes(serialize($row['extra']));
  1824. 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]");
  1825. }
  1826. $_GET['m'] += 500;
  1827. $step_progress['current'] = $_GET['m'];
  1828. }
  1829. unset($_GET['m']);
  1830. ---}
  1831. ---#
  1832. /******************************************************************************/
  1833. --- Create a repository for the javascript files from Simple Machines...
  1834. /******************************************************************************/
  1835. ---# Creating repository table ...
  1836. CREATE TABLE IF NOT EXISTS {$db_prefix}admin_info_files (
  1837. id_file tinyint(4) unsigned NOT NULL auto_increment,
  1838. filename varchar(255) NOT NULL default '',
  1839. path varchar(255) NOT NULL default '',
  1840. parameters varchar(255) NOT NULL default '',
  1841. data text NOT NULL,
  1842. filetype varchar(255) NOT NULL default '',
  1843. PRIMARY KEY (id_file),
  1844. KEY filename (filename(30))
  1845. ) ENGINE=MyISAM{$db_collation};
  1846. ---#
  1847. ---# Add in the files to get from Simple Machines...
  1848. INSERT IGNORE INTO {$db_prefix}admin_info_files
  1849. (id_file, filename, path, parameters)
  1850. VALUES
  1851. (1, 'current-version.js', '/smf/', 'version=%3$s'),
  1852. (2, 'detailed-version.js', '/smf/', 'language=%1$s&version=%3$s'),
  1853. (3, 'latest-news.js', '/smf/', 'language=%1$s&format=%2$s'),
  1854. (4, 'latest-packages.js', '/smf/', 'language=%1$s&version=%3$s'),
  1855. (5, 'latest-smileys.js', '/smf/', 'language=%1$s&version=%3$s'),
  1856. (6, 'latest-themes.js', '/smf/', 'language=%1$s&version=%3$s');
  1857. ---#
  1858. ---# Ensure that the table has the filetype column
  1859. ALTER TABLE {$db_prefix}admin_info_files
  1860. ADD filetype varchar(255) NOT NULL default '';
  1861. ---#
  1862. ---# Set the filetype for the files
  1863. UPDATE {$db_prefix}admin_info_files
  1864. SET filetype='text/javascript'
  1865. WHERE id_file IN (1,2,3,4,5,6,7);
  1866. ---#
  1867. ---# Ensure that the files from Simple Machines get updated
  1868. UPDATE {$db_prefix}scheduled_tasks
  1869. SET next_time = UNIX_TIMESTAMP()
  1870. WHERE id_task = 7
  1871. LIMIT 1;
  1872. ---#
  1873. /******************************************************************************/
  1874. --- Adding new personal messaging functionality.
  1875. /******************************************************************************/
  1876. ---# Adding personal message rules table...
  1877. CREATE TABLE IF NOT EXISTS {$db_prefix}pm_rules (
  1878. id_rule int(10) unsigned NOT NULL auto_increment,
  1879. id_member int(10) unsigned NOT NULL default '0',
  1880. rule_name varchar(60) NOT NULL,
  1881. criteria text NOT NULL,
  1882. actions text NOT NULL,
  1883. delete_pm tinyint(3) unsigned NOT NULL default '0',
  1884. is_or tinyint(3) unsigned NOT NULL default '0',
  1885. PRIMARY KEY (id_rule),
  1886. KEY id_member (id_member),
  1887. KEY delete_pm (delete_pm)
  1888. ) ENGINE=MyISAM{$db_collation};
  1889. ---#
  1890. ---# Adding new message status columns...
  1891. ALTER TABLE {$db_prefix}members
  1892. ADD COLUMN new_pm tinyint(3) NOT NULL default '0';
  1893. ALTER TABLE {$db_prefix}members
  1894. ADD COLUMN pm_prefs mediumint(8) NOT NULL default '0';
  1895. ALTER TABLE {$db_prefix}pm_recipients
  1896. ADD COLUMN is_new tinyint(3) NOT NULL default '0';
  1897. ---#
  1898. ---# Set the new status to be correct....
  1899. ---{
  1900. // Don't do this twice!
  1901. if (@$modSettings['smfVersion'] < '2.0')
  1902. {
  1903. // Set all unread messages as new.
  1904. upgrade_query("
  1905. UPDATE {$db_prefix}pm_recipients
  1906. SET is_new = 1
  1907. WHERE is_read = 0");
  1908. // Also set members to have a new pm if they have any unread.
  1909. upgrade_query("
  1910. UPDATE {$db_prefix}members
  1911. SET new_pm = 1
  1912. WHERE unread_messages > 0");
  1913. }
  1914. ---}
  1915. ---#
  1916. ---# Adding personal message tracking column...
  1917. ALTER TABLE {$db_prefix}personal_messages
  1918. ADD id_pm_head int(10) unsigned default '0' NOT NULL AFTER id_pm,
  1919. ADD INDEX id_pm_head (id_pm_head);
  1920. ---#
  1921. ---# Adding personal message tracking column...
  1922. UPDATE {$db_prefix}personal_messages
  1923. SET id_pm_head = id_pm
  1924. WHERE id_pm_head = 0;
  1925. ---#
  1926. /******************************************************************************/
  1927. --- Adding Open ID support.
  1928. /******************************************************************************/
  1929. ---# Adding Open ID Assocation table...
  1930. CREATE TABLE IF NOT EXISTS {$db_prefix}openid_assoc (
  1931. server_url text NOT NULL,
  1932. handle varchar(255) NOT NULL default '',
  1933. secret text NOT NULL,
  1934. issued int(10) NOT NULL default '0',
  1935. expires int(10) NOT NULL default '0',
  1936. assoc_type varchar(64) NOT NULL,
  1937. PRIMARY KEY (server_url(125), handle(125)),
  1938. KEY expires (expires)
  1939. ) ENGINE=MyISAM{$db_collation};
  1940. ---#
  1941. ---# Adding column to hold Open ID URL...
  1942. ALTER TABLE {$db_prefix}members
  1943. ADD openid_uri text NOT NULL;
  1944. ---#
  1945. /******************************************************************************/
  1946. --- Adding paid subscriptions.
  1947. /******************************************************************************/
  1948. ---# Creating subscriptions table...
  1949. CREATE TABLE IF NOT EXISTS {$db_prefix}subscriptions(
  1950. id_subscribe mediumint(8) unsigned NOT NULL auto_increment,
  1951. name varchar(60) NOT NULL default '',
  1952. description varchar(255) NOT NULL default '',
  1953. cost text NOT NULL,
  1954. length varchar(6) NOT NULL default '',
  1955. id_group smallint(5) NOT NULL default '0',
  1956. add_groups varchar(40) NOT NULL default '',
  1957. active tinyint(3) NOT NULL default '1',
  1958. repeatable tinyint(3) NOT NULL default '0',
  1959. allow_partial tinyint(3) NOT NULL default '0',
  1960. reminder tinyint(3) NOT NULL default '0',
  1961. email_complete text NOT NULL,
  1962. PRIMARY KEY (id_subscribe),
  1963. KEY active (active)
  1964. ) ENGINE=MyISAM{$db_collation};
  1965. ---#
  1966. ---# Creating log_subscribed table...
  1967. CREATE TABLE IF NOT EXISTS {$db_prefix}log_subscribed(
  1968. id_sublog int(10) unsigned NOT NULL auto_increment,
  1969. id_subscribe mediumint(8) unsigned NOT NULL default '0',
  1970. id_member int(10) NOT NULL default '0',
  1971. old_id_group smallint(5) NOT NULL default '0',
  1972. start_time int(10) NOT NULL default '0',
  1973. end_time int(10) NOT NULL default '0',
  1974. status tinyint(3) NOT NULL default '0',
  1975. payments_pending tinyint(3) NOT NULL default '0',
  1976. pending_details text NOT NULL,
  1977. reminder_sent tinyint(3) NOT NULL default '0',
  1978. vendor_ref varchar(255) NOT NULL default '',
  1979. PRIMARY KEY (id_sublog),
  1980. UNIQUE KEY id_subscribe (id_subscribe, id_member),
  1981. KEY end_time (end_time),
  1982. KEY reminder_sent (reminder_sent),
  1983. KEY payments_pending (payments_pending),
  1984. KEY id_member (id_member)
  1985. ) ENGINE=MyISAM{$db_collation};
  1986. ---#
  1987. ---# Clean up any pre-2.0 mod settings.
  1988. UPDATE {$db_prefix}settings
  1989. SET variable = 'paid_currency_code'
  1990. WHERE variable = 'currency_code';
  1991. UPDATE {$db_prefix}settings
  1992. SET variable = 'paid_currency_symbol'
  1993. WHERE variable = 'currency_symbol';
  1994. DELETE FROM {$db_prefix}settings
  1995. WHERE variable = 'currency_code'
  1996. OR variable = 'currency_symbol';
  1997. ---#
  1998. ---# Clean up any pre-2.0 mod settings (part 2).
  1999. ---{
  2000. $request = upgrade_query("
  2001. SHOW COLUMNS
  2002. FROM {$db_prefix}subscriptions");
  2003. $new_cols = array('repeatable', 'reminder', 'email_complete', 'allow_partial');
  2004. $new_cols = array_flip($new_cols);
  2005. while ($request && $row = smf_mysql_fetch_row($request))
  2006. {
  2007. $row[0] = strtolower($row[0]);
  2008. if (isset($new_cols[$row[0]]))
  2009. unset($new_cols[$row[0]]);
  2010. }
  2011. if ($request)
  2012. smf_mysql_free_result($request);
  2013. if (isset($new_cols['repeatable']))
  2014. upgrade_query("
  2015. ALTER TABLE {$db_prefix}subscriptions
  2016. ADD COLUMN Repeatable tinyint(3) NOT NULL default '0'");
  2017. if (isset($new_cols['reminder']))
  2018. upgrade_query("
  2019. ALTER TABLE {$db_prefix}subscriptions
  2020. ADD COLUMN reminder tinyint(3) NOT NULL default '0'");
  2021. if (isset($new_cols['email_complete']))
  2022. upgrade_query("
  2023. ALTER TABLE {$db_prefix}subscriptions
  2024. ADD COLUMN email_complete text NOT NULL");
  2025. if (isset($new_cols['allowpartial']))
  2026. upgrade_query("
  2027. ALTER TABLE {$db_prefix}subscriptions
  2028. ADD COLUMN allow_partial tinyint(3) NOT NULL default '0'");
  2029. $request = upgrade_query("
  2030. SHOW COLUMNS
  2031. FROM {$db_prefix}log_subscribed");
  2032. $new_cols = array('reminder_sent', 'vendor_ref', 'payments_pending', 'pending_details');
  2033. $new_cols = array_flip($new_cols);
  2034. while ($request && $row = smf_mysql_fetch_row($request))
  2035. {
  2036. if (isset($new_cols[$row[0]]))
  2037. unset($new_cols[$row[0]]);
  2038. }
  2039. if ($request)
  2040. smf_mysql_free_result($request);
  2041. if (isset($new_cols['reminder_sent']))
  2042. upgrade_query("
  2043. ALTER TABLE {$db_prefix}log_subscribed
  2044. ADD COLUMN reminder_sent tinyint(3) NOT NULL default '0'");
  2045. if (isset($new_cols['vendor_ref']))
  2046. upgrade_query("
  2047. ALTER TABLE {$db_prefix}log_subscribed
  2048. ADD COLUMN vendor_ref varchar(255) NOT NULL default ''");
  2049. if (isset($new_cols['payments_pending']))
  2050. upgrade_query("
  2051. ALTER TABLE {$db_prefix}log_subscribed
  2052. ADD COLUMN payments_pending tinyint(3) NOT NULL default '0'");
  2053. if (isset($new_cols['pending_details']))
  2054. {
  2055. upgrade_query("
  2056. UPDATE {$db_prefix}log_subscribed
  2057. SET status = 0
  2058. WHERE status = 1");
  2059. upgrade_query("
  2060. UPDATE {$db_prefix}log_subscribed
  2061. SET status = 1
  2062. WHERE status = 2");
  2063. upgrade_query("
  2064. ALTER TABLE {$db_prefix}log_subscribed
  2065. ADD COLUMN pending_details text NOT NULL");
  2066. }
  2067. ---}
  2068. ---#
  2069. ---# Confirming paid subscription keys are in place ...
  2070. ALTER TABLE {$db_prefix}log_subscribed
  2071. ADD KEY reminder_sent (reminder_sent),
  2072. ADD KEY end_time (end_time),
  2073. ADD KEY payments_pending (payments_pending),
  2074. ADD KEY status (status);
  2075. ---#
  2076. /******************************************************************************/
  2077. --- Adding weekly maintenance task.
  2078. /******************************************************************************/
  2079. ---# Adding scheduled task...
  2080. 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');
  2081. ---#
  2082. /******************************************************************************/
  2083. --- Adding log pruning.
  2084. /******************************************************************************/
  2085. ---# Adding pruning option...
  2086. INSERT IGNORE INTO {$db_prefix}settings (variable, value) VALUES ('pruningOptions', '30,180,180,180,30,0');
  2087. ---#
  2088. /******************************************************************************/
  2089. --- Adding restore topic from recycle.
  2090. /******************************************************************************/
  2091. ---# Adding restore from recycle feature...
  2092. ALTER TABLE {$db_prefix}topics
  2093. ADD COLUMN id_previous_board smallint(5) NOT NULL default '0',
  2094. ADD COLUMN id_previous_topic mediumint(8) NOT NULL default '0';
  2095. ---#
  2096. /******************************************************************************/
  2097. --- Providing more room for apf options.
  2098. /******************************************************************************/
  2099. ---# Changing field_options column to a larger field type...
  2100. ALTER TABLE {$db_prefix}custom_fields
  2101. CHANGE field_options field_options text NOT NULL;
  2102. ---#
  2103. /******************************************************************************/
  2104. --- Providing more room for ignoring boards.
  2105. /******************************************************************************/
  2106. ---# Changing ignore_boards column to a larger field type...
  2107. ALTER TABLE {$db_prefix}members
  2108. CHANGE ignore_boards ignore_boards text NOT NULL;
  2109. ---#
  2110. /******************************************************************************/
  2111. --- Allow for longer calendar event/holiday titles.
  2112. /******************************************************************************/
  2113. ---# Changing event title column to a larger field type...
  2114. ALTER TABLE {$db_prefix}calendar
  2115. CHANGE title title varchar(255) NOT NULL default '';
  2116. ---#
  2117. ---# Changing holidays title column to a larger field type...
  2118. ALTER TABLE {$db_prefix}calendar_holidays
  2119. CHANGE title title varchar(255) NOT NULL default '';
  2120. ---#
  2121. /******************************************************************************/
  2122. --- Adding extra columns to polls.
  2123. /******************************************************************************/
  2124. ---# Adding reset poll timestamp and guest voters counter...
  2125. ALTER TABLE {$db_prefix}polls
  2126. ADD COLUMN reset_poll int(10) unsigned NOT NULL default '0' AFTER guest_vote,
  2127. ADD COLUMN num_guest_voters int(10) unsigned NOT NULL default '0' AFTER guest_vote;
  2128. ---#
  2129. ---# Fixing guest voter tallys on existing polls...
  2130. ---{
  2131. $request = upgrade_query("
  2132. SELECT p.id_poll, count(lp.id_member) as guest_voters
  2133. FROM {$db_prefix}polls AS p
  2134. LEFT JOIN {$db_prefix}log_polls AS lp ON (lp.id_poll = p.id_poll AND lp.id_member = 0)
  2135. WHERE lp.id_member = 0
  2136. AND p.num_guest_voters = 0
  2137. GROUP BY p.id_poll");
  2138. while ($request && $row = $smcFunc['db_fetch_assoc']($request))
  2139. upgrade_query("
  2140. UPDATE {$db_prefix}polls
  2141. SET num_guest_voters = ". $row['guest_voters']. "
  2142. WHERE id_poll = " . $row['id_poll'] . "
  2143. AND num_guest_voters = 0");
  2144. ---}
  2145. ---#
  2146. /******************************************************************************/
  2147. --- Changing all tinytext columns to varchar(255).
  2148. /******************************************************************************/
  2149. ---# Changing all tinytext columns to varchar(255)...
  2150. ---{
  2151. // The array holding all the changes.
  2152. $nameChanges = array(
  2153. 'admin_info_files' => array(
  2154. 'filename' => 'filename filename varchar(255) NOT NULL default \'\'',
  2155. 'path' => 'path path varchar(255) NOT NULL default \'\'',
  2156. 'parameters' => 'parameters parameters varchar(255) NOT NULL default \'\'',
  2157. 'filetype' => 'filetype filetype varchar(255) NOT NULL default \'\'',
  2158. ),
  2159. 'attachments' => array(
  2160. 'filename' => 'filename filename varchar(255) NOT NULL default \'\'',
  2161. ),
  2162. 'ban_groups' => array(
  2163. 'reason' => 'reason reason varchar(255) NOT NULL default \'\'',
  2164. ),
  2165. 'ban_items' => array(
  2166. 'hostname' => 'hostname hostname varchar(255) NOT NULL default \'\'',
  2167. 'email_address' => 'email_address email_address varchar(255) NOT NULL default \'\'',
  2168. ),
  2169. 'boards' => array(
  2170. 'name' => 'name name varchar(255) NOT NULL default \'\'',
  2171. ),
  2172. 'categories' => array(
  2173. 'name' => 'name name varchar(255) NOT NULL default \'\'',
  2174. ),
  2175. 'custom_fields' => array(
  2176. 'field_desc' => 'field_desc field_desc varchar(255) NOT NULL default \'\'',
  2177. 'mask' => 'mask mask varchar(255) NOT NULL default \'\'',
  2178. 'default_value' => 'default_value default_value varchar(255) NOT NULL default \'\'',
  2179. ),
  2180. 'log_banned' => array(
  2181. 'email' => 'email email varchar(255) NOT NULL default \'\'',
  2182. ),
  2183. 'log_comments' => array(
  2184. 'recipient_name' => 'recipient_name recipient_name varchar(255) NOT NULL default \'\'',
  2185. ),
  2186. 'log_errors' => array(
  2187. 'file' => 'file file varchar(255) NOT NULL default \'\'',
  2188. ),
  2189. 'log_member_notices' => array(
  2190. 'subject' => 'subject subject varchar(255) NOT NULL default \'\'',
  2191. ),
  2192. 'log_packages' => array(
  2193. 'filename' => 'filename filename varchar(255) NOT NULL default \'\'',
  2194. 'package_id' => 'package_id package_id varchar(255) NOT NULL default \'\'',
  2195. 'name' => 'name name varchar(255) NOT NULL default \'\'',
  2196. 'version' => 'version version varchar(255) NOT NULL default \'\'',
  2197. 'member_installed' => 'member_installed member_installed varchar(255) NOT NULL default \'\'',
  2198. 'member_removed' => 'member_removed member_removed varchar(255) NOT NULL default \'\'',
  2199. 'themes_installed' => 'themes_installed themes_installed varchar(255) NOT NULL default \'\'',
  2200. ),
  2201. 'log_reported' => array(
  2202. 'membername' => 'membername membername varchar(255) NOT NULL default \'\'',
  2203. 'subject' => 'subject subject varchar(255) NOT NULL default \'\'',
  2204. ),
  2205. 'log_reported_comments' => array(
  2206. 'membername' => 'membername membername varchar(255) NOT NULL default \'\'',
  2207. 'comment' => 'comment comment varchar(255) NOT NULL default \'\'',
  2208. ),
  2209. 'log_spider_hits' => array(
  2210. 'url' => 'url url varchar(255) NOT NULL default \'\'',
  2211. ),
  2212. 'log_subscribed' => array(
  2213. 'vendor_ref' => 'vendor_ref vendor_ref varchar(255) NOT NULL default \'\'',
  2214. ),
  2215. 'mail_queue' => array(
  2216. 'recipient' => 'recipient recipient varchar(255) NOT NULL default \'\'',
  2217. 'subject' => 'subject subject varchar(255) NOT NULL default \'\'',
  2218. ),
  2219. 'membergroups' => array(
  2220. 'stars' => 'stars stars varchar(255) NOT NULL default \'\'',
  2221. ),
  2222. 'members' => array(
  2223. 'lngfile' => 'lngfile lngfile varchar(255) NOT NULL default \'\'',
  2224. 'real_name' => 'real_name real_name varchar(255) NOT NULL default \'\'',
  2225. 'pm_ignore_list' => 'pm_ignore_list pm_ignore_list varchar(255) NOT NULL default \'\'',
  2226. 'email_address' => 'email_address email_address varchar(255) NOT NULL default \'\'',
  2227. 'personal_text' => 'personal_text personal_text varchar(255) NOT NULL default \'\'',
  2228. 'website_title' => 'website_title website_title varchar(255) NOT NULL default \'\'',
  2229. 'website_url' => 'website_url website_url varchar(255) NOT NULL default \'\'',
  2230. 'location' => 'location location varchar(255) NOT NULL default \'\'',
  2231. 'icq' => 'icq icq varchar(255) NOT NULL default \'\'',
  2232. 'aim' => 'aim aim varchar(255) NOT NULL default \'\'',
  2233. 'msn' => 'msn msn varchar(255) NOT NULL default \'\'',
  2234. 'avatar' => 'avatar avatar varchar(255) NOT NULL default \'\'',
  2235. 'usertitle' => 'usertitle usertitle varchar(255) NOT NULL default \'\'',
  2236. 'member_ip' => 'member_ip member_ip varchar(255) NOT NULL default \'\'',
  2237. 'member_ip2' => 'member_ip2 member_ip2 varchar(255) NOT NULL default \'\'',
  2238. 'secret_question' => 'secret_question secret_question varchar(255) NOT NULL default \'\'',
  2239. 'additional_groups' => 'additional_groups additional_groups varchar(255) NOT NULL default \'\'',
  2240. ),
  2241. 'messages' => array(
  2242. 'subject' => 'subject subject varchar(255) NOT NULL default \'\'',
  2243. 'poster_name' => 'poster_name poster_name varchar(255) NOT NULL default \'\'',
  2244. 'poster_email' => 'poster_email poster_email varchar(255) NOT NULL default \'\'',
  2245. 'poster_ip' => 'poster_ip poster_ip varchar(255) NOT NULL default \'\'',
  2246. 'modified_name' => 'modified_name modified_name varchar(255) NOT NULL default \'\'',
  2247. ),
  2248. 'openid_assoc' => array(
  2249. 'handle' => 'handle handle varchar(255) NOT NULL default \'\'',
  2250. ),
  2251. 'package_servers' => array(
  2252. 'name' => 'name name varchar(255) NOT NULL default \'\'',
  2253. 'url' => 'url url varchar(255) NOT NULL default \'\'',
  2254. ),
  2255. 'permission_profiles' => array(
  2256. 'profile_name' => 'profile_name profile_name varchar(255) NOT NULL default \'\'',
  2257. ),
  2258. 'personal_messages' => array(
  2259. 'from_name' => 'from_name from_name varchar(255) NOT NULL default \'\'',
  2260. 'subject' => 'subject subject varchar(255) NOT NULL default \'\'',
  2261. ),
  2262. 'polls' => array(
  2263. 'question' => 'question question varchar(255) NOT NULL default \'\'',
  2264. 'poster_name' => 'poster_name poster_name varchar(255) NOT NULL default \'\'',
  2265. ),
  2266. 'poll_choices' => array(
  2267. 'label' => 'label label varchar(255) NOT NULL default \'\'',
  2268. ),
  2269. 'settings' => array(
  2270. 'variable' => 'variable variable varchar(255) NOT NULL default \'\'',
  2271. ),
  2272. 'spiders' => array(
  2273. 'spider_name' => 'spider_name spider_name varchar(255) NOT NULL default \'\'',
  2274. 'user_agent' => 'user_agent user_agent varchar(255) NOT NULL default \'\'',
  2275. 'ip_info' => 'ip_info ip_info varchar(255) NOT NULL default \'\'',
  2276. ),
  2277. 'subscriptions' => array(
  2278. 'description' => 'description description varchar(255) NOT NULL default \'\'',
  2279. ),
  2280. 'themes' => array(
  2281. 'variable' => 'variable variable varchar(255) NOT NULL default \'\'',
  2282. ),
  2283. );
  2284. $_GET['ren_col'] = isset($_GET['ren_col']) ? (int) $_GET['ren_col'] : 0;
  2285. $step_progress['name'] = 'Changing tinytext columns to varchar(255)';
  2286. $step_progress['current'] = $_GET['ren_col'];
  2287. $step_progress['total'] = count($nameChanges);
  2288. $count = 0;
  2289. // Now do every table...
  2290. foreach ($nameChanges as $table_name => $table)
  2291. {
  2292. // Already done this?
  2293. $count++;
  2294. if ($_GET['ren_col'] > $count)
  2295. continue;
  2296. $_GET['ren_col'] = $count;
  2297. // Check the table exists!
  2298. $request = upgrade_query("
  2299. SHOW TABLES
  2300. LIKE '{$db_prefix}$table_name'");
  2301. if (smf_mysql_num_rows($request) == 0)
  2302. {
  2303. smf_mysql_free_result($request);
  2304. continue;
  2305. }
  2306. smf_mysql_free_result($request);
  2307. // Converting is intensive, so make damn sure that we need to do it.
  2308. $request = upgrade_query("
  2309. SHOW FIELDS
  2310. FROM `{$db_prefix}$table_name`");
  2311. $tinytextColumns = array();
  2312. while($row = smf_mysql_fetch_assoc($request))
  2313. {
  2314. // Tinytext detected so store column name.
  2315. if ($row['Type'] == 'tinytext')
  2316. $tinytextColumns[$row['Field']] = $row['Field'];
  2317. }
  2318. smf_mysql_free_result($request);
  2319. // Check each column!
  2320. $actualChanges = array();
  2321. foreach ($table as $colname => $coldef)
  2322. {
  2323. // Column was not detected as tinytext so skip it
  2324. // Either it was already converted or was changed eg text (so do not break it)
  2325. if (!isset($tinytextColumns[$colname]))
  2326. continue;
  2327. $change = array(
  2328. 'table' => $table_name,
  2329. 'name' => $colname,
  2330. 'type' => 'column',
  2331. 'method' => 'change_remove',
  2332. 'text' => 'CHANGE ' . $coldef,
  2333. );
  2334. if (protected_alter($change, $substep, true) == false)
  2335. $actualChanges[] = ' CHANGE COLUMN ' . $coldef;
  2336. }
  2337. // Do the query - if it needs doing.
  2338. if (!empty($actualChanges))
  2339. {
  2340. $change = array(
  2341. 'table' => $table_name,
  2342. 'name' => 'na',
  2343. 'type' => 'table',
  2344. 'method' => 'full_change',
  2345. 'text' => implode(', ', $actualChanges),
  2346. );
  2347. // Here we go - hold on!
  2348. protected_alter($change, $substep);
  2349. }
  2350. // Update where we are!
  2351. $step_progress['current'] = $_GET['ren_col'];
  2352. }
  2353. // All done!
  2354. unset($_GET['ren_col']);
  2355. ---}
  2356. ---#
  2357. /******************************************************************************/
  2358. --- Adding new personal message setting.
  2359. /******************************************************************************/
  2360. ---# Adding column that stores the PM receiving setting...
  2361. ALTER TABLE {$db_prefix}members
  2362. ADD COLUMN pm_receive_from tinyint(4) unsigned NOT NULL default '1';
  2363. ---#
  2364. ---# Enable the buddy and ignore lists if we have not done so thus far...
  2365. ---{
  2366. // Don't do this if we've done this already.
  2367. if (empty($modSettings['dont_repeat_buddylists']))
  2368. {
  2369. // Make sure the pm_receive_from column has the right default value - early adoptors might have a '0' set here.
  2370. upgrade_query("
  2371. ALTER TABLE {$db_prefix}members
  2372. CHANGE pm_receive_from pm_receive_from tinyint(3) unsigned NOT NULL default '1'");
  2373. // Update previous ignore lists if they're set to ignore all.
  2374. upgrade_query("
  2375. UPDATE {$db_prefix}members
  2376. SET pm_receive_from = 3, pm_ignore_list = ''
  2377. WHERE pm_ignore_list = '*'");
  2378. // Ignore posts made by ignored users by default.
  2379. upgrade_query("
  2380. REPLACE INTO {$db_prefix}themes
  2381. (id_member, id_theme, variable, value)
  2382. VALUES
  2383. (-1, 1, 'posts_apply_ignore_list', '1')");
  2384. // Enable buddy and ignore lists, and make sure not to skip this step next time we run this.
  2385. upgrade_query("
  2386. REPLACE INTO {$db_prefix}settings
  2387. (variable, value)
  2388. VALUES
  2389. ('enable_buddylist', '1'),
  2390. ('dont_repeat_buddylists', '1')");
  2391. }
  2392. // And yet, and yet... We might have a small hiccup here...
  2393. if (!empty($modSettings['dont_repeat_buddylists']) && !isset($modSettings['enable_buddylist']))
  2394. {
  2395. // Correct RC3 adopters setting here...
  2396. if (isset($modSettings['enable_buddylists']))
  2397. {
  2398. upgrade_query("
  2399. REPLACE INTO {$db_prefix}settings
  2400. (variable, value)
  2401. VALUES
  2402. ('enable_buddylist', '" . $modSettings['enable_buddylists'] . "')");
  2403. }
  2404. else
  2405. {
  2406. // This should never happen :)
  2407. upgrade_query("
  2408. REPLACE INTO {$db_prefix}settings
  2409. (variable, value)
  2410. VALUES
  2411. ('enable_buddylist', '1')");
  2412. }
  2413. }
  2414. ---}
  2415. ---#
  2416. /******************************************************************************/
  2417. --- Adding settings for attachments and avatars.
  2418. /******************************************************************************/
  2419. ---# Add new security settings for attachments and avatars...
  2420. ---{
  2421. // Don't do this if we've done this already.
  2422. if (!isset($modSettings['attachment_image_reencode']))
  2423. {
  2424. // Enable image re-encoding by default.
  2425. upgrade_query("
  2426. REPLACE INTO {$db_prefix}settings
  2427. (variable, value)
  2428. VALUES
  2429. ('attachment_image_reencode', '1')");
  2430. }
  2431. if (!isset($modSettings['attachment_image_paranoid']))
  2432. {
  2433. // Disable draconic checks by default.
  2434. upgrade_query("
  2435. REPLACE INTO {$db_prefix}settings
  2436. (variable, value)
  2437. VALUES
  2438. ('attachment_image_paranoid', '0')");
  2439. }
  2440. if (!isset($modSettings['avatar_reencode']))
  2441. {
  2442. // Enable image re-encoding by default.
  2443. upgrade_query("
  2444. REPLACE INTO {$db_prefix}settings
  2445. (variable, value)
  2446. VALUES
  2447. ('avatar_reencode', '1')");
  2448. }
  2449. if (!isset($modSettings['avatar_paranoid']))
  2450. {
  2451. // Disable draconic checks by default.
  2452. upgrade_query("
  2453. REPLACE INTO {$db_prefix}settings
  2454. (variable, value)
  2455. VALUES
  2456. ('avatar_paranoid', '0')");
  2457. }
  2458. ---}
  2459. ---#
  2460. ---# Add other attachment settings...
  2461. ---{
  2462. if (!isset($modSettings['attachment_thumb_png']))
  2463. {
  2464. // Make image attachment thumbnail as PNG by default.
  2465. upgrade_query("
  2466. REPLACE INTO {$db_prefix}settings
  2467. (variable, value)
  2468. VALUES
  2469. ('attachment_thumb_png', '1')");
  2470. }
  2471. ---}
  2472. ---#
  2473. /******************************************************************************/
  2474. --- Cleaning up after old themes...
  2475. /******************************************************************************/
  2476. ---# Checking for "babylon" and removing it if necessary...
  2477. ---{
  2478. // Do they have "babylon" installed?
  2479. if (file_exists($GLOBALS['boarddir'] . '/Themes/babylon'))
  2480. {
  2481. $babylon_dir = $GLOBALS['boarddir'] . '/Themes/babylon';
  2482. $theme_request = upgrade_query("
  2483. SELECT ID_THEME
  2484. FROM {$db_prefix}themes
  2485. WHERE variable = 'theme_dir'
  2486. AND value ='$babylon_dir'");
  2487. // Don't do anything if this theme is already uninstalled
  2488. if (smf_mysql_num_rows($theme_request) == 1)
  2489. {
  2490. $id_theme = mysql_result($theme_request, 0);
  2491. mysql_free_result($theme_request);
  2492. $known_themes = explode(', ', $modSettings['knownThemes']);
  2493. // Remove this value...
  2494. $known_themes = array_diff($known_themes, array($id_theme));
  2495. // Change back to a string...
  2496. $known_themes = implode(', ', $known_themes);
  2497. // Update the database
  2498. upgrade_query("
  2499. REPLACE INTO {$db_prefix}settings (variable, value)
  2500. VALUES ('knownThemes', '$known_themes')");
  2501. // Delete any info about this theme
  2502. upgrade_query("
  2503. DELETE FROM {$db_prefix}themes
  2504. WHERE id_theme = $id_theme");
  2505. // Set any members or boards using this theme to the default
  2506. upgrade_query("
  2507. UPDATE {$db_prefix}members
  2508. SET id_theme = 0
  2509. WHERE id_theme = $id_theme");
  2510. upgrade_query("
  2511. UPDATE {$db_prefix}boards
  2512. SET id_theme = 0
  2513. WHERE id_theme = $id_theme");
  2514. if ($modSettings['theme_guests'] == $id_theme)
  2515. {
  2516. upgrade_query("
  2517. REPLACE INTO {$db_prefix}settings
  2518. (variable, value)
  2519. VALUES('theme_guests', 0)");
  2520. }
  2521. }
  2522. }
  2523. ---}
  2524. ---#
  2525. /******************************************************************************/
  2526. --- Installing new smileys sets...
  2527. /******************************************************************************/
  2528. ---# Installing new smiley sets...
  2529. ---{
  2530. // Don't do this twice!
  2531. if (empty($modSettings['installed_new_smiley_sets_20']))
  2532. {
  2533. // First, the entries.
  2534. upgrade_query("
  2535. UPDATE {$db_prefix}settings
  2536. SET value = CONCAT(value, ',aaron,akyhne')
  2537. WHERE variable = 'smiley_sets_known'");
  2538. // Second, the names.
  2539. upgrade_query("
  2540. UPDATE {$db_prefix}settings
  2541. SET value = CONCAT(value, '\nAaron\nAkyhne')
  2542. WHERE variable = 'smiley_sets_names'");
  2543. // This ain't running twice either.
  2544. upgrade_query("
  2545. REPLACE INTO {$db_prefix}settings
  2546. (variable, value)
  2547. VALUES
  2548. ('installed_new_smiley_sets_20', '1')");
  2549. }
  2550. ---}
  2551. ---#
  2552. /******************************************************************************/
  2553. --- Adding new indexes to the topics table.
  2554. /******************************************************************************/
  2555. ---# Adding index member_started...
  2556. ALTER TABLE {$db_prefix}topics
  2557. ADD INDEX member_started (id_member_started, id_board);
  2558. ---#
  2559. ---# Adding index last_message_sticky...
  2560. ALTER TABLE {$db_prefix}topics
  2561. ADD INDEX last_message_sticky (id_board, is_sticky, id_last_msg);
  2562. ---#
  2563. ---# Adding index board_news...
  2564. ALTER TABLE {$db_prefix}topics
  2565. ADD INDEX board_news (id_board, id_first_msg);
  2566. ---#
  2567. /******************************************************************************/
  2568. --- Adding new indexes to members table.
  2569. /******************************************************************************/
  2570. ---# Adding index on total_time_logged_in...
  2571. ALTER TABLE {$db_prefix}members
  2572. ADD INDEX total_time_logged_in (total_time_logged_in);
  2573. ---#
  2574. ---# Adding index on id_theme...
  2575. ALTER TABLE {$db_prefix}members
  2576. ADD INDEX id_theme (id_theme);
  2577. ---#
  2578. ---# Dropping index on real_name(30) ...
  2579. ---{
  2580. // Detect existing index with limited length
  2581. $request = upgrade_query("
  2582. SHOW INDEXES
  2583. FROM {$db_prefix}members"
  2584. );
  2585. // Drop the existing index before we recreate it.
  2586. while ($row = smf_mysql_fetch_assoc($request))
  2587. {
  2588. if ($row['Key_name'] === 'real_name' && $row['Sub_part'] == 30)
  2589. {
  2590. upgrade_query("
  2591. ALTER TABLE {$db_prefix}members
  2592. DROP INDEX real_name"
  2593. );
  2594. break;
  2595. }
  2596. }
  2597. smf_mysql_free_result($request);
  2598. ---}
  2599. ---#
  2600. ---# Adding index on real_name...
  2601. ALTER TABLE {$db_prefix}members
  2602. ADD INDEX real_name (real_name);
  2603. ---#
  2604. ---# Dropping index member_name(30)...
  2605. ---{
  2606. // Detect existing index with limited length
  2607. $request = upgrade_query("
  2608. SHOW INDEXES
  2609. FROM {$db_prefix}members"
  2610. );
  2611. // Drop the existing index before we recreate it.
  2612. while ($row = smf_mysql_fetch_assoc($request))
  2613. {
  2614. if ($row['Key_name'] === 'member_name' && $row['Sub_part'] == 30)
  2615. {
  2616. upgrade_query("
  2617. ALTER TABLE {$db_prefix}members
  2618. DROP INDEX member_name"
  2619. );
  2620. break;
  2621. }
  2622. }
  2623. smf_mysql_free_result($request);
  2624. ---}
  2625. ---#
  2626. ---# Adding index on member_name...
  2627. ALTER TABLE {$db_prefix}members
  2628. ADD INDEX member_name (member_name);
  2629. ---#
  2630. /******************************************************************************/
  2631. --- Adding new indexes to messages table.
  2632. /******************************************************************************/
  2633. ---# Adding index id_member_msg...
  2634. ALTER TABLE {$db_prefix}messages
  2635. ADD INDEX id_member_msg (id_member, approved, id_msg);
  2636. ---#
  2637. ---# Adding index current_topic...
  2638. ALTER TABLE {$db_prefix}messages
  2639. ADD INDEX current_topic (id_topic, id_msg, id_member, approved);
  2640. ---#
  2641. ---# Adding index related_ip...
  2642. ALTER TABLE {$db_prefix}messages
  2643. ADD INDEX related_ip (id_member, poster_ip, id_msg);
  2644. ---#
  2645. /******************************************************************************/
  2646. --- Adding new indexes to attachments table.
  2647. /******************************************************************************/
  2648. ---# Adding index on attachment_type...
  2649. ALTER TABLE {$db_prefix}attachments
  2650. ADD INDEX attachment_type (attachment_type);
  2651. ---#
  2652. /******************************************************************************/
  2653. --- Dropping unnecessary indexes...
  2654. /******************************************************************************/
  2655. ---# Removing index on hits...
  2656. ALTER TABLE {$db_prefix}log_activity
  2657. DROP INDEX hits;
  2658. ---#
  2659. /******************************************************************************/
  2660. --- Adding extra columns to reported post comments
  2661. /******************************************************************************/
  2662. ---# Adding email address and member ip columns...
  2663. ALTER TABLE {$db_prefix}log_reported_comments
  2664. ADD COLUMN member_ip varchar(255) NOT NULL default '' AFTER membername,
  2665. ADD COLUMN email_address varchar(255) NOT NULL default '' AFTER membername;
  2666. ---#
  2667. /******************************************************************************/
  2668. --- Adjusting group types.
  2669. /******************************************************************************/
  2670. ---# Fixing the group types.
  2671. ---{
  2672. // Get the admin group type.
  2673. $request = upgrade_query("
  2674. SELECT group_type
  2675. FROM {$db_prefix}membergroups
  2676. WHERE id_group = 1
  2677. LIMIT 1");
  2678. list ($admin_group_type) = smf_mysql_fetch_row($request);
  2679. smf_mysql_free_result($request);
  2680. // Not protected means we haven't updated yet!
  2681. if ($admin_group_type != 1)
  2682. {
  2683. // Increase by one.
  2684. upgrade_query("
  2685. UPDATE {$db_prefix}membergroups
  2686. SET group_type = group_type + 1
  2687. WHERE group_type > 0");
  2688. }
  2689. ---}
  2690. ---#
  2691. ---# Changing the group type for Administrator group.
  2692. UPDATE {$db_prefix}membergroups
  2693. SET group_type = 1
  2694. WHERE id_group = 1;
  2695. ---#
  2696. /******************************************************************************/
  2697. --- Final clean up...
  2698. /******************************************************************************/
  2699. ---# Sorting the boards...
  2700. ALTER TABLE {$db_prefix}categories
  2701. ORDER BY cat_order;
  2702. ALTER TABLE {$db_prefix}boards
  2703. ORDER BY board_order;
  2704. ---#