upgrade_2-0_mysql.sql 100 KB

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