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. (20, 'Yandex', 'yandex', '');
  463. ---#
  464. ---# Removing a spider.
  465. ---{
  466. upgrade_query("
  467. DELETE FROM {$db_prefix}spiders
  468. WHERE user_agent = 'yahoo'
  469. AND spider_name = 'Yahoo! (Publisher)'
  470. ");
  471. ---}
  472. ---#
  473. ---# Creating spider hit tracking table.
  474. CREATE TABLE IF NOT EXISTS {$db_prefix}log_spider_hits (
  475. id_hit int(10) unsigned NOT NULL auto_increment,
  476. id_spider smallint(5) unsigned NOT NULL default '0',
  477. log_time int(10) unsigned NOT NULL default '0',
  478. url varchar(255) NOT NULL default '',
  479. processed tinyint(3) unsigned NOT NULL default '0',
  480. PRIMARY KEY (id_hit),
  481. KEY id_spider(id_spider),
  482. KEY log_time(log_time),
  483. KEY processed (processed)
  484. ) ENGINE=MyISAM{$db_collation};
  485. ---#
  486. ---# Making some changes to spider hit table...
  487. ALTER TABLE {$db_prefix}log_spider_hits
  488. ADD COLUMN id_hit int(10) unsigned NOT NULL auto_increment,
  489. ADD PRIMARY KEY (id_hit);
  490. ---#
  491. ---# Creating spider statistic table.
  492. CREATE TABLE IF NOT EXISTS {$db_prefix}log_spider_stats (
  493. id_spider smallint(5) unsigned NOT NULL default '0',
  494. page_hits smallint(5) unsigned NOT NULL default '0',
  495. last_seen int(10) unsigned NOT NULL default '0',
  496. stat_date date NOT NULL default '0001-01-01',
  497. PRIMARY KEY (stat_date, id_spider)
  498. ) ENGINE=MyISAM{$db_collation};
  499. ---#
  500. /******************************************************************************/
  501. --- Adding new forum settings.
  502. /******************************************************************************/
  503. ---# Resetting settings_updated.
  504. REPLACE INTO {$db_prefix}settings
  505. (variable, value)
  506. VALUES
  507. ('settings_updated', '0'),
  508. ('last_mod_report_action', '0'),
  509. ('search_floodcontrol_time', '5'),
  510. ('next_task_time', UNIX_TIMESTAMP());
  511. ---#
  512. ---# Changing stats settings.
  513. ---{
  514. $request = upgrade_query("
  515. SELECT value
  516. FROM {$db_prefix}themes
  517. WHERE variable = 'show_sp1_info'");
  518. if (smf_mysql_num_rows($request) != 0)
  519. {
  520. upgrade_query("
  521. DELETE FROM {$db_prefix}themes
  522. WHERE variable = 'show_stats_index'");
  523. upgrade_query("
  524. UPDATE {$db_prefix}themes
  525. SET variable = 'show_stats_index'
  526. WHERE variable = 'show_sp1_info'");
  527. }
  528. upgrade_query("
  529. DELETE FROM {$db_prefix}themes
  530. WHERE variable = 'show_sp1_info'");
  531. ---}
  532. ---#
  533. ---# Enable cache if upgrading from 1.1 and lower.
  534. ---{
  535. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1')
  536. {
  537. $request = upgrade_query("
  538. SELECT value
  539. FROM {$db_prefix}settings
  540. WHERE variable = 'cache_enable'");
  541. list ($cache_enable) = $smcFunc['db_fetch_row']($request);
  542. // No cache before 1.1.
  543. if ($smcFunc['db_num_rows']($request) == 0)
  544. upgrade_query("
  545. INSERT INTO {$db_prefix}settings
  546. (variable, value)
  547. VALUES ('cache_enable', '1')");
  548. elseif (empty($cache_enable))
  549. upgrade_query("
  550. UPDATE {$db_prefix}settings
  551. SET value = '1'
  552. WHERE variable = 'cache_enable'");
  553. }
  554. ---}
  555. ---#
  556. ---# Changing visual verification setting.
  557. ---{
  558. $request = upgrade_query("
  559. SELECT value
  560. FROM {$db_prefix}settings
  561. WHERE variable = 'disable_visual_verification'");
  562. if (smf_mysql_num_rows($request) != 0)
  563. {
  564. list ($oldValue) = smf_mysql_fetch_row($request);
  565. if ($oldValue != 0)
  566. {
  567. // We have changed the medium setting from SMF 1.1.2.
  568. if ($oldValue == 4)
  569. $oldValue = 5;
  570. upgrade_query("
  571. UPDATE {$db_prefix}settings
  572. SET variable = 'visual_verification_type', value = $oldValue
  573. WHERE variable = 'disable_visual_verification'");
  574. }
  575. }
  576. upgrade_query("
  577. DELETE FROM {$db_prefix}settings
  578. WHERE variable = 'disable_visual_verification'");
  579. ---}
  580. ---#
  581. ---# Changing visual verification setting, again.
  582. ---{
  583. $request = upgrade_query("
  584. SELECT value
  585. FROM {$db_prefix}settings
  586. WHERE variable = 'reg_verification'");
  587. if (smf_mysql_num_rows($request) == 0)
  588. {
  589. // Upgrade visual verification again!
  590. if (!empty($modSettings['visual_verification_type']))
  591. {
  592. upgrade_query("
  593. UPDATE {$db_prefix}settings
  594. SET value = value - 1
  595. WHERE variable = 'visual_verification_type'");
  596. $modSettings['visual_verification_type']--;
  597. }
  598. // Never set?
  599. elseif (!isset($modSettings['visual_verification_type']))
  600. {
  601. upgrade_query("
  602. INSERT INTO {$db_prefix}settings
  603. (variable, value)
  604. VALUES
  605. ('visual_verification_type', '3')");
  606. $modSettings['visual_verification_type'] = 3;
  607. }
  608. upgrade_query("
  609. INSERT INTO {$db_prefix}settings
  610. (variable, value)
  611. VALUES
  612. ('reg_verification', '" . (!empty($modSettings['visual_verification_type']) ? 1 : 0) . "')");
  613. }
  614. ---}
  615. ---#
  616. ---# Changing default personal text setting.
  617. UPDATE {$db_prefix}settings
  618. SET variable = 'default_personal_text'
  619. WHERE variable = 'default_personalText';
  620. DELETE FROM {$db_prefix}settings
  621. WHERE variable = 'default_personalText';
  622. ---#
  623. ---# Removing allow hide email setting.
  624. DELETE FROM {$db_prefix}settings
  625. WHERE variable = 'allow_hideEmail'
  626. OR variable = 'allow_hide_email';
  627. ---#
  628. ---# Ensuring stats index setting present...
  629. INSERT IGNORE INTO {$db_prefix}themes
  630. (id_theme, variable, value)
  631. VALUES
  632. (1, 'show_stats_index', '0');
  633. ---#
  634. ---# Ensuring forum width setting present...
  635. INSERT IGNORE INTO {$db_prefix}themes
  636. (id_theme, variable, value)
  637. VALUES
  638. (1, 'forum_width', '90%');
  639. ---#
  640. ---# Replacing old calendar settings...
  641. ---{
  642. // Only try it if one of the "new" settings doesn't yet exist.
  643. if (!isset($modSettings['cal_showholidays']) || !isset($modSettings['cal_showbdays']) || !isset($modSettings['cal_showevents']))
  644. {
  645. // Default to just the calendar setting.
  646. $modSettings['cal_showholidays'] = empty($modSettings['cal_showholidaysoncalendar']) ? 0 : 1;
  647. $modSettings['cal_showbdays'] = empty($modSettings['cal_showbdaysoncalendar']) ? 0 : 1;
  648. $modSettings['cal_showevents'] = empty($modSettings['cal_showeventsoncalendar']) ? 0 : 1;
  649. // Then take into account board index.
  650. if (!empty($modSettings['cal_showholidaysonindex']))
  651. $modSettings['cal_showholidays'] = $modSettings['cal_showholidays'] === 1 ? 2 : 3;
  652. if (!empty($modSettings['cal_showbdaysonindex']))
  653. $modSettings['cal_showbdays'] = $modSettings['cal_showbdays'] === 1 ? 2 : 3;
  654. if (!empty($modSettings['cal_showeventsonindex']))
  655. $modSettings['cal_showevents'] = $modSettings['cal_showevents'] === 1 ? 2 : 3;
  656. // Actually save the settings.
  657. upgrade_query("
  658. INSERT IGNORE INTO {$db_prefix}settings
  659. (variable, value)
  660. VALUES
  661. ('cal_showholidays', $modSettings[cal_showholidays]),
  662. ('cal_showbdays', $modSettings[cal_showbdays]),
  663. ('cal_showevents', $modSettings[cal_showevents])");
  664. }
  665. ---}
  666. ---#
  667. ---# Deleting old calendar settings...
  668. DELETE FROM {$db_prefix}settings
  669. WHERE VARIABLE IN ('cal_showholidaysonindex', 'cal_showbdaysonindex', 'cal_showeventsonindex',
  670. 'cal_showholidaysoncalendar', 'cal_showbdaysoncalendar', 'cal_showeventsoncalendar',
  671. 'cal_holidaycolor', 'cal_bdaycolor', 'cal_eventcolor');
  672. ---#
  673. ---# Adjusting calendar maximum year...
  674. ---{
  675. if (!isset($modSettings['cal_maxyear']) || $modSettings['cal_maxyear'] == '2010')
  676. {
  677. upgrade_query("
  678. REPLACE INTO {$db_prefix}settings
  679. (variable, value)
  680. VALUES
  681. ('cal_maxyear', '2020')");
  682. }
  683. ---}
  684. ---#
  685. ---# Adding advanced signature settings...
  686. ---{
  687. if (empty($modSettings['signature_settings']))
  688. {
  689. if (isset($modSettings['max_signatureLength']))
  690. $modSettings['signature_settings'] = '1,' . $modSettings['max_signatureLength'] . ',0,0,0,0,0,0:';
  691. else
  692. $modSettings['signature_settings'] = '1,300,0,0,0,0,0,0:';
  693. upgrade_query("
  694. INSERT IGNORE INTO {$db_prefix}settings
  695. (variable, value)
  696. VALUES
  697. ('signature_settings', '$modSettings[signature_settings]')");
  698. upgrade_query("
  699. DELETE FROM {$db_prefix}settings
  700. WHERE variable = 'max_signatureLength'");
  701. }
  702. ---}
  703. ---#
  704. ---# Updating spam protection settings.
  705. ---{
  706. if (empty($modSettings['pm_spam_settings']))
  707. {
  708. if (isset($modSettings['max_pm_recipients']))
  709. $modSettings['pm_spam_settings'] = $modSettings['max_pm_recipients'] . ',5,20';
  710. else
  711. $modSettings['pm_spam_settings'] = '10,5,20';
  712. }
  713. elseif (substr_count($modSettings['pm_spam_settings'], ',') == 1)
  714. {
  715. $modSettings['pm_spam_settings'] .= ',20';
  716. }
  717. upgrade_query("
  718. INSERT IGNORE INTO {$db_prefix}settings
  719. (variable, value)
  720. VALUES
  721. ('pm_spam_settings', '$modSettings[pm_spam_settings]')");
  722. upgrade_query("
  723. DELETE FROM {$db_prefix}settings
  724. WHERE variable = 'max_pm_recipients'");
  725. ---}
  726. ---#
  727. ---# Adjusting timezone settings...
  728. ---{
  729. if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
  730. {
  731. $server_offset = mktime(0, 0, 0, 1, 1, 1970);
  732. $timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600);
  733. if (date_default_timezone_set($timezone_id))
  734. upgrade_query("
  735. REPLACE INTO {$db_prefix}settings
  736. (variable, value)
  737. VALUES
  738. ('default_timezone', '$timezone_id')");
  739. }
  740. ---}
  741. ---#
  742. ---# Checking theme layers are correct for default themes.
  743. ---{
  744. $request = upgrade_query("
  745. SELECT id_theme, value, variable
  746. FROM {$db_prefix}themes
  747. WHERE variable = 'theme_layers'
  748. OR variable = 'theme_dir'");
  749. $themeLayerChanges = array();
  750. while ($row = smf_mysql_fetch_assoc($request))
  751. {
  752. $themeLayerChanges[$row['id_theme']][$row['variable']] = $row['value'];
  753. }
  754. smf_mysql_free_result($request);
  755. foreach ($themeLayerChanges as $id_theme => $data)
  756. {
  757. // Has to be a SMF provided theme and have custom layers defined.
  758. if (!isset($data['theme_layers']) || !isset($data['theme_dir']) || !in_array(substr($data['theme_dir'], -7), array('default', 'babylon', 'classic')))
  759. continue;
  760. $layers = explode(',', $data['theme_layers']);
  761. foreach ($layers as $k => $v)
  762. if ($v == 'main')
  763. {
  764. $layers[$k] = 'html,body';
  765. upgrade_query("
  766. UPDATE {$db_prefix}themes
  767. SET value = '" . implode(',', $layers) . "'
  768. WHERE id_theme = $id_theme
  769. AND variable = 'theme_layers'");
  770. break;
  771. }
  772. }
  773. ---}
  774. ---#
  775. ---# Adding index to log_notify table...
  776. ALTER TABLE {$db_prefix}log_notify
  777. ADD INDEX id_topic (id_topic, id_member);
  778. ---#
  779. /******************************************************************************/
  780. --- Adding custom profile fields.
  781. /******************************************************************************/
  782. ---# Creating "custom_fields" table...
  783. CREATE TABLE IF NOT EXISTS {$db_prefix}custom_fields (
  784. id_field smallint(5) NOT NULL auto_increment,
  785. col_name varchar(12) NOT NULL default '',
  786. field_name varchar(40) NOT NULL default '',
  787. field_desc varchar(255) NOT NULL default '',
  788. field_type varchar(8) NOT NULL default 'text',
  789. field_length smallint(5) NOT NULL default '255',
  790. field_options text NOT NULL,
  791. mask varchar(255) NOT NULL default '',
  792. show_reg tinyint(3) NOT NULL default '0',
  793. show_display tinyint(3) NOT NULL default '0',
  794. show_profile varchar(20) NOT NULL default 'forumprofile',
  795. private tinyint(3) NOT NULL default '0',
  796. active tinyint(3) NOT NULL default '1',
  797. bbc tinyint(3) NOT NULL default '0',
  798. default_value varchar(255) NOT NULL default '',
  799. PRIMARY KEY (id_field),
  800. UNIQUE col_name (col_name)
  801. ) ENGINE=MyISAM{$db_collation};
  802. ---#
  803. ---# Adding search ability to custom fields.
  804. ALTER TABLE {$db_prefix}custom_fields
  805. ADD COLUMN can_search tinyint(3) NOT NULL default '0' AFTER bbc;
  806. ---#
  807. ---# Fixing default value field length.
  808. ALTER TABLE {$db_prefix}custom_fields
  809. CHANGE COLUMN default_value default_value varchar(255) NOT NULL default '';
  810. ---#
  811. ---# Enhancing privacy settings for custom fields.
  812. ---{
  813. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1')
  814. {
  815. upgrade_query("
  816. UPDATE {$db_prefix}custom_fields
  817. SET private = 2
  818. WHERE private = 1");
  819. }
  820. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] < '2.0 Beta 4')
  821. {
  822. upgrade_query("
  823. UPDATE {$db_prefix}custom_fields
  824. SET private = 3
  825. WHERE private = 2");
  826. }
  827. ---}
  828. ---#
  829. ---# Checking display fields setup correctly..
  830. ---{
  831. if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1' && isset($modSettings['displayFields']) && @unserialize($modSettings['displayFields']) == false)
  832. {
  833. $request = upgrade_query("
  834. SELECT col_name, field_name, bbc
  835. FROM {$db_prefix}custom_fields
  836. WHERE show_display = 1
  837. AND active = 1
  838. AND private != 2");
  839. $fields = array();
  840. while ($row = smf_mysql_fetch_assoc($request))
  841. {
  842. $fields[] = array(
  843. 'c' => strtr($row['col_name'], array('|' => '', ';' => '')),
  844. 'f' => strtr($row['field_name'], array('|' => '', ';' => '')),
  845. 'b' => ($row['bbc'] ? '1' : '0')
  846. );
  847. }
  848. smf_mysql_free_result($request);
  849. upgrade_query("
  850. UPDATE {$db_prefix}settings
  851. SET value = '" . smf_mysql_real_escape_string(serialize($fields)) . "'
  852. WHERE variable = 'displayFields'");
  853. }
  854. ---}
  855. ---#
  856. ---# Adding new custom fields columns.
  857. ALTER TABLE {$db_prefix}custom_fields
  858. ADD enclose text NOT NULL;
  859. ALTER TABLE {$db_prefix}custom_fields
  860. ADD placement tinyint(3) NOT NULL default '0';
  861. ---#
  862. /******************************************************************************/
  863. --- Adding email digest functionality.
  864. /******************************************************************************/
  865. ---# Creating "log_digest" table...
  866. CREATE TABLE IF NOT EXISTS {$db_prefix}log_digest (
  867. id_topic mediumint(8) unsigned NOT NULL default '0',
  868. id_msg int(10) unsigned NOT NULL default '0',
  869. note_type varchar(10) NOT NULL default 'post',
  870. daily tinyint(3) unsigned NOT NULL default '0',
  871. exclude mediumint(8) unsigned NOT NULL default '0'
  872. ) ENGINE=MyISAM{$db_collation};
  873. ---#
  874. ---# Adding digest option to "members" table...
  875. ALTER TABLE {$db_prefix}members
  876. CHANGE COLUMN notifyOnce notify_regularity tinyint(4) unsigned NOT NULL default '1';
  877. ---#
  878. /******************************************************************************/
  879. --- Making changes to the package manager.
  880. /******************************************************************************/
  881. ---# Creating "log_packages" table...
  882. CREATE TABLE IF NOT EXISTS {$db_prefix}log_packages (
  883. id_install int(10) NOT NULL auto_increment,
  884. filename varchar(255) NOT NULL default '',
  885. package_id varchar(255) NOT NULL default '',
  886. name varchar(255) NOT NULL default '',
  887. version varchar(255) NOT NULL default '',
  888. id_member_installed mediumint(8) NOT NULL default '0',
  889. member_installed varchar(255) NOT NULL default '',
  890. time_installed int(10) NOT NULL default '0',
  891. id_member_removed mediumint(8) NOT NULL default '0',
  892. member_removed varchar(255) NOT NULL default '',
  893. time_removed int(10) NOT NULL default '0',
  894. install_state tinyint(3) NOT NULL default '1',
  895. failed_steps text NOT NULL,
  896. themes_installed varchar(255) NOT NULL default '',
  897. db_changes text NOT NULL,
  898. PRIMARY KEY (id_install),
  899. KEY filename (filename(15))
  900. ) ENGINE=MyISAM{$db_collation};
  901. ---#
  902. ---# Adding extra "log_packages" columns...
  903. ALTER TABLE {$db_prefix}log_packages
  904. ADD db_changes text NOT NULL AFTER themes_installed;
  905. ---#
  906. ---# Changing URL to SMF package server...
  907. UPDATE {$db_prefix}package_servers
  908. SET url = 'http://custom.simplemachines.org/packages/mods'
  909. WHERE url = 'http://mods.simplemachines.org';
  910. ---#
  911. /******************************************************************************/
  912. --- Creating mail queue functionality.
  913. /******************************************************************************/
  914. ---# Creating "mail_queue" table...
  915. CREATE TABLE IF NOT EXISTS {$db_prefix}mail_queue (
  916. id_mail int(10) unsigned NOT NULL auto_increment,
  917. time_sent int(10) NOT NULL default '0',
  918. recipient varchar(255) NOT NULL default '',
  919. body text NOT NULL,
  920. subject varchar(255) NOT NULL default '',
  921. headers text NOT NULL,
  922. send_html tinyint(3) NOT NULL default '0',
  923. priority tinyint(3) NOT NULL default '1',
  924. PRIMARY KEY (id_mail),
  925. KEY time_sent (time_sent),
  926. KEY mail_priority (priority, id_mail)
  927. ) ENGINE=MyISAM{$db_collation};
  928. ---#
  929. ---# Adding new mail queue settings...
  930. ---{
  931. if (!isset($modSettings['mail_next_send']))
  932. {
  933. upgrade_query("
  934. INSERT INTO {$db_prefix}settings
  935. (variable, value)
  936. VALUES
  937. ('mail_next_send', '0'),
  938. ('mail_recent', '0000000000|0')");
  939. }
  940. ---}
  941. ---#
  942. ---# Change mail queue indexes...
  943. ALTER TABLE {$db_prefix}mail_queue
  944. DROP INDEX priority;
  945. ALTER TABLE {$db_prefix}mail_queue
  946. ADD INDEX mail_priority (priority, id_mail);
  947. ---#
  948. ---# Adding type to mail queue...
  949. ALTER TABLE {$db_prefix}mail_queue
  950. ADD private tinyint(1) NOT NULL default '0';
  951. ---#
  952. /******************************************************************************/
  953. --- Creating moderation center tables.
  954. /******************************************************************************/
  955. ---# Creating "log_reported" table...
  956. CREATE TABLE IF NOT EXISTS {$db_prefix}log_reported (
  957. id_report mediumint(8) unsigned NOT NULL auto_increment,
  958. id_msg int(10) unsigned NOT NULL default '0',
  959. id_topic mediumint(8) unsigned NOT NULL default '0',
  960. id_board smallint(5) unsigned NOT NULL default '0',
  961. id_member mediumint(8) unsigned NOT NULL default '0',
  962. membername varchar(255) NOT NULL default '',
  963. subject varchar(255) NOT NULL default '',
  964. body text NOT NULL,
  965. time_started int(10) NOT NULL default '0',
  966. time_updated int(10) NOT NULL default '0',
  967. num_reports mediumint(6) NOT NULL default '0',
  968. closed tinyint(3) NOT NULL default '0',
  969. ignore_all tinyint(3) NOT NULL default '0',
  970. PRIMARY KEY (id_report),
  971. KEY id_member (id_member),
  972. KEY id_topic (id_topic),
  973. KEY closed (closed),
  974. KEY time_started (time_started),
  975. KEY id_msg (id_msg)
  976. ) ENGINE=MyISAM{$db_collation};
  977. ---#
  978. ---# Creating "log_reported_comments" table...
  979. CREATE TABLE IF NOT EXISTS {$db_prefix}log_reported_comments (
  980. id_comment mediumint(8) unsigned NOT NULL auto_increment,
  981. id_report mediumint(8) NOT NULL default '0',
  982. id_member mediumint(8) NOT NULL,
  983. membername varchar(255) NOT NULL default '',
  984. comment varchar(255) NOT NULL default '',
  985. time_sent int(10) NOT NULL,
  986. PRIMARY KEY (id_comment),
  987. KEY id_report (id_report),
  988. KEY id_member (id_member),
  989. KEY time_sent (time_sent)
  990. ) ENGINE=MyISAM{$db_collation};
  991. ---#
  992. ---# Adding moderator center permissions...
  993. ---{
  994. // Don't do this twice!
  995. if (@$modSettings['smfVersion'] < '2.0')
  996. {
  997. // Try find people who probably should see the moderation center.
  998. $request = upgrade_query("
  999. SELECT id_group, add_deny, permission
  1000. FROM {$db_prefix}permissions
  1001. WHERE permission = 'calendar_edit_any'");
  1002. $inserts = array();
  1003. while ($row = smf_mysql_fetch_assoc($request))
  1004. {
  1005. $inserts[] = "($row[id_group], 'access_mod_center', $row[add_deny])";
  1006. }
  1007. smf_mysql_free_result($request);
  1008. if (!empty($inserts))
  1009. upgrade_query("
  1010. INSERT IGNORE INTO {$db_prefix}permissions
  1011. (id_group, permission, add_deny)
  1012. VALUES
  1013. " . implode(',', $inserts));
  1014. }
  1015. ---}
  1016. ---#
  1017. ---# Adding moderation center preferences...
  1018. ALTER TABLE {$db_prefix}members
  1019. ADD mod_prefs varchar(20) NOT NULL default '';
  1020. ---#
  1021. /******************************************************************************/
  1022. --- Adding user warnings.
  1023. /******************************************************************************/
  1024. ---# Creating member notices table...
  1025. CREATE TABLE IF NOT EXISTS {$db_prefix}log_member_notices (
  1026. id_notice mediumint(8) unsigned NOT NULL auto_increment,
  1027. subject varchar(255) NOT NULL default '',
  1028. body text NOT NULL,
  1029. PRIMARY KEY (id_notice)
  1030. ) ENGINE=MyISAM{$db_collation};
  1031. ---#
  1032. ---# Creating comments table...
  1033. CREATE TABLE IF NOT EXISTS {$db_prefix}log_comments (
  1034. id_comment mediumint(8) unsigned NOT NULL auto_increment,
  1035. id_member mediumint(8) unsigned NOT NULL default '0',
  1036. member_name varchar(80) NOT NULL default '',
  1037. comment_type varchar(8) NOT NULL default 'warning',
  1038. id_recipient mediumint(8) unsigned NOT NULL default '0',
  1039. recipient_name varchar(255) NOT NULL default '',
  1040. log_time int(10) NOT NULL default '0',
  1041. id_notice mediumint(8) unsigned NOT NULL default '0',
  1042. counter tinyint(3) NOT NULL default '0',
  1043. body text NOT NULL,
  1044. PRIMARY KEY (id_comment),
  1045. KEY id_recipient (id_recipient),
  1046. KEY log_time (log_time),
  1047. KEY comment_type (comment_type(8))
  1048. ) ENGINE=MyISAM{$db_collation};
  1049. ---#
  1050. ---# Adding user warning column...
  1051. ALTER TABLE {$db_prefix}members
  1052. ADD warning tinyint(4) NOT NULL default '0';
  1053. ALTER TABLE {$db_prefix}members
  1054. ADD INDEX warning (warning);
  1055. ---#
  1056. ---# Ensuring warning settings are present...
  1057. ---{
  1058. // Only do this if not already done.
  1059. if (empty($modSettings['warning_settings']))
  1060. {
  1061. upgrade_query("
  1062. INSERT IGNORE INTO {$db_prefix}settings
  1063. (variable, value)
  1064. VALUES
  1065. ('warning_settings', '1,20,0'),
  1066. ('warning_watch', '10'),
  1067. ('warning_moderate', '35'),
  1068. ('warning_mute', '60')");
  1069. }
  1070. ---}
  1071. ---#
  1072. /******************************************************************************/
  1073. --- Enhancing membergroups.
  1074. /******************************************************************************/
  1075. ---# Creating "log_group_requests" table...
  1076. CREATE TABLE IF NOT EXISTS {$db_prefix}log_group_requests (
  1077. id_request mediumint(8) unsigned NOT NULL auto_increment,
  1078. id_member mediumint(8) unsigned NOT NULL default '0',
  1079. id_group smallint(5) unsigned NOT NULL default '0',
  1080. time_applied int(10) unsigned NOT NULL default '0',
  1081. reason text NOT NULL,
  1082. PRIMARY KEY (id_request),
  1083. UNIQUE id_member (id_member, id_group)
  1084. ) ENGINE=MyISAM{$db_collation};
  1085. ---#
  1086. ---# Adding new membergroup table columns...
  1087. ALTER TABLE {$db_prefix}membergroups
  1088. ADD description text NOT NULL AFTER group_name;
  1089. ALTER TABLE {$db_prefix}membergroups
  1090. ADD group_type tinyint(3) NOT NULL default '0';
  1091. ALTER TABLE {$db_prefix}membergroups
  1092. ADD hidden tinyint(3) NOT NULL default '0';
  1093. ---#
  1094. ---# Creating "group_moderators" table...
  1095. CREATE TABLE IF NOT EXISTS {$db_prefix}group_moderators (
  1096. id_group smallint(5) unsigned NOT NULL default '0',
  1097. id_member mediumint(8) unsigned NOT NULL default '0',
  1098. PRIMARY KEY (id_group, id_member)
  1099. ) ENGINE=MyISAM{$db_collation};
  1100. ---#
  1101. /******************************************************************************/
  1102. --- Updating attachment data...
  1103. /******************************************************************************/
  1104. ---# Altering attachment table.
  1105. ALTER TABLE {$db_prefix}attachments
  1106. ADD COLUMN fileext varchar(8) NOT NULL default '',
  1107. ADD COLUMN mime_type varchar(20) NOT NULL default '';
  1108. ALTER TABLE {$db_prefix}attachments
  1109. ADD COLUMN id_folder tinyint(3) NOT NULL default '1';
  1110. ---#
  1111. ---# Adding file hash.
  1112. ALTER TABLE {$db_prefix}attachments
  1113. ADD COLUMN file_hash varchar(40) NOT NULL default '';
  1114. ---#
  1115. ---# Populate the attachment extension.
  1116. UPDATE {$db_prefix}attachments
  1117. SET fileext = LOWER(SUBSTRING(filename, 1 - (INSTR(REVERSE(filename), '.'))))
  1118. WHERE fileext = ''
  1119. AND INSTR(filename, '.')
  1120. AND attachment_type != 3;
  1121. ---#
  1122. ---# Updating thumbnail attachments JPG.
  1123. UPDATE {$db_prefix}attachments
  1124. SET fileext = 'jpg'
  1125. WHERE attachment_type = 3
  1126. AND fileext = ''
  1127. AND RIGHT(filename, 9) = 'JPG_thumb';
  1128. ---#
  1129. ---# Updating thumbnail attachments PNG.
  1130. UPDATE {$db_prefix}attachments
  1131. SET fileext = 'png'
  1132. WHERE attachment_type = 3
  1133. AND fileext = ''
  1134. AND RIGHT(filename, 9) = 'PNG_thumb';
  1135. ---#
  1136. ---# Calculating attachment mime types.
  1137. ---{
  1138. // Don't ever bother doing this twice.
  1139. if (@$modSettings['smfVersion'] < '2.0' || @$modSettings['smfVersion'] === '2.0 a')
  1140. {
  1141. $request = upgrade_query("
  1142. SELECT MAX(id_attach)
  1143. FROM {$db_prefix}attachments");
  1144. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  1145. $smcFunc['db_free_result']($request);
  1146. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  1147. $step_progress['name'] = 'Calculating MIME Types';
  1148. $step_progress['current'] = $_GET['a'];
  1149. if (!function_exists('getAttachmentFilename'))
  1150. {
  1151. function getAttachmentFilename($filename, $attachment_id)
  1152. {
  1153. global $modSettings;
  1154. $clean_name = strtr($filename, 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
  1155. $clean_name = strtr($clean_name, array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u'));
  1156. $clean_name = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $clean_name);
  1157. $enc_name = $attachment_id . '_' . strtr($clean_name, '.', '_') . md5($clean_name);
  1158. $clean_name = preg_replace('~\.[\.]+~', '.', $clean_name);
  1159. if ($attachment_id == false)
  1160. return $clean_name;
  1161. if (file_exists($modSettings['attachmentUploadDir'] . '/' . $enc_name))
  1162. $filename = $modSettings['attachmentUploadDir'] . '/' . $enc_name;
  1163. else
  1164. $filename = $modSettings['attachmentUploadDir'] . '/' . $clean_name;
  1165. return $filename;
  1166. }
  1167. }
  1168. $ext_updates = array();
  1169. // What headers are valid results for getimagesize?
  1170. $validTypes = array(
  1171. 1 => 'gif',
  1172. 2 => 'jpeg',
  1173. 3 => 'png',
  1174. 5 => 'psd',
  1175. 6 => 'bmp',
  1176. 7 => 'tiff',
  1177. 8 => 'tiff',
  1178. 9 => 'jpeg',
  1179. 14 => 'iff',
  1180. );
  1181. $is_done = false;
  1182. while (!$is_done)
  1183. {
  1184. nextSubStep($substep);
  1185. $request = upgrade_query("
  1186. SELECT id_attach, filename, fileext
  1187. FROM {$db_prefix}attachments
  1188. WHERE fileext != ''
  1189. AND mime_type = ''
  1190. LIMIT $_GET[a], 100");
  1191. // Finished?
  1192. if ($smcFunc['db_num_rows']($request) == 0)
  1193. $is_done = true;
  1194. while ($row = $smcFunc['db_fetch_assoc']($request))
  1195. {
  1196. $filename = getAttachmentFilename($row['filename'], $row['id_attach']);
  1197. if (!file_exists($filename))
  1198. continue;
  1199. // Is it an image?
  1200. $size = @getimagesize($filename);
  1201. // Nothing valid?
  1202. if (empty($size) || empty($size[0]))
  1203. continue;
  1204. // Got the mime?
  1205. elseif (!empty($size['mime']))
  1206. $mime = $size['mime'];
  1207. // Otherwise is it valid?
  1208. elseif (!isset($validTypes[$size[2]]))
  1209. continue;
  1210. else
  1211. $mime = 'image/' . $validTypes[$size[2]];
  1212. // Let's try keep updates to a minimum.
  1213. if (!isset($ext_updates[$row['fileext'] . $size['mime']]))
  1214. $ext_updates[$row['fileext'] . $size['mime']] = array(
  1215. 'fileext' => $row['fileext'],
  1216. 'mime' => $mime,
  1217. 'files' => array(),
  1218. );
  1219. $ext_updates[$row['fileext'] . $size['mime']]['files'][] = $row['id_attach'];
  1220. }
  1221. $smcFunc['db_free_result']($request);
  1222. // Do the updates?
  1223. foreach ($ext_updates as $key => $update)
  1224. {
  1225. upgrade_query("
  1226. UPDATE {$db_prefix}attachments
  1227. SET mime_type = '$update[mime]'
  1228. WHERE id_attach IN (" . implode(',', $update['files']) . ")");
  1229. // Remove it.
  1230. unset($ext_updates[$key]);
  1231. }
  1232. $_GET['a'] += 100;
  1233. $step_progress['current'] = $_GET['a'];
  1234. }
  1235. unset($_GET['a']);
  1236. }
  1237. ---}
  1238. ---#
  1239. /******************************************************************************/
  1240. --- Adding Post Moderation.
  1241. /******************************************************************************/
  1242. ---# Creating "approval_queue" table...
  1243. CREATE TABLE IF NOT EXISTS {$db_prefix}approval_queue (
  1244. id_msg int(10) unsigned NOT NULL default '0',
  1245. id_attach int(10) unsigned NOT NULL default '0',
  1246. id_event smallint(5) unsigned NOT NULL default '0'
  1247. ) ENGINE=MyISAM{$db_collation};
  1248. ---#
  1249. ---# Adding approved column to attachments table...
  1250. ALTER TABLE {$db_prefix}attachments
  1251. ADD approved tinyint(3) NOT NULL default '1';
  1252. ---#
  1253. ---# Adding approved column to messages table...
  1254. ALTER TABLE {$db_prefix}messages
  1255. ADD approved tinyint(3) NOT NULL default '1';
  1256. ALTER TABLE {$db_prefix}messages
  1257. ADD INDEX approved (approved);
  1258. ---#
  1259. ---# Adding unapproved count column to topics table...
  1260. ALTER TABLE {$db_prefix}topics
  1261. ADD unapproved_posts smallint(5) NOT NULL default '0';
  1262. ---#
  1263. ---# Adding approved column to topics table...
  1264. ALTER TABLE {$db_prefix}topics
  1265. ADD approved tinyint(3) NOT NULL default '1',
  1266. ADD INDEX approved (approved);
  1267. ---#
  1268. ---# Adding approved columns to boards table...
  1269. ALTER TABLE {$db_prefix}boards
  1270. ADD unapproved_posts smallint(5) NOT NULL default '0',
  1271. ADD unapproved_topics smallint(5) NOT NULL default '0';
  1272. ---#
  1273. ---# Adding post moderation permissions...
  1274. ---{
  1275. // We *cannot* do this twice!
  1276. if (@$modSettings['smfVersion'] < '2.0')
  1277. {
  1278. // Anyone who can currently edit posts we assume can approve them...
  1279. $request = upgrade_query("
  1280. SELECT id_group, id_board, add_deny, permission
  1281. FROM {$db_prefix}board_permissions
  1282. WHERE permission = 'modify_any'");
  1283. $inserts = array();
  1284. while ($row = smf_mysql_fetch_assoc($request))
  1285. {
  1286. $inserts[] = "($row[id_group], $row[id_board], 'approve_posts', $row[add_deny])";
  1287. }
  1288. smf_mysql_free_result($request);
  1289. if (!empty($inserts))
  1290. upgrade_query("
  1291. INSERT IGNORE INTO {$db_prefix}board_permissions
  1292. (id_group, id_board, permission, add_deny)
  1293. VALUES
  1294. " . implode(',', $inserts));
  1295. }
  1296. ---}
  1297. ---#
  1298. /******************************************************************************/
  1299. --- Upgrading the error log.
  1300. /******************************************************************************/
  1301. ---# Adding columns to log_errors table...
  1302. ALTER TABLE {$db_prefix}log_errors
  1303. ADD error_type char(15) NOT NULL default 'general';
  1304. ALTER TABLE {$db_prefix}log_errors
  1305. ADD file varchar(255) NOT NULL default '',
  1306. ADD line mediumint(8) unsigned NOT NULL default '0';
  1307. ---#
  1308. ---# Updating error log table...
  1309. ---{
  1310. $request = upgrade_query("
  1311. SELECT COUNT(*)
  1312. FROM {$db_prefix}log_errors");
  1313. list($totalActions) = smf_mysql_fetch_row($request);
  1314. smf_mysql_free_result($request);
  1315. $_GET['m'] = !empty($_GET['m']) ? (int) $_GET['m'] : '0';
  1316. $step_progress['total'] = $totalActions;
  1317. $step_progress['current'] = $_GET['m'];
  1318. while ($_GET['m'] < $totalActions)
  1319. {
  1320. nextSubStep($substep);
  1321. $request = upgrade_query("
  1322. SELECT id_error, message, file, line
  1323. FROM {$db_prefix}log_errors
  1324. LIMIT $_GET[m], 500");
  1325. while($row = smf_mysql_fetch_assoc($request))
  1326. {
  1327. preg_match('~<br />(%1\$s: )?([\w\. \\\\/\-_:]+)<br />(%2\$s: )?([\d]+)~', $row['message'], $matches);
  1328. if (!empty($matches[2]) && !empty($matches[4]) && empty($row['file']) && empty($row['line']))
  1329. {
  1330. $row['file'] = addslashes(str_replace('\\', '/', $matches[2]));
  1331. $row['line'] = (int) $matches[4];
  1332. $row['message'] = addslashes(preg_replace('~<br />(%1\$s: )?([\w\. \\\\/\-_:]+)<br />(%2\$s: )?([\d]+)~', '', $row['message']));
  1333. }
  1334. else
  1335. continue;
  1336. upgrade_query("
  1337. UPDATE {$db_prefix}log_errors
  1338. SET file = SUBSTRING('$row[file]', 1, 255),
  1339. line = $row[line],
  1340. message = SUBSTRING('$row[message]', 1, 65535)
  1341. WHERE id_error = $row[id_error]
  1342. LIMIT 1");
  1343. }
  1344. $_GET['m'] += 500;
  1345. $step_progress['current'] = $_GET['m'];
  1346. }
  1347. unset($_GET['m']);
  1348. ---}
  1349. ---#
  1350. /******************************************************************************/
  1351. --- Adding Scheduled Tasks Data.
  1352. /******************************************************************************/
  1353. ---# Creating Scheduled Task Table...
  1354. CREATE TABLE IF NOT EXISTS {$db_prefix}scheduled_tasks (
  1355. id_task smallint(5) NOT NULL auto_increment,
  1356. next_time int(10) NOT NULL default '0',
  1357. time_offset int(10) NOT NULL default '0',
  1358. time_regularity smallint(5) NOT NULL default '0',
  1359. time_unit varchar(1) NOT NULL default 'h',
  1360. disabled tinyint(3) NOT NULL default '0',
  1361. task varchar(24) NOT NULL default '',
  1362. PRIMARY KEY (id_task),
  1363. KEY next_time (next_time),
  1364. KEY disabled (disabled),
  1365. UNIQUE task (task)
  1366. ) ENGINE=MyISAM{$db_collation};
  1367. ---#
  1368. ---# Populating Scheduled Task Table...
  1369. INSERT IGNORE INTO {$db_prefix}scheduled_tasks
  1370. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  1371. VALUES
  1372. (0, 0, 2, 'h', 0, 'approval_notification'),
  1373. (0, 0, 7, 'd', 0, 'auto_optimize'),
  1374. (0, 60, 1, 'd', 0, 'daily_maintenance'),
  1375. (0, 0, 1, 'd', 0, 'daily_digest'),
  1376. (0, 0, 1, 'w', 0, 'weekly_digest'),
  1377. (0, 0, 1, 'd', 1, 'birthdayemails'),
  1378. (0, 120, 1, 'd', 0, 'paid_subscriptions');
  1379. ---#
  1380. ---# Adding the simple machines scheduled task.
  1381. ---{
  1382. // Randomise the time.
  1383. $randomTime = 82800 + rand(0, 86399);
  1384. upgrade_query("
  1385. INSERT IGNORE INTO {$db_prefix}scheduled_tasks
  1386. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  1387. VALUES
  1388. (0, {$randomTime}, 1, 'd', 0, 'fetchSMfiles')");
  1389. ---}
  1390. ---#
  1391. ---# Deleting old scheduled task items...
  1392. DELETE FROM {$db_prefix}scheduled_tasks
  1393. WHERE task = 'clean_cache';
  1394. ---#
  1395. ---# Moving auto optimise settings to scheduled task...
  1396. ---{
  1397. if (!isset($modSettings['next_task_time']) && isset($modSettings['autoOptLastOpt']))
  1398. {
  1399. // Try move over the regularity...
  1400. if (isset($modSettings['autoOptDatabase']))
  1401. {
  1402. $disabled = empty($modSettings['autoOptDatabase']) ? 1 : 0;
  1403. $regularity = $disabled ? 7 : $modSettings['autoOptDatabase'];
  1404. $next_time = $modSettings['autoOptLastOpt'] + 3600 * 24 * $modSettings['autoOptDatabase'];
  1405. // Update the task accordingly.
  1406. upgrade_query("
  1407. UPDATE {$db_prefix}scheduled_tasks
  1408. SET disabled = $disabled, time_regularity = $regularity, next_time = $next_time
  1409. WHERE task = 'auto_optimize'");
  1410. }
  1411. // Delete the old settings!
  1412. upgrade_query("
  1413. DELETE FROM {$db_prefix}settings
  1414. WHERE VARIABLE IN ('autoOptLastOpt', 'autoOptDatabase')");
  1415. }
  1416. ---}
  1417. ---#
  1418. ---# Creating Scheduled Task Log Table...
  1419. CREATE TABLE IF NOT EXISTS {$db_prefix}log_scheduled_tasks (
  1420. id_log mediumint(8) NOT NULL auto_increment,
  1421. id_task smallint(5) NOT NULL default '0',
  1422. time_run int(10) NOT NULL default '0',
  1423. time_taken float NOT NULL default '0',
  1424. PRIMARY KEY (id_log)
  1425. ) ENGINE=MyISAM{$db_collation};
  1426. ---#
  1427. ---# Adding new scheduled task setting...
  1428. ---{
  1429. if (!isset($modSettings['next_task_time']))
  1430. {
  1431. upgrade_query("
  1432. INSERT INTO {$db_prefix}settings
  1433. (variable, value)
  1434. VALUES
  1435. ('next_task_time', '0')");
  1436. }
  1437. ---}
  1438. ---#
  1439. ---# Setting the birthday email template if not set...
  1440. ---{
  1441. if (!isset($modSettings['birthday_email']))
  1442. {
  1443. upgrade_query("
  1444. INSERT INTO {$db_prefix}settings
  1445. (variable, value)
  1446. VALUES
  1447. ('birthday_email', 'happy_birthday')");
  1448. }
  1449. ---}
  1450. ---#
  1451. /******************************************************************************/
  1452. --- Adding permission profiles for boards.
  1453. /******************************************************************************/
  1454. ---# Creating "permission_profiles" table...
  1455. CREATE TABLE IF NOT EXISTS {$db_prefix}permission_profiles (
  1456. id_profile smallint(5) NOT NULL auto_increment,
  1457. profile_name varchar(255) NOT NULL default '',
  1458. PRIMARY KEY (id_profile)
  1459. ) ENGINE=MyISAM{$db_collation};
  1460. ---#
  1461. ---# Adding profile columns to boards table...
  1462. ALTER TABLE {$db_prefix}boards
  1463. ADD id_profile smallint(5) unsigned NOT NULL default '1' AFTER member_groups;
  1464. ---#
  1465. ---# Adding profile columns to board permission table...
  1466. ALTER TABLE {$db_prefix}board_permissions
  1467. ADD id_profile smallint(5) unsigned NOT NULL default '1' AFTER id_group;
  1468. ALTER TABLE {$db_prefix}board_permissions
  1469. DROP PRIMARY KEY;
  1470. ALTER TABLE {$db_prefix}board_permissions
  1471. ADD PRIMARY KEY (id_group, id_profile, permission);
  1472. ---#
  1473. ---# Cleaning up some 2.0 Beta 1 permission profile bits...
  1474. ---{
  1475. $request = upgrade_query("
  1476. SELECT id_profile
  1477. FROM {$db_prefix}permission_profiles
  1478. WHERE profile_name = ''");
  1479. $profiles = array();
  1480. while ($row = smf_mysql_fetch_assoc($request))
  1481. $profiles[] = $row['id_profile'];
  1482. smf_mysql_free_result($request);
  1483. if (!empty($profiles))
  1484. {
  1485. $request = upgrade_query("
  1486. SELECT id_profile, name
  1487. FROM {$db_prefix}boards
  1488. WHERE id_profile IN (" . implode(',', $profiles) . ")");
  1489. $done_ids = array();
  1490. while ($row = smf_mysql_fetch_assoc($request))
  1491. {
  1492. if (isset($done_ids[$row['id_profile']]))
  1493. continue;
  1494. $done_ids[$row['id_profile']] = true;
  1495. $row['name'] = smf_mysql_real_escape_string($row['name']);
  1496. upgrade_query("
  1497. UPDATE {$db_prefix}permission_profiles
  1498. SET profile_name = '$row[name]'
  1499. WHERE id_profile = $row[id_profile]");
  1500. }
  1501. smf_mysql_free_result($request);
  1502. }
  1503. ---}
  1504. ---#
  1505. ---# Migrating old board profiles to profile system
  1506. ---{
  1507. // Doing this twice would be awful!
  1508. $request = upgrade_query("
  1509. SELECT COUNT(*)
  1510. FROM {$db_prefix}permission_profiles");
  1511. list ($profileCount) = smf_mysql_fetch_row($request);
  1512. smf_mysql_free_result($request);
  1513. if ($profileCount == 0)
  1514. {
  1515. // Everything starts off invalid.
  1516. upgrade_query("
  1517. UPDATE {$db_prefix}board_permissions
  1518. SET id_profile = 0");
  1519. // Insert a boat load of default profile permissions.
  1520. upgrade_query("
  1521. INSERT INTO {$db_prefix}permission_profiles
  1522. (id_profile, profile_name)
  1523. VALUES
  1524. (1, 'default'),
  1525. (2, 'no_polls'),
  1526. (3, 'reply_only'),
  1527. (4, 'read_only')");
  1528. // Update the default permissions, this is easy!
  1529. upgrade_query("
  1530. UPDATE {$db_prefix}board_permissions
  1531. SET id_profile = 1
  1532. WHERE id_board = 0");
  1533. // Load all the other permissions
  1534. $request = upgrade_query("
  1535. SELECT id_board, id_group, permission, add_deny
  1536. FROM {$db_prefix}board_permissions
  1537. WHERE id_profile = 0");
  1538. $all_perms = array();
  1539. while ($row = smf_mysql_fetch_assoc($request))
  1540. $all_perms[$row['id_board']][$row['id_group']][$row['permission']] = $row['add_deny'];
  1541. smf_mysql_free_result($request);
  1542. // Now we have the profile profiles for this installation. We now need to go through each board and work out what the permission profile should be!
  1543. $request = upgrade_query("
  1544. SELECT id_board, name, permission_mode
  1545. FROM {$db_prefix}boards");
  1546. $board_updates = array();
  1547. while ($row = smf_mysql_fetch_assoc($request))
  1548. {
  1549. $row['name'] = addslashes($row['name']);
  1550. // Is it a truely local permission board? If so this is a new profile!
  1551. if ($row['permission_mode'] == 1)
  1552. {
  1553. // I know we could cache this, but I think we need to be practical - this is slow but guaranteed to work.
  1554. upgrade_query("
  1555. INSERT INTO {$db_prefix}permission_profiles
  1556. (profile_name)
  1557. VALUES
  1558. ('$row[name]')");
  1559. $board_updates[smf_mysql_insert_id()][] = $row['id_board'];
  1560. }
  1561. // Otherwise, dear god, this is an old school "simple" permission...
  1562. elseif ($row['permission_mode'] > 1 && $row['permission_mode'] < 5)
  1563. {
  1564. $board_updates[$row['permission_mode']][] = $row['id_board'];
  1565. }
  1566. // Otherwise this is easy. It becomes default.
  1567. else
  1568. $board_updates[1][] = $row['id_board'];
  1569. }
  1570. smf_mysql_free_result($request);
  1571. // Update the board tables.
  1572. foreach ($board_updates as $profile => $boards)
  1573. {
  1574. if (empty($boards))
  1575. continue;
  1576. $boards = implode(',', $boards);
  1577. upgrade_query("
  1578. UPDATE {$db_prefix}boards
  1579. SET id_profile = $profile
  1580. WHERE id_board IN ($boards)");
  1581. // If it's a custom profile then update this too.
  1582. if ($profile > 4)
  1583. upgrade_query("
  1584. UPDATE {$db_prefix}board_permissions
  1585. SET id_profile = $profile
  1586. WHERE id_board IN ($boards)
  1587. AND id_profile = 0");
  1588. }
  1589. // Just in case we have any random permissions that didn't have boards.
  1590. upgrade_query("
  1591. DELETE FROM {$db_prefix}board_permissions
  1592. WHERE id_profile = 0");
  1593. }
  1594. ---}
  1595. ---#
  1596. ---# Removing old board permissions column...
  1597. ALTER TABLE {$db_prefix}board_permissions
  1598. DROP COLUMN id_board;
  1599. ---#
  1600. ---# Check the predefined profiles all have the right permissions.
  1601. ---{
  1602. // What are all the permissions people can have.
  1603. $mod_permissions = array(
  1604. 'moderate_board', 'post_new', 'post_reply_own', 'post_reply_any', 'poll_post', 'poll_add_any',
  1605. 'poll_remove_any', 'poll_view', 'poll_vote', 'poll_lock_any', 'poll_edit_any', 'report_any',
  1606. 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own', 'make_sticky',
  1607. 'lock_any', 'remove_any', 'move_any', 'merge_any', 'split_any', 'delete_any', 'modify_any', 'approve_posts',
  1608. 'post_attachment', 'view_attachments', 'post_unapproved_replies_any', 'post_unapproved_replies_own',
  1609. 'post_unapproved_attachments', 'post_unapproved_topics',
  1610. );
  1611. $no_poll_reg = array(
  1612. 'post_new', 'post_reply_own', 'post_reply_any', 'poll_view', 'poll_vote', 'report_any',
  1613. 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own',
  1614. 'post_attachment', 'view_attachments', 'remove_own', 'post_unapproved_replies_any', 'post_unapproved_replies_own',
  1615. 'post_unapproved_attachments', 'post_unapproved_topics',
  1616. );
  1617. $reply_only_reg = array(
  1618. 'post_reply_own', 'post_reply_any', 'poll_view', 'poll_vote', 'report_any',
  1619. 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own',
  1620. 'post_attachment', 'view_attachments', 'remove_own', 'post_unapproved_replies_any', 'post_unapproved_replies_own',
  1621. 'post_unapproved_attachments',
  1622. );
  1623. $read_only_reg = array(
  1624. 'poll_view', 'poll_vote', 'report_any', 'send_topic', 'mark_any_notify', 'mark_notify', 'view_attachments',
  1625. );
  1626. // Clear all the current predefined profiles.
  1627. upgrade_query("
  1628. DELETE FROM {$db_prefix}board_permissions
  1629. WHERE id_profile IN (2,3,4)");
  1630. // Get all the membergroups - cheating to use the fact id_group = 1 exists to get a group of 0.
  1631. $request = upgrade_query("
  1632. SELECT IF(id_group = 1, 0, id_group) AS id_group
  1633. FROM {$db_prefix}membergroups
  1634. WHERE id_group != 0
  1635. AND min_posts = -1");
  1636. $inserts = array();
  1637. while ($row = smf_mysql_fetch_assoc($request))
  1638. {
  1639. if ($row['id_group'] == 2 || $row['id_group'] == 3)
  1640. {
  1641. foreach ($mod_permissions as $permission)
  1642. {
  1643. $inserts[] = "($row[id_group], 2, '$permission')";
  1644. $inserts[] = "($row[id_group], 3, '$permission')";
  1645. $inserts[] = "($row[id_group], 4, '$permission')";
  1646. }
  1647. }
  1648. else
  1649. {
  1650. foreach ($no_poll_reg as $permission)
  1651. $inserts[] = "($row[id_group], 2, '$permission')";
  1652. foreach ($reply_only_reg as $permission)
  1653. $inserts[] = "($row[id_group], 3, '$permission')";
  1654. foreach ($read_only_reg as $permission)
  1655. $inserts[] = "($row[id_group], 4, '$permission')";
  1656. }
  1657. }
  1658. smf_mysql_free_result($request);
  1659. upgrade_query("
  1660. INSERT INTO {$db_prefix}board_permissions
  1661. (id_group, id_profile, permission)
  1662. VALUES (-1, 2, 'poll_view'),
  1663. (-1, 3, 'poll_view'),
  1664. (-1, 4, 'poll_view'),
  1665. " . implode(', ', $inserts));
  1666. ---}
  1667. ---#
  1668. ---# Adding inherited permissions...
  1669. ALTER TABLE {$db_prefix}membergroups
  1670. ADD id_parent smallint(5) NOT NULL default '-2';
  1671. ---#
  1672. ---# Make sure admins and moderators don't inherit...
  1673. UPDATE {$db_prefix}membergroups
  1674. SET id_parent = -2
  1675. WHERE id_group = 1
  1676. OR id_group = 3;
  1677. ---#
  1678. ---# Deleting old permission settings...
  1679. DELETE FROM {$db_prefix}settings
  1680. WHERE VARIABLE IN ('permission_enable_by_board', 'autoOptDatabase');
  1681. ---#
  1682. ---# Removing old permission_mode column...
  1683. ALTER TABLE {$db_prefix}boards
  1684. DROP COLUMN permission_mode;
  1685. ---#
  1686. /******************************************************************************/
  1687. --- Adding Some Additional Functionality.
  1688. /******************************************************************************/
  1689. ---# Adding column to hold the boards being ignored ...
  1690. ALTER TABLE {$db_prefix}members
  1691. ADD ignore_boards text NOT NULL;
  1692. ---#
  1693. ---# Purge flood control ...
  1694. DELETE FROM {$db_prefix}log_floodcontrol;
  1695. ---#
  1696. ---# Adding advanced flood control ...
  1697. ALTER TABLE {$db_prefix}log_floodcontrol
  1698. ADD log_type varchar(8) NOT NULL default 'post';
  1699. ---#
  1700. ---# Sorting out flood control keys ...
  1701. ALTER TABLE {$db_prefix}log_floodcontrol
  1702. DROP PRIMARY KEY,
  1703. ADD PRIMARY KEY (ip(16), log_type(8));
  1704. ---#
  1705. ---# Adding guest voting ...
  1706. ALTER TABLE {$db_prefix}polls
  1707. ADD guest_vote tinyint(3) NOT NULL default '0';
  1708. DELETE FROM {$db_prefix}log_polls
  1709. WHERE id_member < 0;
  1710. ALTER TABLE {$db_prefix}log_polls
  1711. DROP PRIMARY KEY;
  1712. ALTER TABLE {$db_prefix}log_polls
  1713. ADD INDEX id_poll (id_poll, id_member, id_choice);
  1714. ---#
  1715. ---# Implementing admin feature toggles.
  1716. ---{
  1717. if (!isset($modSettings['admin_features']))
  1718. {
  1719. // Work out what they used to have enabled.
  1720. $enabled_features = array('rg');
  1721. if (!empty($modSettings['cal_enabled']))
  1722. $enabled_features[] = 'cd';
  1723. if (!empty($modSettings['karmaMode']))
  1724. $enabled_features[] = 'k';
  1725. if (!empty($modSettings['modlog_enabled']))
  1726. $enabled_features[] = 'ml';
  1727. if (!empty($modSettings['paid_enabled']))
  1728. $enabled_features[] = 'ps';
  1729. $enabled_features = implode(',', $enabled_features);
  1730. upgrade_query("
  1731. INSERT INTO {$db_prefix}settings
  1732. (variable, value)
  1733. VALUES
  1734. ('admin_features', '$enabled_features')");
  1735. }
  1736. ---}
  1737. ---#
  1738. ---# Adding advanced password brute force protection to "members" table...
  1739. ALTER TABLE {$db_prefix}members
  1740. ADD passwd_flood varchar(12) NOT NULL default '';
  1741. ---#
  1742. /******************************************************************************/
  1743. --- Adding some columns to moderation log
  1744. /******************************************************************************/
  1745. ---# Add the columns and the keys to log_actions ...
  1746. ALTER TABLE {$db_prefix}log_actions
  1747. ADD id_board smallint(5) unsigned NOT NULL default '0',
  1748. ADD id_topic mediumint(8) unsigned NOT NULL default '0',
  1749. ADD id_msg int(10) unsigned NOT NULL default '0',
  1750. ADD KEY id_board (id_board),
  1751. ADD KEY id_msg (id_msg);
  1752. ---#
  1753. ---# Add the user log...
  1754. ALTER TABLE {$db_prefix}log_actions
  1755. ADD id_log tinyint(3) unsigned NOT NULL default '1',
  1756. ADD KEY id_log (id_log);
  1757. ---#
  1758. ---# Update the information already in log_actions
  1759. ---{
  1760. $request = upgrade_query("
  1761. SELECT COUNT(*)
  1762. FROM {$db_prefix}log_actions");
  1763. list($totalActions) = smf_mysql_fetch_row($request);
  1764. smf_mysql_free_result($request);
  1765. $_GET['m'] = !empty($_GET['m']) ? (int) $_GET['m'] : '0';
  1766. $step_progress['total'] = $totalActions;
  1767. $step_progress['current'] = $_GET['m'];
  1768. while ($_GET['m'] < $totalActions)
  1769. {
  1770. nextSubStep($substep);
  1771. $mrequest = upgrade_query("
  1772. SELECT id_action, extra, id_board, id_topic, id_msg
  1773. FROM {$db_prefix}log_actions
  1774. LIMIT $_GET[m], 500");
  1775. while ($row = smf_mysql_fetch_assoc($mrequest))
  1776. {
  1777. if (!empty($row['id_board']) || !empty($row['id_topic']) || !empty($row['id_msg']))
  1778. continue;
  1779. $row['extra'] = @unserialize($row['extra']);
  1780. // Corrupt?
  1781. $row['extra'] = is_array($row['extra']) ? $row['extra'] : array();
  1782. if (!empty($row['extra']['board']))
  1783. {
  1784. $board_id = (int) $row['extra']['board'];
  1785. unset($row['extra']['board']);
  1786. }
  1787. else
  1788. $board_id = '0';
  1789. if (!empty($row['extra']['board_to']) && empty($board_id))
  1790. {
  1791. $board_id = (int) $row['extra']['board_to'];
  1792. unset($row['extra']['board_to']);
  1793. }
  1794. if (!empty($row['extra']['topic']))
  1795. {
  1796. $topic_id = (int) $row['extra']['topic'];
  1797. unset($row['extra']['topic']);
  1798. if (empty($board_id))
  1799. {
  1800. $trequest = upgrade_query("
  1801. SELECT id_board
  1802. FROM {$db_prefix}topics
  1803. WHERE id_topic=$topic_id
  1804. LIMIT 1");
  1805. if (smf_mysql_num_rows($trequest))
  1806. list($board_id) = smf_mysql_fetch_row($trequest);
  1807. smf_mysql_free_result($trequest);
  1808. }
  1809. }
  1810. else
  1811. $topic_id = '0';
  1812. if(!empty($row['extra']['message']))
  1813. {
  1814. $msg_id = (int) $row['extra']['message'];
  1815. unset($row['extra']['message']);
  1816. if (empty($topic_id) || empty($board_id))
  1817. {
  1818. $trequest = upgrade_query("
  1819. SELECT id_board, id_topic
  1820. FROM {$db_prefix}messages
  1821. WHERE id_msg=$msg_id
  1822. LIMIT 1");
  1823. if (smf_mysql_num_rows($trequest))
  1824. list($board_id, $topic_id) = smf_mysql_fetch_row($trequest);
  1825. smf_mysql_free_result($trequest);
  1826. }
  1827. }
  1828. else
  1829. $msg_id = '0';
  1830. $row['extra'] = addslashes(serialize($row['extra']));
  1831. 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]");
  1832. }
  1833. $_GET['m'] += 500;
  1834. $step_progress['current'] = $_GET['m'];
  1835. }
  1836. unset($_GET['m']);
  1837. ---}
  1838. ---#
  1839. /******************************************************************************/
  1840. --- Create a repository for the javascript files from Simple Machines...
  1841. /******************************************************************************/
  1842. ---# Creating repository table ...
  1843. CREATE TABLE IF NOT EXISTS {$db_prefix}admin_info_files (
  1844. id_file tinyint(4) unsigned NOT NULL auto_increment,
  1845. filename varchar(255) NOT NULL default '',
  1846. path varchar(255) NOT NULL default '',
  1847. parameters varchar(255) NOT NULL default '',
  1848. data text NOT NULL,
  1849. filetype varchar(255) NOT NULL default '',
  1850. PRIMARY KEY (id_file),
  1851. KEY filename (filename(30))
  1852. ) ENGINE=MyISAM{$db_collation};
  1853. ---#
  1854. ---# Add in the files to get from Simple Machines...
  1855. INSERT IGNORE INTO {$db_prefix}admin_info_files
  1856. (id_file, filename, path, parameters)
  1857. VALUES
  1858. (1, 'current-version.js', '/smf/', 'version=%3$s'),
  1859. (2, 'detailed-version.js', '/smf/', 'language=%1$s&version=%3$s'),
  1860. (3, 'latest-news.js', '/smf/', 'language=%1$s&format=%2$s'),
  1861. (4, 'latest-packages.js', '/smf/', 'language=%1$s&version=%3$s'),
  1862. (5, 'latest-smileys.js', '/smf/', 'language=%1$s&version=%3$s'),
  1863. (6, '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. ---#