upgrade_2-0_mysql.sql 100 KB

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