[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id$ 10 */ 11 12 /** 13 * Upgrade Script: 1.2.12, 1.2.13 or 1.2.14 14 */ 15 16 $upgrade_detail = array( 17 "revert_all_templates" => 0, 18 "revert_all_themes" => 0, 19 "revert_all_settings" => 0, 20 "requires_deactivated_plugins" => 1, 21 ); 22 23 @set_time_limit(0); 24 25 // We need to globalize $db here because when this script is called 26 // during load_module $db is not globalized in the function 27 global $db; 28 29 // FIRST STEP IS FOR INTEGER CONVERSION PROJECT 30 31 function upgrade12_dbchanges() 32 { 33 global $db, $output, $mybb; 34 35 $output->print_header("Integer Conversion Project"); 36 37 $perpage = 10000; 38 39 $to_int = array( 40 "announcements" => array("aid", "allowhtml", "allowmycode", "allowsmilies"), 41 "forumpermissions" => array("pid", "canview","canviewthreads","candlattachments","canpostthreads","canpostreplys","canpostattachments","canratethreads","caneditposts","candeleteposts","candeletethreads","caneditattachments","canpostpolls","canvotepolls","cansearch"), 42 "forums" => array("fid", "active","open","allowhtml","allowmycode","allowsmilies","allowimgcode","allowpicons","allowtratings","usepostcounts","showinjump","modposts","modthreads","modattachments","overridestyle"), 43 "groupleaders" => array("lid", "canmanagemembers","canmanagerequests"), 44 "helpdocs" => array("hid", "usetranslation","enabled"), 45 "helpsections" => array("sid", "usetranslation","enabled"), 46 "moderators" => array("mid", "caneditposts","candeleteposts","canviewips","canopenclosethreads","canmanagethreads","canmovetononmodforum"), 47 "mycode" => array("cid", "active"), 48 "polls" => array("pid", "closed","multiple","public"), 49 "posts" => array("pid", "includesig","smilieoff"), 50 "privatemessages" => array("pmid", "includesig","smilieoff"), 51 "profilefields" => array("fid", "required","editable","hidden"), 52 "smilies" => array("sid", "showclickable"), 53 "usergroups" => array("gid","isbannedgroup","canview","canviewthreads","canviewprofiles","candlattachments","canpostthreads","canpostreplys","canpostattachments","canratethreads","caneditposts","candeleteposts","candeletethreads","caneditattachments","canpostpolls","canvotepolls","canusepms","cansendpms","cantrackpms","candenypmreceipts","cansendemail","canviewmemberlist","canviewcalendar","canviewonline","canviewwolinvis","canviewonlineips","cancp","issupermod","cansearch","canusercp","canuploadavatars","canratemembers","canchangename","showforumteam","usereputationsystem","cangivereputations","candisplaygroup","cancustomtitle"), 54 "users" => array("uid","allownotices","hideemail","invisible","receivepms","pmpopup","pmnotify","remember","showsigs","showavatars","showquickreply","showredirect","away"), 55 "threads" => array("tid", "closed") 56 ); 57 58 if(!$db->field_exists('pmpopup', "users")) 59 { 60 $pmpopup_key = array_search('pmpopup', $to_int['users']); 61 if($pmpopup_key) 62 { 63 unset($to_int['users'][$pmpopup_key]); 64 } 65 } 66 67 // Continuing? 68 if($mybb->input['last_table']) 69 { 70 $current_table = $mybb->input['last_table']; 71 } 72 else 73 { 74 $current_table = array_keys($to_int); 75 $current_table = $current_table[0]; 76 echo "<p>MyBB 1.4 represents a huge leap forward for the MyBB project.</p><p>Due to this, lots of information in the database needs to be converted to a new format.</p>"; 77 } 78 79 echo "<p>MyBB is now currently converting a section of data to the new format, this may take a while.</p>"; 80 81 $remaining = $perpage; 82 83 $final_table = array_keys($to_int); 84 $final_table = $final_table[count($final_table)-1]; 85 86 $next_act = "12_dbchanges"; 87 88 $start = intval($mybb->input['start']); 89 $count = $mybb->input['count']; 90 91 foreach($to_int as $table => $columns) 92 { 93 if($table == $current_table) 94 { 95 $form_fields['last_table'] = $current_table; 96 if($remaining <= 0) 97 { 98 break; 99 } 100 $columns_sql = implode(",", $columns); 101 $primary_key = $columns[0]; 102 if(!$mybb->input['count']) 103 { 104 $query = $db->simple_select($table, "COUNT({$primary_key}) AS count"); 105 $count = $form_fields['count'] = $db->fetch_field($query, "count"); 106 } 107 if($start <= $count) 108 { 109 $end = $start+$perpage; 110 if($end > $count) $end = $count; 111 echo "<p>{$table}: Converting {$start} to {$end} of {$count}</p>"; 112 flush(); 113 $form_fields['start'] = $perpage+$start; 114 115 $query = $db->simple_select($table, $columns_sql, "", array('order_by' => $pimary_key, 'limit_start' => $start, 'limit' => $remaining)); 116 while($row = $db->fetch_array($query)) 117 { 118 $updated_row = array(); 119 foreach($columns as $column) 120 { 121 if($column == $primary_key || is_int($row[$column])) continue; 122 if($row[$column] == "yes" || $row[$column] == "on") 123 { 124 $updated_row[$column] = 1; 125 } 126 else if($row[$column] == "off" || $row[$column] == "no" || $row[$column] == 'new' || $row[$column] == "") 127 { 128 $updated_row[$column] = 0; 129 } 130 } 131 if(count($updated_row) > 0) 132 { 133 $db->update_query($table, $updated_row, "{$primary_key}={$row[$primary_key]}"); 134 } 135 --$remaining; 136 } 137 } 138 else 139 { 140 echo "<p>{$table}: Converting column type</p>"; 141 flush(); 142 $change_column = array(); 143 foreach($columns as $column) 144 { 145 // Closed does not get converted to an int 146 if($column == $primary_key || ($table == "threads" && $column == "closed")) 147 { 148 continue; 149 } 150 $change_column[] = "MODIFY {$column} int(1) NOT NULL default '0'"; 151 } 152 $db->write_query("ALTER TABLE ".TABLE_PREFIX."{$table} ".implode(", ", $change_column)); 153 154 if($table == $final_table) 155 { 156 // Finished, after all this! 157 $next_act = "12_dbchanges1"; 158 } 159 else 160 { 161 $tbl_keys = array_keys($to_int); 162 $current = array_search($current_table, $tbl_keys); 163 $form_fields['last_table'] = $current_table = $tbl_keys[$current+1]; 164 $form_fields['start'] = $start = 0; 165 $form_fields['count'] = $count = $mybb->input['count'] = 0; 166 } 167 } 168 } 169 } 170 171 // Still converting 172 if($next_act == "12_dbchanges") 173 { 174 echo "<p>Done</p>"; 175 echo "<p>Click next to continue with the integer conversion process.</p>"; 176 foreach($form_fields as $key => $val) 177 { 178 echo "<input type=\"hidden\" name=\"{$key}\" value=\"{$val}\" />"; 179 } 180 global $footer_extra; 181 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 182 $output->print_footer($next_act); 183 } 184 else 185 { 186 // Convert settings table 187 $query = $db->write_query("UPDATE ".TABLE_PREFIX."settings SET value=1 WHERE value='yes' OR value='on'"); 188 $query = $db->write_query("UPDATE ".TABLE_PREFIX."settings SET value=0 WHERE value='no' OR value='off'"); 189 echo "<p>Done</p>"; 190 echo "<p><strong>The integrer conversion process is now complete.</strong></p>"; 191 echo "<p>Click next to continue with the upgrade process.</p>"; 192 global $footer_extra; 193 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 194 195 $output->print_footer($next_act); 196 } 197 } 198 199 function upgrade12_dbchanges1() 200 { 201 global $db, $output, $mybb; 202 203 $output->print_header("Performing Queries"); 204 205 echo "<p>Performing necessary upgrade queries..</p>"; 206 echo "<p>Adding index to private messages table ... "; 207 flush(); 208 209 $db->write_query("ALTER TABLE ".TABLE_PREFIX."privatemessages ADD INDEX ( `uid` )"); 210 211 echo "done.</p>"; 212 213 $contents = "<p>Click next to continue with the upgrade process.</p>"; 214 $output->print_contents($contents); 215 216 global $footer_extra; 217 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 218 219 $output->print_footer("12_dbchanges_post1"); 220 } 221 222 function upgrade12_dbchanges_post1() 223 { 224 global $db, $output, $mybb; 225 226 $output->print_header("Performing Queries"); 227 228 echo "<p>Performing necessary upgrade queries..</p>"; 229 echo "<p>Adding index to posts table ... "; 230 flush(); 231 232 // This will take a LONG time on huge post databases, so we only run it isolted from most of the other queries 233 $db->write_query("ALTER TABLE ".TABLE_PREFIX."posts ADD INDEX ( `visible` )"); 234 235 echo "done.</p>"; 236 flush(); 237 238 $contents = "<p>Click next to continue with the upgrade process.</p>"; 239 $output->print_contents($contents); 240 241 global $footer_extra; 242 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 243 244 $output->print_footer("12_dbchanges_post2"); 245 } 246 247 function upgrade12_dbchanges_post2() 248 { 249 global $db, $output, $mybb; 250 251 $output->print_header("Performing Queries"); 252 253 echo "<p>Performing necessary upgrade queries..</p>"; 254 255 if($db->field_exists('longipaddress', "posts")) 256 { 257 echo "<p>Dropping longipaddress column in posts table ... "; 258 flush(); 259 260 $db->write_query("ALTER TABLE ".TABLE_PREFIX."posts DROP longipaddress;"); 261 262 echo "done.</p>"; 263 flush(); 264 } 265 266 echo "<p>Adding longipaddress column to posts table ... "; 267 flush(); 268 269 $db->write_query("ALTER TABLE ".TABLE_PREFIX."posts ADD longipaddress int(11) NOT NULL default '0' AFTER ipaddress"); 270 271 echo "done.</p>"; 272 flush(); 273 274 $contents = "<p>Click next to continue with the upgrade process.</p>"; 275 $output->print_contents($contents); 276 277 global $footer_extra; 278 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 279 280 $output->print_footer("12_dbchanges_user"); 281 } 282 283 function upgrade12_dbchanges_user() 284 { 285 global $db, $output, $mybb; 286 287 $output->print_header("Performing Queries"); 288 289 echo "<p>Performing necessary upgrade queries..</p>"; 290 echo "<p>Adding index to users table ... "; 291 flush(); 292 293 // This will take a LONG time on huge user databases, so we only run it isolted from most of the other queries 294 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD INDEX ( `lastvisit` )"); 295 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD INDEX ( `regdate` )"); 296 297 echo "done.</p>"; 298 flush(); 299 300 $contents = "<p>Click next to continue with the upgrade process.</p>"; 301 $output->print_contents($contents); 302 303 global $footer_extra; 304 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 305 306 $output->print_footer("12_dbchanges2"); 307 } 308 309 function upgrade12_dbchanges2() 310 { 311 global $db, $output, $mybb; 312 313 $output->print_header("Performing Queries"); 314 315 echo "<p>Performing necessary upgrade queries..</p>"; 316 flush(); 317 318 if($db->field_exists('recipients', "privatemessages")) 319 { 320 $db->write_query("ALTER TABLE ".TABLE_PREFIX."privatemessages DROP recipients;"); 321 } 322 $db->write_query("ALTER TABLE ".TABLE_PREFIX."privatemessages ADD recipients text NOT NULL AFTER fromid"); 323 324 if($db->field_exists('deletetime', "privatemessages")) 325 { 326 $db->write_query("ALTER TABLE ".TABLE_PREFIX."privatemessages DROP deletetime;"); 327 } 328 $db->write_query("ALTER TABLE ".TABLE_PREFIX."privatemessages ADD deletetime bigint(30) NOT NULL default '0' AFTER dateline"); 329 330 if($db->field_exists('maxpmrecipients', "usergroups")) 331 { 332 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups DROP maxpmrecipients;"); 333 } 334 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups ADD maxpmrecipients int(4) NOT NULL default '5' AFTER pmquota"); 335 336 if($db->field_exists('canwarnusers', "usergroups")) 337 { 338 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups DROP canwarnusers;"); 339 } 340 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups ADD canwarnusers int(1) NOT NULL default '0' AFTER cancustomtitle"); 341 342 if($db->field_exists('lastip', "users")) 343 { 344 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP lastip;"); 345 } 346 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD lastip varchar(50) NOT NULL default '' AFTER regip"); 347 348 349 350 if($db->field_exists('coppauser', "users")) 351 { 352 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP coppauser;"); 353 } 354 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD coppauser int(1) NOT NULL default '0'"); 355 356 if($db->field_exists('classicpostbit', 'users')) 357 { 358 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP classicpostbit;"); 359 } 360 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD classicpostbit int(1) NOT NULL default '0'"); 361 362 if($db->field_exists('canreceivewarnings', "usergroups")) 363 { 364 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups DROP canreceivewarnings;"); 365 } 366 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups ADD canreceivewarnings int(1) NOT NULL default '0' AFTER canwarnusers"); 367 368 if($db->field_exists('maxwarningsday', "usergroups")) 369 { 370 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups DROP maxwarningsday;"); 371 } 372 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups ADD maxwarningsday int(3) NOT NULL default '3' AFTER canreceivewarnings"); 373 374 $db->update_query("usergroups", array('canreceivewarnings' => 1), "cancp != 1"); 375 $db->update_query("usergroups", array('maxwarningsday' => 3, 'canwarnusers' => 1), "cancp=1 OR issupermod=1 OR gid=6"); // Admins, Super Mods and Mods 376 377 if($db->field_exists('canmodcp', "usergroups")) 378 { 379 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups DROP canmodcp;"); 380 } 381 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups ADD canmodcp int(1) NOT NULL default '0' AFTER maxwarningsday"); 382 $db->update_query("usergroups", array('canmodcp' => 1), "cancp=1 OR issupermod=1 OR gid='6'"); // Admins, Super Mods and Mods 383 384 if($db->field_exists('newpms', "users")) 385 { 386 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP newpms;"); 387 } 388 389 if($db->field_exists('keywords', "searchlog")) 390 { 391 $db->write_query("ALTER TABLE ".TABLE_PREFIX."searchlog DROP keywords;"); 392 } 393 $db->write_query("ALTER TABLE ".TABLE_PREFIX."searchlog ADD keywords text NOT NULL AFTER querycache"); 394 395 if($db->field_exists('canaddpublicevents', "usergroups") && !$db->field_exists('canaddevents', "usergroups")) 396 { 397 $db->update_query("usergroups", array('canaddpublicevents' => 0), "canaddpublicevents='no'"); 398 $db->update_query("usergroups", array('canaddpublicevents' => 1), "canaddpublicevents='yes'"); 399 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups CHANGE canaddpublicevents canaddevents int(1) NOT NULL default '0';"); 400 } 401 402 if($db->field_exists('canaddprivateevents', "usergroups")) 403 { 404 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups DROP canaddprivateevents;"); 405 } 406 407 if($db->field_exists('canbypasseventmod', "usergroups")) 408 { 409 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups DROP canbypasseventmod;"); 410 } 411 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups ADD canbypasseventmod int(1) NOT NULL default '0' AFTER canaddevents;"); 412 413 if($db->field_exists('canmoderateevents', "usergroups")) 414 { 415 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups DROP canmoderateevents;"); 416 } 417 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups ADD canmoderateevents int(1) NOT NULL default '0' AFTER canbypasseventmod;"); 418 $db->update_query("usergroups", array('canbypasseventmod' => 1, 'canmoderateevents' => 1), "cancp=1 OR issupermod=1"); 419 $db->update_query("usergroups", array('canbypasseventmod' => 0, 'canmoderateevents' => 0), "cancp=0 AND issupermod=0"); 420 $db->update_query("usergroups", array('canaddevents' => 0), "gid='1'"); 421 422 $db->drop_table("maillogs"); 423 $db->drop_table("mailerrors"); 424 $db->drop_table("promotions"); 425 $db->drop_table("promotionlogs"); 426 $db->drop_table("massemails"); 427 428 $collation = $db->build_create_table_collation(); 429 430 $db->write_query("CREATE TABLE ".TABLE_PREFIX."massemails ( 431 mid int unsigned NOT NULL auto_increment, 432 uid int unsigned NOT NULL default '0', 433 subject varchar(200) NOT NULL default '', 434 message text NOT NULL, 435 htmlmessage text NOT NULL, 436 type tinyint(1) NOT NULL default '0', 437 format tinyint(1) NOT NULL default '0', 438 dateline bigint(30) NOT NULL default '0', 439 senddate bigint(30) NOT NULL default '0', 440 status tinyint(1) NOT NULL default '0', 441 sentcount int unsigned NOT NULL default '0', 442 totalcount int unsigned NOT NULL default '0', 443 conditions text NOT NULL, 444 perpage smallint(4) NOT NULL default '50', 445 PRIMARY KEY(mid) 446 ) ENGINE=MyISAM{$collation};"); 447 448 $db->write_query("CREATE TABLE ".TABLE_PREFIX."maillogs ( 449 mid int unsigned NOT NULL auto_increment, 450 subject varchar(200) not null default '', 451 message TEXT NOT NULL, 452 dateline bigint(30) NOT NULL default '0', 453 fromuid int unsigned NOT NULL default '0', 454 fromemail varchar(200) not null default '', 455 touid bigint(30) NOT NULL default '0', 456 toemail varchar(200) NOT NULL default '', 457 tid int unsigned NOT NULL default '0', 458 ipaddress varchar(20) NOT NULL default '', 459 PRIMARY KEY(mid) 460 ) ENGINE=MyISAM{$collation};"); 461 462 $db->write_query("CREATE TABLE ".TABLE_PREFIX."mailerrors( 463 eid int unsigned NOT NULL auto_increment, 464 subject varchar(200) NOT NULL default '', 465 message TEXT NOT NULL, 466 toaddress varchar(150) NOT NULL default '', 467 fromaddress varchar(150) NOT NULL default '', 468 dateline bigint(30) NOT NULL default '0', 469 error text NOT NULL, 470 smtperror varchar(200) NOT NULL default '', 471 smtpcode int(5) NOT NULL default '0', 472 PRIMARY KEY(eid) 473 ) ENGINE=MyISAM{$collation};"); 474 475 $db->write_query("CREATE TABLE ".TABLE_PREFIX."promotions ( 476 pid int unsigned NOT NULL auto_increment, 477 title varchar(120) NOT NULL default '', 478 description text NOT NULL, 479 enabled tinyint(1) NOT NULL default '1', 480 logging tinyint(1) NOT NULL default '0', 481 posts int NOT NULL default '0', 482 posttype char(2) NOT NULL default '', 483 registered int NOT NULL default '0', 484 registeredtype varchar(20) NOT NULL default '', 485 reputations int NOT NULL default '0', 486 reputationtype char(2) NOT NULL default '', 487 requirements varchar(200) NOT NULL default '', 488 originalusergroup varchar(120) NOT NULL default '0', 489 newusergroup smallint unsigned NOT NULL default '0', 490 usergrouptype varchar(120) NOT NULL default '0', 491 PRIMARY KEY (pid) 492 ) ENGINE=MyISAM{$collation};"); 493 494 $db->write_query("CREATE TABLE ".TABLE_PREFIX."promotionlogs( 495 plid int unsigned NOT NULL auto_increment, 496 pid int unsigned NOT NULL default '0', 497 uid int unsigned NOT NULL default '0', 498 oldusergroup varchar(200) NOT NULL default '0', 499 newusergroup smallint unsigned NOT NULL default '0', 500 dateline bigint(30) NOT NULL default '0', 501 type varchar(9) NOT NULL default 'primary', 502 PRIMARY KEY(plid) 503 ) ENGINE=MyISAM{$collation};"); 504 505 if($db->field_exists('maxemails', "usergroups")) 506 { 507 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups DROP maxemails;"); 508 } 509 $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups ADD maxemails int(3) NOT NULL default '5' AFTER cansendemail"); 510 511 if($db->field_exists('parseorder', "mycode")) 512 { 513 $db->write_query("ALTER TABLE ".TABLE_PREFIX."mycode DROP parseorder;"); 514 } 515 $db->write_query("ALTER TABLE ".TABLE_PREFIX."mycode ADD parseorder smallint unsigned NOT NULL default '0' AFTER active"); 516 517 if($db->field_exists('mod_edit_posts', "forums")) 518 { 519 $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums DROP mod_edit_posts;"); 520 } 521 $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums ADD mod_edit_posts int(1) NOT NULL default '0' AFTER modthreads"); 522 523 if($db->field_exists('pmpopup', "users") && !$db->field_exists('pmnotice', "users")) 524 { 525 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users CHANGE pmpopup pmnotice int(1) NOT NULL default '0'"); 526 } 527 528 $db->drop_table("tasks"); 529 $db->drop_table("tasklog"); 530 531 $db->write_query("CREATE TABLE ".TABLE_PREFIX."tasks ( 532 tid int unsigned NOT NULL auto_increment, 533 title varchar(120) NOT NULL default '', 534 description text NOT NULL, 535 file varchar(30) NOT NULL default '', 536 minute varchar(200) NOT NULL default '', 537 hour varchar(200) NOT NULL default '', 538 day varchar(100) NOT NULL default '', 539 month varchar(30) NOT NULL default '', 540 weekday varchar(15) NOT NULL default '', 541 nextrun bigint(30) NOT NULL default '0', 542 lastrun bigint(30) NOT NULL default '0', 543 enabled int(1) NOT NULL default '1', 544 logging int(1) NOT NULL default '0', 545 locked bigint(30) NOT NULL default '0', 546 PRIMARY KEY(tid) 547 ) ENGINE=MyISAM{$collation};"); 548 549 550 $db->write_query("CREATE TABLE ".TABLE_PREFIX."tasklog ( 551 lid int unsigned NOT NULL auto_increment, 552 tid int unsigned NOT NULL default '0', 553 dateline bigint(30) NOT NULL default '0', 554 data text NOT NULL, 555 PRIMARY KEY(lid) 556 ) ENGINE=MyISAM{$collation};"); 557 558 559 include_once MYBB_ROOT."inc/functions_task.php"; 560 $tasks = file_get_contents(INSTALL_ROOT.'resources/tasks.xml'); 561 $parser = new XMLParser($tasks); 562 $parser->collapse_dups = 0; 563 $tree = $parser->get_tree(); 564 565 // Insert scheduled tasks 566 foreach($tree['tasks'][0]['task'] as $task) 567 { 568 $new_task = array( 569 'title' => $db->escape_string($task['title'][0]['value']), 570 'description' => $db->escape_string($task['description'][0]['value']), 571 'file' => $db->escape_string($task['file'][0]['value']), 572 'minute' => $db->escape_string($task['minute'][0]['value']), 573 'hour' => $db->escape_string($task['hour'][0]['value']), 574 'day' => $db->escape_string($task['day'][0]['value']), 575 'weekday' => $db->escape_string($task['weekday'][0]['value']), 576 'month' => $db->escape_string($task['month'][0]['value']), 577 'enabled' => $db->escape_string($task['enabled'][0]['value']), 578 'logging' => $db->escape_string($task['logging'][0]['value']) 579 ); 580 581 $new_task['nextrun'] = fetch_next_run($new_task); 582 583 $db->insert_query("tasks", $new_task); 584 $taskcount++; 585 } 586 587 if($db->table_exists("favorites") && !$db->table_exists("threadsubscriptions")) 588 { 589 $db->write_query("RENAME TABLE ".TABLE_PREFIX."favorites TO ".TABLE_PREFIX."threadsubscriptions"); 590 } 591 592 if($db->field_exists('fid', "threadsubscriptions")) 593 { 594 $db->write_query("ALTER TABLE ".TABLE_PREFIX."threadsubscriptions CHANGE fid sid int unsigned NOT NULL auto_increment"); 595 } 596 597 if($db->field_exists('type', "threadsubscriptions")) 598 { 599 $db->update_query("threadsubscriptions", array('type' => 0), "type='f'"); 600 $db->update_query("threadsubscriptions", array('type' => 1), "type='s'"); 601 $db->write_query("ALTER TABLE ".TABLE_PREFIX."threadsubscriptions CHANGE type notification int(1) NOT NULL default '0'"); 602 } 603 604 if($db->field_exists('dateline', "threadsubscriptions")) 605 { 606 $db->write_query("ALTER TABLE ".TABLE_PREFIX."threadsubscriptions DROP dateline;"); 607 } 608 $db->write_query("ALTER TABLE ".TABLE_PREFIX."threadsubscriptions ADD dateline bigint(30) NOT NULL default '0'"); 609 610 if($db->field_exists('subscriptionkey', "threadsubscriptions")) 611 { 612 $db->write_query("ALTER TABLE ".TABLE_PREFIX."threadsubscriptions DROP subscriptionkey;"); 613 } 614 $db->write_query("ALTER TABLE ".TABLE_PREFIX."threadsubscriptions ADD subscriptionkey varchar(32) NOT NULL default ''"); 615 616 if($db->field_exists('emailnotify', "users")) 617 { 618 $db->update_query("users", array('emailnotify' => 0), "emailnotify='no' OR emailnotify='0'"); 619 $db->update_query("users", array('emailnotify' => 2), "emailnotify='yes' OR emailnotify='1'"); 620 $db->update_query("users", array('emailnotify' => 0), "emailnotify != 1 AND emailnotify != 2"); 621 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users CHANGE emailnotify subscriptionmethod int(1) NOT NULL default '0'"); 622 } 623 624 $db->drop_table("warninglevels"); 625 $db->drop_table("warningtypes"); 626 $db->drop_table("warnings"); 627 628 $db->write_query("CREATE TABLE ".TABLE_PREFIX."warninglevels ( 629 lid int unsigned NOT NULL auto_increment, 630 percentage int(3) NOT NULL default '0', 631 action text NOT NULL, 632 PRIMARY KEY(lid) 633 ) ENGINE=MyISAM{$collation};"); 634 635 $db->write_query("CREATE TABLE ".TABLE_PREFIX."warningtypes ( 636 tid int unsigned NOT NULL auto_increment, 637 title varchar(120) NOT NULL default '', 638 points int unsigned NOT NULL default '0', 639 expirationtime bigint(30) NOT NULL default '0', 640 PRIMARY KEY(tid) 641 ) ENGINE=MyISAM{$collation};"); 642 643 $db->write_query("CREATE TABLE ".TABLE_PREFIX."warnings ( 644 wid int unsigned NOT NULL auto_increment, 645 uid int unsigned NOT NULL default '0', 646 tid int unsigned NOT NULL default '0', 647 pid int unsigned NOT NULL default '0', 648 title varchar(120) NOT NULL default '', 649 points int unsigned NOT NULL default '0', 650 dateline bigint(30) NOT NULL default '0', 651 issuedby int unsigned NOT NULL default '0', 652 expires bigint(30) NOT NULL default '0', 653 expired int(1) NOT NULL default '0', 654 daterevoked bigint(30) NOT NULL default '0', 655 revokedby int unsigned NOT NULL default '0', 656 revokereason text NOT NULL, 657 notes text NOT NULL, 658 PRIMARY KEY(wid) 659 ) ENGINE=MyISAM{$collation};"); 660 661 if($db->field_exists('warningpoints', "users")) 662 { 663 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP warningpoints;"); 664 } 665 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD warningpoints int(3) NOT NULL default '0' AFTER unreadpms"); 666 667 if($db->field_exists('moderateposts', "users")) 668 { 669 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP moderateposts;"); 670 } 671 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD moderateposts int(1) NOT NULL default '0' AFTER warningpoints"); 672 673 if($db->field_exists('moderationtime', "users")) 674 { 675 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP moderationtime;"); 676 } 677 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD moderationtime bigint(30) NOT NULL default '0' AFTER moderateposts"); 678 679 if($db->field_exists('suspendposting', "users")) 680 { 681 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP suspendposting;"); 682 } 683 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD suspendposting int(1) NOT NULL default '0' AFTER moderationtime"); 684 685 if($db->field_exists('suspensiontime', "users")) 686 { 687 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP suspensiontime;"); 688 } 689 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD suspensiontime bigint(30) NOT NULL default '0' AFTER suspendposting"); 690 691 $db->write_query("ALTER TABLE ".TABLE_PREFIX."banned CHANGE oldadditionalgroups oldadditionalgroups TEXT NOT NULL"); 692 693 if($db->field_exists('birthdayprivacy', "users")) 694 { 695 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP birthdayprivacy;"); 696 } 697 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD birthdayprivacy varchar(4) NOT NULL default 'all' AFTER birthday"); 698 699 if($db->field_exists('birthdayprivacy', "users")) 700 { 701 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP birthdayprivacy;"); 702 } 703 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD birthdayprivacy varchar(4) NOT NULL default 'all' AFTER birthday"); 704 705 if($db->field_exists('longregip', "users")) 706 { 707 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP longregip;"); 708 } 709 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD longregip int(11) NOT NULL default '0' AFTER lastip"); 710 711 if($db->field_exists('longlastip', "users")) 712 { 713 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP longlastip;"); 714 } 715 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD longlastip int(11) NOT NULL default '0' AFTER lastip"); 716 717 // Unused column 718 if($db->field_exists('titles', "searchlog")) 719 { 720 $db->write_query("ALTER TABLE ".TABLE_PREFIX."searchlog DROP titles;"); 721 } 722 723 $db->drop_table("adminlog"); 724 $db->write_query("CREATE TABLE ".TABLE_PREFIX."adminlog ( 725 uid int unsigned NOT NULL default '0', 726 ipaddress varchar(50) NOT NULL default '', 727 dateline bigint(30) NOT NULL default '0', 728 module varchar(50) NOT NULL default '', 729 action varchar(50) NOT NULL default '', 730 data text NOT NULL, 731 KEY module (module, action) 732 ) ENGINE=MyISAM{$collation};"); 733 734 if($db->field_exists('data', "adminsessions")) 735 { 736 $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminsessions DROP data;"); 737 } 738 739 $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminsessions ADD data TEXT NOT NULL AFTER lastactive;"); 740 741 if($db->field_exists('isdefault', "settings")) 742 { 743 $db->write_query("ALTER TABLE ".TABLE_PREFIX."settings DROP isdefault;"); 744 } 745 $db->write_query("ALTER TABLE ".TABLE_PREFIX."settings ADD isdefault int(1) NOT NULL default '0' AFTER gid;"); 746 747 $setting_group_cache = array(); 748 $query = $db->simple_select("settinggroups", "gid, isdefault"); 749 while($settinggroup = $db->fetch_array($query)) 750 { 751 $setting_group_cache[$settinggroup['gid']] = $settinggroup['isdefault']; 752 } 753 754 $query = $db->simple_select("settings", "gid, sid"); 755 while($setting = $db->fetch_array($query)) 756 { 757 if($setting_group_cache[$setting['gid']] == 1) 758 { 759 $db->update_query("settings", array('isdefault' => 1), "sid = '{$setting['sid']}'", 1); 760 } 761 } 762 763 $db->update_query("settings", array('value' => 'classic'), "name='postlayout' AND value != 'horizontal'"); 764 765 $db->update_query("settings", array('optionscode' => $db->escape_string('php 766 <select name=\"upsetting[{$setting[\'name\']}]\"><option value=\"standard\">".($lang->setting_searchtype_standard?$lang->setting_searchtype_standard:"Standard")."</option>".($db->supports_fulltext("threads") && $db->supports_fulltext_boolean("posts")?"<option value=\"fulltext\"".($setting[\'value\']=="fulltext"?" selected=\"selected\"":"").">".($lang->setting_searchtype_fulltext?$lang->setting_searchtype_fulltext:"Full Text")."</option>":"")."</select>')), "name='searchtype'", 1); 767 768 $contents = "Done</p>"; 769 $contents .= "<p>Click next to continue with the upgrade process.</p>"; 770 $output->print_contents($contents); 771 772 global $footer_extra; 773 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 774 775 $output->print_footer("12_dbchanges3"); 776 } 777 778 function upgrade12_dbchanges3() 779 { 780 global $db, $output, $mybb; 781 782 $output->print_header("Converting Ban Filters"); 783 784 echo "<p>Converting existing banned IP addresses, email addresses and usernames..</p>"; 785 flush(); 786 787 $db->drop_table("banfilters"); 788 789 $collation = $db->build_create_table_collation(); 790 791 $db->write_query("CREATE TABLE ".TABLE_PREFIX."banfilters ( 792 fid int unsigned NOT NULL auto_increment, 793 filter varchar(200) NOT NULL default '', 794 type int(1) NOT NULL default '0', 795 lastuse bigint(30) NOT NULL default '0', 796 dateline bigint(30) NOT NULL default '0', 797 PRIMARY KEY (fid) 798 ) ENGINE=MyISAM{$collation};"); 799 800 // Now we convert all of the old bans in to the new system! 801 $ban_types = array('bannedips', 'bannedemails', 'bannedusernames'); 802 foreach($ban_types as $type) 803 { 804 // Some people put spaces or breaks (\r\n) instead, so we should take that into account. 805 $mybb->settings[$type] = str_replace(array("\n", "\r\n", "\r"), ",", $mybb->settings[$type]); 806 807 // Usernames can have spaces so don't replace those with commas. 808 if($type != 'bannedusernames') 809 { 810 $mybb->settings[$type] = str_replace(" ", ",", $mybb->settings[$type]); 811 } 812 813 $bans = explode(",", $mybb->settings[$type]); 814 $bans = array_unique($bans); 815 $bans = array_map("trim", $bans); 816 foreach($bans as $ban) 817 { 818 if(!$ban) 819 { 820 continue; 821 } 822 823 if($type == "bannedips") 824 { 825 $ban_type = 1; 826 } 827 else if($type == "bannedusernames") 828 { 829 $ban_type = 2; 830 } 831 else if($type == "bannedemails") 832 { 833 $ban_type = 3; 834 } 835 $new_ban = array( 836 "filter" => $db->escape_string($ban), 837 "type" => $ban_type, 838 "dateline" => TIME_NOW 839 ); 840 $db->insert_query("banfilters", $new_ban); 841 } 842 } 843 844 $contents = "Done</p>"; 845 $contents .= "<p>Click next to continue with the upgrade process.</p>"; 846 $output->print_contents($contents); 847 848 global $footer_extra; 849 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 850 851 $output->print_footer("12_dbchanges4"); 852 } 853 854 function upgrade12_dbchanges4() 855 { 856 global $db, $output, $mybb; 857 858 $output->print_header("Performing Queries"); 859 860 echo "<p>Performing necessary upgrade queries..</p>"; 861 flush(); 862 863 $db->drop_table("spiders"); 864 $db->drop_table("stats"); 865 866 $collation = $db->build_create_table_collation(); 867 868 $db->write_query("CREATE TABLE ".TABLE_PREFIX."spiders ( 869 sid int unsigned NOT NULL auto_increment, 870 name varchar(100) NOT NULL default '', 871 theme int unsigned NOT NULL default '0', 872 language varchar(20) NOT NULL default '', 873 usergroup int unsigned NOT NULL default '0', 874 useragent varchar(200) NOT NULL default '', 875 lastvisit bigint(30) NOT NULL default '0', 876 PRIMARY KEY(sid) 877 ) ENGINE=MyISAM{$collation};"); 878 879 $db->write_query("CREATE TABLE ".TABLE_PREFIX."stats ( 880 dateline bigint(30) NOT NULL default '0', 881 numusers int unsigned NOT NULL default '0', 882 numthreads int unsigned NOT NULL default '0', 883 numposts int unsigned NOT NULL default '0', 884 PRIMARY KEY(dateline) 885 ) ENGINE=MyISAM{$collation};"); 886 887 $db->insert_query("spiders", array('name' => 'GoogleBot', 'useragent' => 'google')); 888 $db->insert_query("spiders", array('name' => 'Lycos', 'useragent' => 'lycos')); 889 $db->insert_query("spiders", array('name' => 'Ask Jeeves', 'useragent' => 'ask jeeves')); 890 $db->insert_query("spiders", array('name' => 'Hot Bot', 'useragent' => 'slurp@inktomi')); 891 $db->insert_query("spiders", array('name' => 'What You Seek', 'useragent' => 'whatuseek')); 892 $db->insert_query("spiders", array('name' => 'Archive.org', 'useragent' => 'is_archiver')); 893 $db->insert_query("spiders", array('name' => 'Altavista', 'useragent' => 'scooter')); 894 $db->insert_query("spiders", array('name' => 'Alexa', 'useragent' => 'ia_archiver')); 895 $db->insert_query("spiders", array('name' => 'MSN Search', 'useragent' => 'msnbot')); 896 $db->insert_query("spiders", array('name' => 'Yahoo!', 'useragent' => 'yahoo! slurp')); 897 898 // DST correction changes 899 $db->update_query("users", array('dst' => 1), "dst=1"); 900 $db->update_query("users", array('dst' => 0), "dst=0"); 901 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users CHANGE dst dst INT(1) NOT NULL default '0'"); 902 if($db->field_exists('dstcorrection', "users")) 903 { 904 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP dstcorrection;"); 905 } 906 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD dstcorrection INT(1) NOT NULL default '0' AFTER dst"); 907 908 $db->update_query("users", array('dstcorrection' => 2)); 909 910 $db->update_query("adminoptions", array('cpstyle' => '')); 911 912 if($db->field_exists('permsset', "adminoptions") && !$db->field_exists('permissions', "adminoptions")) 913 { 914 $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminoptions CHANGE permsset permissions TEXT NOT NULL "); 915 } 916 917 $adminoptions = file_get_contents(INSTALL_ROOT.'resources/adminoptions.xml'); 918 $parser = new XMLParser($adminoptions); 919 $parser->collapse_dups = 0; 920 $tree = $parser->get_tree(); 921 922 // Fetch default permissions list 923 $default_permissions = array(); 924 foreach($tree['adminoptions'][0]['user'] as $users) 925 { 926 $uid = $users['attributes']['uid']; 927 if($uid == -4) 928 { 929 foreach($users['permissions'][0]['module'] as $module) 930 { 931 foreach($module['permission'] as $permission) 932 { 933 $default_permissions[$module['attributes']['name']][$permission['attributes']['name']] = $permission['value']; 934 } 935 } 936 break; 937 } 938 } 939 940 $convert_permissions = array( 941 "caneditsettings" => array( 942 "module" => "config", 943 "permission" => "settings" 944 ), 945 "caneditann" => array( 946 "module" => "forum", 947 "permission" => "announcements", 948 ), 949 "caneditforums" => array( 950 "module" => "forum", 951 "permission" => "management", 952 ), 953 "canmodposts" => array( 954 "module" => "forum", 955 "permission" => "moderation_queue", 956 ), 957 "caneditsmilies" => array( 958 "module" => "config", 959 "permission" => "smilies", 960 ), 961 "caneditpicons" => array( 962 "module" => "config", 963 "permission" => "post_icons", 964 ), 965 "caneditthemes" => array( 966 "module" => "style", 967 "permission" => "themes", 968 ), 969 "canedittemps" => array( 970 "module" => "style", 971 "permission" => "templates", 972 ), 973 "caneditusers" => array( 974 "module" => "user", 975 "permission" => "view", 976 ), 977 "caneditpfields" => array( 978 "module" => "config", 979 "permission" => "profile_fields", 980 ), 981 "caneditmodactions" => array( 982 "module" => "config", 983 "permission" => "mod_tools", 984 ), 985 "caneditugroups" => array( 986 "module" => "user", 987 "permission" => "groups", 988 ), 989 "caneditaperms" => array( 990 "module" => "user", 991 "permission" => "admin_permissions", 992 ), 993 "caneditutitles" => array( 994 "module" => "user", 995 "permission" => "titles", 996 ), 997 "caneditattach" => array( 998 "module" => "forum", 999 "permission" => "attachments", 1000 ), 1001 "canedithelp" => array( 1002 "module" => "config", 1003 "permission" => "help_documents", 1004 ), 1005 "caneditlangs" => array( 1006 "module" => "config", 1007 "permission" => "languages", 1008 ), 1009 "canrunmaint" => array( 1010 "module" => "tools", 1011 "permission" => "recount_rebuild", 1012 ), 1013 "canrundbtools" => array( 1014 "module" => "tools", 1015 "permission" => "backupdb", 1016 ), 1017 ); 1018 1019 $new_permissions = $default_permissions; 1020 1021 $query = $db->simple_select("adminoptions"); 1022 while($adminoption = $db->fetch_array($query)) 1023 { 1024 foreach($adminoption as $field => $value) 1025 { 1026 if(strtolower(substr($field, 0, 3)) != "can") 1027 { 1028 continue; 1029 } 1030 1031 if(array_key_exists($field, $convert_permissions)) 1032 { 1033 // Note: old adminoptions table is still yes/no - do not change me 1034 if($value == "yes") 1035 { 1036 $value = 1; 1037 } 1038 else 1039 { 1040 $value = $default_permissions[$convert_permissions[$field]['module']][$convert_permissions[$field]['permission']]; 1041 } 1042 $new_permissions[$convert_permissions[$field]['module']][$convert_permissions[$field]['permission']] = $value; 1043 } 1044 } 1045 1046 $db->update_query("adminoptions", array('permissions' => serialize($new_permissions)), "uid = '{$adminoption['uid']}'"); 1047 1048 $new_permissions = $default_permissions; 1049 } 1050 1051 foreach($convert_permissions as $field => $value) 1052 { 1053 if($db->field_exists($field, "adminoptions")) 1054 { 1055 $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminoptions DROP {$field}"); 1056 } 1057 } 1058 1059 // Set default views 1060 if($db->field_exists('defaultviews', "adminoptions")) 1061 { 1062 $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminoptions DROP defaultviews"); 1063 } 1064 $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminoptions ADD defaultviews TEXT NOT NULL"); 1065 $db->update_query("adminoptions", array('defaultviews' => serialize(array('user' => 1)))); 1066 1067 require_once MYBB_ROOT."inc/functions_rebuild.php"; 1068 rebuild_stats(); 1069 1070 $contents = "Done</p>"; 1071 $contents .= "<p>Click next to continue with the upgrade process.</p>"; 1072 $output->print_contents($contents); 1073 1074 global $footer_extra; 1075 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 1076 1077 $output->print_footer("12_dbchanges5"); 1078 } 1079 1080 function upgrade12_dbchanges5() 1081 { 1082 global $db, $output, $mybb; 1083 1084 $output->print_header("Performing Queries"); 1085 1086 echo "<p>Performing necessary upgrade queries..</p>"; 1087 flush(); 1088 1089 $db->drop_table("templategroups"); 1090 $db->write_query("CREATE TABLE ".TABLE_PREFIX."templategroups ( 1091 gid int unsigned NOT NULL auto_increment, 1092 prefix varchar(50) NOT NULL default '', 1093 title varchar(100) NOT NULL default '', 1094 PRIMARY KEY (gid) 1095 ) ENGINE=MyISAM{$collation};"); 1096 1097 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('1','calendar','<lang:group_calendar>');"); 1098 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('2','editpost','<lang:group_editpost>');"); 1099 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('3','forumbit','<lang:group_forumbit>');"); 1100 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('4','forumjump','<lang:group_forumjump>');"); 1101 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('5','forumdisplay','<lang:group_forumdisplay>');"); 1102 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('6','index','<lang:group_index>');"); 1103 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('7','error','<lang:group_error>');"); 1104 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('8','memberlist','<lang:group_memberlist>');"); 1105 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('9','multipage','<lang:group_multipage>');"); 1106 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('10','private','<lang:group_private>');"); 1107 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('11','portal','<lang:group_portal>');"); 1108 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('12','postbit','<lang:group_postbit>');"); 1109 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('13','redirect','<lang:group_redirect>');"); 1110 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('14','showthread','<lang:group_showthread>');"); 1111 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('15','usercp','<lang:group_usercp>');"); 1112 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('16','online','<lang:group_online>');"); 1113 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('17','moderation','<lang:group_moderation>');"); 1114 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('18','nav','<lang:group_nav>');"); 1115 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('19','search','<lang:group_search>');"); 1116 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('20','showteam','<lang:group_showteam>');"); 1117 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('21','reputation','<lang:group_reputation>');"); 1118 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('22','newthread','<lang:group_newthread>');"); 1119 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('23','newreply','<lang:group_newreply>');"); 1120 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('24','member','<lang:group_member>');"); 1121 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('25','warnings','<lang:group_warning>');"); 1122 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('26','global','<lang:group_global>');"); 1123 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('27','header','<lang:group_header>');"); 1124 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('28','managegroup','<lang:group_managegroup>');"); 1125 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('29','misc','<lang:group_misc>');"); 1126 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('30','modcp','<lang:group_modcp>');"); 1127 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('31','php','<lang:group_php>');"); 1128 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('32','polls','<lang:group_polls>');"); 1129 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('33','post','<lang:group_post>');"); 1130 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('34','printthread','<lang:group_printthread>');"); 1131 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('35','report','<lang:group_report>');"); 1132 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('36','smilieinsert','<lang:group_smilieinsert>');"); 1133 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('37','stats','<lang:group_stats>');"); 1134 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('38','xmlhttp','<lang:group_xmlhttp>');"); 1135 $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('39','footer','<lang:group_footer>');"); 1136 1137 $query = $db->query("SHOW INDEX FROM ".TABLE_PREFIX."users"); 1138 while($ukey = $db->fetch_array($query)) 1139 { 1140 if($ukey['Key_name'] == "username") 1141 { 1142 $index = $ukey; 1143 break; 1144 } 1145 } 1146 if($index) 1147 { 1148 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP KEY username"); 1149 } 1150 $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD UNIQUE KEY username (username)"); 1151 1152 if($db->field_exists('statustime', "privatemessages")) 1153 { 1154 $db->write_query("ALTER TABLE ".TABLE_PREFIX."privatemessages DROP statustime;"); 1155 } 1156 $db->write_query("ALTER TABLE ".TABLE_PREFIX."privatemessages ADD statustime bigint(30) NOT NULL default '0' AFTER status"); 1157 1158 $collation = $db->build_create_table_collation(); 1159 1160 $db->drop_table("calendars"); 1161 $db->drop_table("calendarpermissions"); 1162 $db->drop_table("forumsread"); 1163 $db->drop_table("adminviews"); 1164 $db->drop_table("threadviews"); 1165 1166 $db->write_query("CREATE TABLE ".TABLE_PREFIX."threadviews ( 1167 tid int unsigned NOT NULL default '0' 1168 ) ENGINE=MyISAM{$collation};"); 1169 1170 $db->write_query("CREATE TABLE ".TABLE_PREFIX."calendars ( 1171 cid int unsigned NOT NULL auto_increment, 1172 name varchar(100) NOT NULL default '', 1173 disporder int unsigned NOT NULL default '0', 1174 startofweek int(1) NOT NULL default '0', 1175 showbirthdays int(1) NOT NULL default '0', 1176 eventlimit int(3) NOT NULL default '0', 1177 moderation int(1) NOT NULL default '0', 1178 allowhtml int(1) NOT NULL default '0', 1179 allowmycode int(1) NOT NULL default '0', 1180 allowimgcode int(1) NOT NULL default '0', 1181 allowsmilies int(1) NOT NULL default '0', 1182 PRIMARY KEY(cid) 1183 ) ENGINE=MyISAM{$collation};"); 1184 1185 $calendar_array = array( 1186 'name' => 'Default Calendar', 1187 'disporder' => 1, 1188 'startofweek' => 0, 1189 'showbirthdays' => 1, 1190 'eventlimit' => 4, 1191 'moderation' => 0, 1192 'allowhtml' => 0, 1193 'allowmycode' => 1, 1194 'allowimgcode' => 1, 1195 'allowsmilies' => 1 1196 ); 1197 $db->insert_query("calendars", $calendar_array); 1198 1199 $db->write_query("CREATE TABLE ".TABLE_PREFIX."calendarpermissions ( 1200 cid int unsigned NOT NULL default '0', 1201 gid int unsigned NOT NULL default '0', 1202 canviewcalendar int(1) NOT NULL default '0', 1203 canaddevents int(1) NOT NULL default '0', 1204 canbypasseventmod int(1) NOT NULL default '0', 1205 canmoderateevents int(1) NOT NULL default '0' 1206 ) ENGINE=MyISAM{$collation};"); 1207 1208 $db->write_query("CREATE TABLE ".TABLE_PREFIX."forumsread ( 1209 fid int unsigned NOT NULL default '0', 1210 uid int unsigned NOT NULL default '0', 1211 dateline int(10) NOT NULL default '0', 1212 KEY dateline (dateline), 1213 UNIQUE KEY fid (fid,uid) 1214 ) ENGINE=MyISAM{$collation};"); 1215 1216 if($db->field_exists('dateuploaded', "attachments")) 1217 { 1218 $db->write_query("ALTER TABLE ".TABLE_PREFIX."attachments DROP dateuploaded;"); 1219 } 1220 $db->write_query("ALTER TABLE ".TABLE_PREFIX."attachments ADD dateuploaded bigint(30) NOT NULL default '0' AFTER downloads"); 1221 1222 $db->write_query("CREATE TABLE ".TABLE_PREFIX."adminviews ( 1223 vid int unsigned NOT NULL auto_increment, 1224 uid int unsigned NOT NULL default '0', 1225 title varchar(100) NOT NULL default '', 1226 type varchar(6) NOT NULL default '', 1227 visibility int(1) NOT NULL default '0', 1228 `fields` text NOT NULL, 1229 conditions text NOT NULL, 1230 sortby varchar(20) NOT NULL default '', 1231 sortorder varchar(4) NOT NULL default '', 1232 perpage int(4) NOT NULL default '0', 1233 view_type varchar(6) NOT NULL default '', 1234 PRIMARY KEY(vid) 1235 ) ENGINE=MyISAM{$collation};"); 1236 1237 $views = file_get_contents(INSTALL_ROOT.'resources/adminviews.xml'); 1238 $parser = new XMLParser($views); 1239 $parser->collapse_dups = 0; 1240 $tree = $parser->get_tree(); 1241 1242 // Insert admin views 1243 foreach($tree['adminviews'][0]['view'] as $view) 1244 { 1245 $fields = array(); 1246 foreach($view['fields'][0]['field'] as $field) 1247 { 1248 $fields[] = $field['attributes']['name']; 1249 } 1250 $conditions = array(); 1251 if($view['conditions'][0]['condition']) 1252 { 1253 foreach($view['conditions'][0]['condition'] as $condition) 1254 { 1255 if(!$condition['value']) continue; 1256 if($condition['attributes']['is_serialized'] == 1) 1257 { 1258 $condition['value'] = unserialize($condition['value']); 1259 } 1260 $conditions[$condition['attributes']['name']] = $condition['value']; 1261 } 1262 } 1263 $new_view = array( 1264 "uid" => 0, 1265 "type" => $db->escape_string($view['attributes']['type']), 1266 "visibility" => intval($view['attributes']['visibility']), 1267 "title" => $db->escape_string($view['title'][0]['value']), 1268 "fields" => $db->escape_string(serialize($fields)), 1269 "conditions" => $db->escape_string(serialize($conditions)), 1270 "sortby" => $db->escape_string($view['sortby'][0]['value']), 1271 "sortorder" => $db->escape_string($view['sortorder'][0]['value']), 1272 "perpage" => intval($view['perpage'][0]['value']), 1273 "view_type" => $db->escape_string($view['view_type'][0]['value']) 1274 ); 1275 $db->insert_query("adminviews", $new_view); 1276 $view_count++; 1277 } 1278 1279 $avatardimensions = str_replace('x', '|', my_strtolower($mybb->settings['postmaxavatarsize'])); 1280 1281 $db->simple_select("users", "uid", "avatar != '' AND avatardimensions = ''"); 1282 while($user = $db->fetch_array($query)) 1283 { 1284 $db->update_query("users", array('avatardimensions' => $avatardimensions), "uid='{$user['uid']}'", 1); 1285 } 1286 1287 $contents = "Done</p>"; 1288 $contents .= "<p>Click next to continue with the upgrade process.</p>"; 1289 $output->print_contents($contents); 1290 1291 global $footer_extra; 1292 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 1293 1294 $output->print_footer("12_redoconfig"); 1295 } 1296 1297 function upgrade12_redoconfig() 1298 { 1299 global $db, $output, $orig_config, $mybb; 1300 1301 $config = $orig_config; 1302 1303 $output->print_header("Rewriting config.php"); 1304 1305 if(!is_array($config['database'])) 1306 { 1307 // Backup our old Config file 1308 @copy(MYBB_ROOT."inc/config.php", MYBB_ROOT."inc/config.backup.php"); 1309 1310 $fh = @fopen(MYBB_ROOT."inc/config.php", "w"); 1311 if(!$fh) 1312 { 1313 echo "<p><span style=\"color: red; font-weight: bold;\">Unable to open inc/config.php</span><br />Before the upgrade process can continue, you need to changes the permissions of inc/config.php so it is writable.</p>"; 1314 $output->print_footer("12_redoconfig"); 1315 exit; 1316 } 1317 1318 if(!$config['memcache_host']) 1319 { 1320 $config['memcache_host'] = "localhost"; 1321 } 1322 1323 if(!$config['memcache_port']) 1324 { 1325 $config['memcache_port'] = 11211; 1326 } 1327 1328 $comment = ""; 1329 1330 if(!$db->db_encoding || !$config['db_encoding']) 1331 { 1332 $comment = " // "; 1333 } 1334 1335 if(!$config['db_encoding']) 1336 { 1337 $config['db_encoding'] = "utf8"; 1338 } 1339 1340 1341 $configdata = "<?php 1342 /** 1343 * Database configuration 1344 * 1345 * Please see the MyBB Docs for advanced 1346 * database configuration for larger installations 1347 * http://docs.mybb.com/ 1348 */ 1349 1350 \$config['database']['type'] = '{$config['dbtype']}'; 1351 \$config['database']['database'] = '{$config['database']}'; 1352 \$config['database']['table_prefix'] = '{$config['table_prefix']}'; 1353 1354 \$config['database']['hostname'] = '{$config['hostname']}'; 1355 \$config['database']['username'] = '{$config['username']}'; 1356 \$config['database']['password'] = '{$config['password']}'; 1357 1358 /** 1359 * Admin CP directory 1360 * For security reasons, it is recommended you 1361 * rename your Admin CP directory. You then need 1362 * to adjust the value below to point to the 1363 * new directory. 1364 */ 1365 1366 \$config['admin_dir'] = '{$config['admin_dir']}'; 1367 1368 /** 1369 * Hide all Admin CP links 1370 * If you wish to hide all Admin CP links 1371 * on the front end of the board after 1372 * renaming your Admin CP directory, set this 1373 * to 1. 1374 */ 1375 1376 \$config['hide_admin_links'] = {$config['hide_admin_links']}; 1377 1378 /** 1379 * Data-cache configuration 1380 * The data cache is a temporary cache 1381 * of the most commonly accessed data in MyBB. 1382 * By default, the database is used to store this data. 1383 * 1384 * If you wish to use the file system (cache/ directory) 1385 * you can change the value below to 'files', 'memcache' or 'eaccelerator' from 'db'. 1386 */ 1387 1388 \$config['cache_store'] = '{$config['cache_store']}'; 1389 1390 /** 1391 * Memcache configuration 1392 * If you are using memcache as your data-cache, 1393 * you need to configure the hostname and port 1394 * of your memcache server below. 1395 * 1396 * If not using memcache, ignore this section. 1397 */ 1398 1399 \$config['memcache_host'] = '{$config['memcache_host']}'; 1400 \$config['memcache_port'] = {$config['memcache_port']}; 1401 1402 /** 1403 * Super Administrators 1404 * A comma separated list of user IDs who cannot 1405 * be edited, deleted or banned in the Admin CP. 1406 * The administrator permissions for these users 1407 * cannot be altered either. 1408 */ 1409 1410 \$config['super_admins'] = '{$config['super_admins']}'; 1411 1412 /** 1413 * Database Encoding 1414 * If you wish to set an encoding for MyBB uncomment 1415 * the line below (if it isn't already) and change 1416 * the current value to the mysql charset: 1417 * http://dev.mysql.com/doc/refman/5.1/en/charset-mysql.html 1418 */ 1419 1420 {$comment}\$config['database']['encoding'] = '{$config['db_encoding']}'; 1421 1422 /** 1423 * Automatic Log Pruning 1424 * The MyBB task system can automatically prune 1425 * various log files created by MyBB. 1426 * To enable this functionality for the logs below, set the 1427 * the number of days before each log should be pruned. 1428 * If you set the value to 0, the logs will not be pruned. 1429 */ 1430 1431 \$config['log_pruning'] = array( 1432 'admin_logs' => 365, // Administrator logs 1433 'mod_logs' => 0, // Moderator logs 1434 'task_logs' => 30, // Scheduled task logs 1435 'mail_logs' => 180, // Mail error logs 1436 'user_mail_logs' => 180, // User mail logs 1437 'promotion_logs' => 180 // Promotion logs 1438 ); 1439 1440 ?".">"; 1441 fwrite($fh, $configdata); 1442 fclose($fh); 1443 } 1444 echo "<p>The configuration file has successfully been rewritten.</p>"; 1445 echo "<p>Click next to continue with the upgrade process.</p>"; 1446 1447 global $footer_extra; 1448 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 1449 1450 $output->print_footer("12_dbchanges6"); 1451 } 1452 1453 function upgrade12_dbchanges6() 1454 { 1455 global $db, $output; 1456 1457 $output->print_header("Post IP Conversion"); 1458 1459 if(!$_POST['ipspage']) 1460 { 1461 $ipp = 5000; 1462 } 1463 else 1464 { 1465 $ipp = $_POST['ipspage']; 1466 } 1467 1468 if($_POST['ipstart']) 1469 { 1470 $startat = $_POST['ipstart']; 1471 $upper = $startat+$ipp; 1472 $lower = $startat; 1473 } 1474 else 1475 { 1476 $startat = 0; 1477 $upper = $ipp; 1478 $lower = 1; 1479 } 1480 1481 $query = $db->simple_select("posts", "COUNT(pid) AS ipcount"); 1482 $cnt = $db->fetch_array($query); 1483 1484 if($upper > $cnt['ipcount']) 1485 { 1486 $upper = $cnt['ipcount']; 1487 } 1488 1489 echo "<p>Converting ip {$lower} to {$upper} ({$cnt['ipcount']} Total)</p>"; 1490 flush(); 1491 1492 $ipaddress = false; 1493 1494 $query = $db->simple_select("posts", "ipaddress, longipaddress, pid", "", array('limit_start' => $lower, 'limit' => $ipp)); 1495 while($post = $db->fetch_array($query)) 1496 { 1497 // Have we already converted this ip? 1498 if(!$post['longipaddress']) 1499 { 1500 $db->update_query("posts", array('longipaddress' => my_ip2long($post['ipaddress'])), "pid = '{$post['pid']}'"); 1501 } 1502 $ipaddress = true; 1503 } 1504 1505 $remaining = $upper-$cnt['ipcount']; 1506 if($remaining && $ipaddress) 1507 { 1508 $nextact = "12_dbchanges6"; 1509 $startat = $startat+$ipp; 1510 $contents = "<p><input type=\"hidden\" name=\"ipspage\" value=\"$ipp\" /><input type=\"hidden\" name=\"ipstart\" value=\"$startat\" />Done. Click Next to move on to the next set of post ips.</p>"; 1511 } 1512 else 1513 { 1514 $nextact = "12_dbchanges7"; 1515 $contents = "<p>Done</p><p>All post ips have been converted to the new ip format. Click next to continue.</p>"; 1516 } 1517 $output->print_contents($contents); 1518 1519 global $footer_extra; 1520 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 1521 1522 $output->print_footer($nextact); 1523 } 1524 1525 function upgrade12_dbchanges7() 1526 { 1527 global $db, $output; 1528 1529 $output->print_header("User IP Conversion"); 1530 1531 if(!$_POST['ipspage']) 1532 { 1533 $ipp = 5000; 1534 } 1535 else 1536 { 1537 $ipp = $_POST['ipspage']; 1538 } 1539 1540 if($_POST['ipstart']) 1541 { 1542 $startat = $_POST['ipstart']; 1543 $upper = $startat+$ipp; 1544 $lower = $startat; 1545 } 1546 else 1547 { 1548 $startat = 0; 1549 $upper = $ipp; 1550 $lower = 1; 1551 } 1552 1553 $query = $db->simple_select("users", "COUNT(uid) AS ipcount"); 1554 $cnt = $db->fetch_array($query); 1555 1556 if($upper > $cnt['ipcount']) 1557 { 1558 $upper = $cnt['ipcount']; 1559 } 1560 1561 $contents .= "<p>Converting ip {$lower} to {$upper} ({$cnt['ipcount']} Total)</p>"; 1562 1563 $ipaddress = false; 1564 $update_array = array(); 1565 1566 $query = $db->simple_select("users", "regip, lastip, longlastip, longregip, uid", "", array('limit_start' => $lower, 'limit' => $ipp)); 1567 while($user = $db->fetch_array($query)) 1568 { 1569 // Have we already converted this ip? 1570 if(!$user['longregip']) 1571 { 1572 $update_array['longregip'] = intval(my_ip2long($user['regip'])); 1573 } 1574 1575 if(!$user['longlastip']) 1576 { 1577 $update_array['longlastip'] = intval(my_ip2long($user['lastip'])); 1578 } 1579 1580 if(!empty($update_array)) 1581 { 1582 $db->update_query("users", $update_array, "uid = '{$user['uid']}'"); 1583 } 1584 1585 $update_array = array(); 1586 $ipaddress = true; 1587 } 1588 1589 $remaining = $upper-$cnt['ipcount']; 1590 if($remaining && $ipaddress) 1591 { 1592 $nextact = "12_dbchanges7"; 1593 $startat = $startat+$ipp; 1594 $contents .= "<p><input type=\"hidden\" name=\"ipspage\" value=\"$ipp\" /><input type=\"hidden\" name=\"ipstart\" value=\"$startat\" />Done. Click Next to move on to the next set of user ips.</p>"; 1595 } 1596 else 1597 { 1598 $nextact = "12_dbchanges8"; 1599 $contents .= "<p>Done</p><p>All user ips have been converted to the new ip format. Click next to continue.</p>"; 1600 } 1601 $output->print_contents($contents); 1602 1603 global $footer_extra; 1604 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 1605 1606 $output->print_footer($nextact); 1607 } 1608 1609 function upgrade12_dbchanges8() 1610 { 1611 global $db, $output; 1612 1613 $output->print_header("Event Conversion"); 1614 1615 if(!$_POST['eventspage']) 1616 { 1617 $epp = 50; 1618 } 1619 else 1620 { 1621 $epp = $_POST['eventspage']; 1622 } 1623 1624 if($_POST['eventstart']) 1625 { 1626 $startat = $_POST['eventstart']; 1627 $upper = $startat+$epp; 1628 $lower = $startat; 1629 } 1630 else 1631 { 1632 $startat = 0; 1633 $upper = $epp; 1634 $lower = 1; 1635 } 1636 1637 $query = $db->simple_select("events", "COUNT(eid) AS eventcount"); 1638 $cnt = $db->fetch_array($query); 1639 1640 if($upper > $cnt['eventcount']) 1641 { 1642 $upper = $cnt['eventcount']; 1643 } 1644 1645 $contents .= "<p>Converting events {$lower} to {$upper} ({$cnt['eventcount']} Total)</p>"; 1646 1647 // Just started - add fields 1648 if(!$db->field_exists("donecon", "events")) 1649 { 1650 // Add temporary column 1651 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events ADD donecon smallint(1) NOT NULL;"); 1652 1653 if($db->field_exists('cid', "events")) 1654 { 1655 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events DROP cid;"); 1656 } 1657 1658 if($db->field_exists('visible', "events")) 1659 { 1660 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events DROP visible;"); 1661 } 1662 1663 if($db->field_exists('dateline', "events")) 1664 { 1665 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events DROP dateline;"); 1666 } 1667 1668 if($db->field_exists('starttime', "events")) 1669 { 1670 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events DROP starttime;"); 1671 } 1672 1673 if($db->field_exists('endtime', "events")) 1674 { 1675 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events DROP endtime;"); 1676 } 1677 1678 if($db->field_exists('timezone', "events")) 1679 { 1680 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events DROP timezone;"); 1681 } 1682 1683 if($db->field_exists('ignoretimezone', "events")) 1684 { 1685 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events DROP ignoretimezone;"); 1686 } 1687 1688 if($db->field_exists('usingtime', "events")) 1689 { 1690 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events DROP usingtime;"); 1691 } 1692 1693 if($db->field_exists('repeats', "events")) 1694 { 1695 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events DROP repeats;"); 1696 } 1697 1698 // Got structural changes? 1699 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events ADD cid int unsigned NOT NULL default '0' AFTER eid"); 1700 1701 if($db->field_exists('author', "events") && !$db->field_exists('uid', "events")) 1702 { 1703 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events CHANGE author uid int unsigned NOT NULL default '0'"); 1704 } 1705 1706 if($db->field_exists('subject', "events") && !$db->field_exists('name', "events")) 1707 { 1708 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events CHANGE subject name varchar(120) NOT NULL default ''"); 1709 } 1710 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events ADD visible int(1) NOT NULL default '0' AFTER description"); 1711 $db->update_query("events", array('private' => 1), "private='yes' OR private='1'"); 1712 $db->update_query("events", array('private' => 0), "private='no' OR private='0'"); 1713 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events CHANGE private private int(1) NOT NULL default '0'"); 1714 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events ADD dateline int(10) unsigned NOT NULL default '0' AFTER private"); 1715 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events ADD starttime int(10) unsigned NOT NULL default '0' AFTER dateline"); 1716 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events ADD endtime int(10) unsigned NOT NULL default '0' AFTER starttime"); 1717 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events ADD timezone int(3) NOT NULL default '0' AFTER endtime"); 1718 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events ADD ignoretimezone int(1) NOT NULL default '0' AFTER timezone"); 1719 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events ADD usingtime int(1) NOT NULL default '0' AFTER ignoretimezone"); 1720 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events ADD repeats text NOT NULL AFTER usingtime"); 1721 } 1722 1723 if($db->field_exists('date', "events")) 1724 { 1725 $query = $db->simple_select("events", "*", "donecon!=1", array("order_by" => "eid", "limit" => $epp)); 1726 while($event = $db->fetch_array($query)) 1727 { 1728 $e_date = explode("-", $event['date']); 1729 if(!$e_date[2]) $e_date[2] = 2005; 1730 $starttime = gmmktime(0, 0, 0, $e_date[1], $e_date[0], $e_date[2]); 1731 $updated_event = array( 1732 "cid" => 1, 1733 "visible" => 1, 1734 "donecon" => 1, 1735 "starttime" => $starttime, 1736 "dateline" => $starttime 1737 ); 1738 $db->update_query("events", $updated_event, "eid='{$event['eid']}'", 1); 1739 } 1740 1741 $date = true; 1742 } 1743 else 1744 { 1745 $date = false; 1746 } 1747 1748 $query = $db->simple_select("events", "COUNT(eid) AS remaining", "donecon!=1"); 1749 $remaining = $db->fetch_field($query, "remaining"); 1750 if($remaining && $date) 1751 { 1752 $nextact = "12_dbchanges8"; 1753 $startat = $startat+$epp; 1754 $contents .= "<p><input type=\"hidden\" name=\"eventspage\" value=\"$epp\" /><input type=\"hidden\" name=\"eventstart\" value=\"$startat\" />Done. Click Next to move on to the next set of events.</p>"; 1755 } 1756 else 1757 { 1758 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events DROP donecon"); 1759 if($db->field_exists('date', "events")) 1760 { 1761 $db->write_query("ALTER TABLE ".TABLE_PREFIX."events DROP date"); 1762 } 1763 $nextact = "12_redothemes"; 1764 $contents .= "<p>Done</p><p>All events have been converted to the new calendar system. Click next to continue.</p>"; 1765 } 1766 $output->print_contents($contents); 1767 1768 global $footer_extra; 1769 $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 1770 1771 $output->print_footer($nextact); 1772 } 1773 1774 function upgrade12_redothemes() 1775 { 1776 global $db, $output, $config, $mybb; 1777 1778 $output->print_header("Converting themes"); 1779 1780 if(!@is_dir(MYBB_ROOT.'cache/')) 1781 { 1782 @mkdir(MYBB_ROOT.'cache/', 077); 1783 1784 // Add in empty index.html! 1785 $fp = @fopen(MYBB_ROOT."cache/index.html", "w"); 1786 @fwrite($fp, ""); 1787 @fclose($fp); 1788 } 1789 $cachewritable = @fopen(MYBB_ROOT.'cache/test.write', 'w'); 1790 if(!$cachewritable) 1791 { 1792 $not_writable = true; 1793 @fclose($cachewritable); 1794 } 1795 else 1796 { 1797 @fclose($cachewritable); 1798 @my_chmod(MYBB_ROOT.'cache', '0777'); 1799 @my_chmod(MYBB_ROOT.'cache/test.write', '0777'); 1800 @unlink(MYBB_ROOT.'cache/test.write'); 1801 } 1802 1803 if($not_writable) 1804 { 1805 echo "<p><span style=\"color: red; font-weight: bold;\">Unable to write to the cache/ directory.</span><br />Before the upgrade process can continue you need to make sure this directory exists and is writable (chmod 777)</p>"; 1806 $output->print_footer("12_redothemes"); 1807 exit; 1808 } 1809 1810 $not_writable = false; 1811 if(!@is_dir(MYBB_ROOT.'cache/themes/')) 1812 { 1813 @mkdir(MYBB_ROOT.'cache/themes/', 077); 1814 1815 // Add in empty index.html! 1816 $fp = @fopen(MYBB_ROOT."cache/themes/index.html", "w"); 1817 @fwrite($fp, ""); 1818 @fclose($fp); 1819 } 1820 $themewritable = @fopen(MYBB_ROOT.'cache/themes/test.write', 'w'); 1821 if(!$themewritable) 1822 { 1823 $not_writable = true; 1824 @fclose($themewritable); 1825 } 1826 else 1827 { 1828 @fclose($themewritable); 1829 @my_chmod(MYBB_ROOT.'cache/themes', '0777'); 1830 @my_chmod(MYBB_ROOT.'cache/themes/test.write', '0777'); 1831 @unlink(MYBB_ROOT.'cache/themes/test.write'); 1832 } 1833 1834 if($not_writable) 1835 { 1836 echo "<p><span style=\"color: red; font-weight: bold;\">Unable to write to the cache/themes/ directory.</span><br />Before the upgrade process can continue you need to make sure this directory exists and is writable (chmod 777)</p>"; 1837 $output->print_footer("12_redothemes"); 1838 exit; 1839 } 1840 1841 if($db->field_exists('themebits', "themes") && !$db->field_exists('properties', "themes")) 1842 { 1843 $db->write_query("ALTER TABLE ".TABLE_PREFIX."themes CHANGE themebits properties text NOT NULL"); 1844 } 1845 1846 if($db->field_exists('cssbits', "themes")) 1847 { 1848 $db->write_query("ALTER TABLE ".TABLE_PREFIX."themes DROP cssbits"); 1849 } 1850 1851 if($db->field_exists('csscached', "themes")) 1852 { 1853 $db->write_query("ALTER TABLE ".TABLE_PREFIX."themes DROP csscached"); 1854 } 1855 1856 if($db->field_exists('stylesheets', "themes")) 1857 { 1858 $db->write_query("ALTER TABLE ".TABLE_PREFIX."themes DROP stylesheets"); 1859 } 1860 $db->write_query("ALTER TABLE ".TABLE_PREFIX."themes ADD stylesheets text NOT NULL AFTER properties"); 1861 1862 if($db->table_exists("themestylesheets")) 1863 { 1864 $db->drop_table("themestylesheets"); 1865 } 1866 1867 $db->write_query("CREATE TABLE ".TABLE_PREFIX."themestylesheets( 1868 sid int unsigned NOT NULL auto_increment, 1869 name varchar(30) NOT NULL default '', 1870 tid int unsigned NOT NULL default '0', 1871 attachedto text NOT NULL, 1872 stylesheet text NOT NULL, 1873 cachefile varchar(100) NOT NULL default '', 1874 lastmodified bigint(30) NOT NULL default '0', 1875 PRIMARY KEY(sid) 1876 ) ENGINE=MyISAM{$collation};"); 1877 1878 // Define our default stylesheets - MyBB 1.4 contains additional stylesheets that our converted themes will also need 1879 $contents = @file_get_contents(INSTALL_ROOT.'resources/mybb_theme.xml'); 1880 if(file_exists(MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php")) 1881 { 1882 require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php"; 1883 } 1884 else if(file_exists(MYBB_ROOT."admin/inc/functions_themes.php")) 1885 { 1886 require_once MYBB_ROOT."admin/inc/functions_themes.php"; 1887 } 1888 else 1889 { 1890 $output->print_error("Please make sure your admin directory is uploaded correctly."); 1891 } 1892 1893 // Import master theme 1894 if(import_theme_xml($contents, array("tid" => 1, "no_templates" => 1, "version_compat" => 1)) === -1) 1895 { 1896 $output->print_error("Please make sure your install/resources/mybb_theme.xml file is uploaded correctly."); 1897 } 1898 1899 // Fetch out default stylesheets from master 1900 $query = $db->simple_select("themes", "*", "tid=1"); 1901 $master_theme = $db->fetch_array($query); 1902 1903 $master_stylesheets = unserialize($master_theme['stylesheets']); 1904 1905 if(is_array($master_stylesheets)) 1906 { 1907 // Note: 1.4 only ships with one global|global stylesheet 1908 foreach($master_stylesheets as $location => $sheets) 1909 { 1910 foreach($sheets as $action => $sheets) 1911 { 1912 foreach($sheets as $stylesheet) 1913 { 1914 if($location == "global" && $action == "global") 1915 { 1916 continue; // Skip global 1917 } 1918 1919 $default_stylesheets[$location][$action][] = $stylesheet; 1920 $default_stylesheets['inherited']["{$location}_{$action}"][$stylesheet] = 1; // This stylesheet is inherited from the master 1921 } 1922 } 1923 } 1924 } 1925 1926 $query = $db->simple_select("themes"); 1927 while($theme = $db->fetch_array($query)) 1928 { 1929 if(!$theme['css']) 1930 { 1931 continue; 1932 } 1933 1934 $theme['css'] .= "\n\n".$theme['extracss']; 1935 1936 $theme['css'] = upgrade_css_120_to_140($theme['css']); 1937 1938 1939 // Create stylesheets 1940 $cache_file = cache_stylesheet($theme['tid'], "global.css", $theme['css']); 1941 1942 $new_stylesheet = array( 1943 "tid" => $theme['tid'], 1944 "name" => "global.css", 1945 "attachedto" => "", 1946 "stylesheet" => $db->escape_string($theme['css']), 1947 "cachefile" => "global.css", 1948 "lastmodified" => TIME_NOW 1949 ); 1950 $sid = $db->insert_query("themestylesheets", $new_stylesheet); 1951 $css_url = "css.php?stylesheet={$sid}"; 1952 if($cache_file) 1953 { 1954 $css_url = $cache_file; 1955 } 1956 1957 // Now we go and update the stylesheets column for this theme 1958 $stylesheets = $default_stylesheets; 1959 1960 // Add in our local for this theme 1961 $stylesheets['global']['global'][] = $css_url; 1962 1963 // Update the theme 1964 $db->update_query("themes", array("stylesheets" => $db->escape_string(serialize($stylesheets))), "tid='{$theme['tid']}'"); 1965 } 1966 1967 if($db->field_exists('css', "themes")) 1968 { 1969 $db->write_query("ALTER TABLE ".TABLE_PREFIX."themes DROP css"); 1970 } 1971 1972 if($db->field_exists('extracss', "themes")) 1973 { 1974 $db->write_query("ALTER TABLE ".TABLE_PREFIX."themes DROP extracss"); 1975 } 1976 1977 // We need to replace this for our themes css to show up 1978 // <link rel="stylesheet" type="text/css" href="{$theme['css_url']}" /> must be present in the old template (it usually is) 1979 $query = $db->simple_select("templates", "tid,template", "title='headerinclude'"); 1980 while($template = $db->fetch_array($query)) 1981 { 1982 $template['template'] = str_replace('<link rel="stylesheet" type="text/css" href="{$theme[\'css_url\']}" />', '{$stylesheets}', $template['template']); 1983 1984 $db->update_query("templates", array('template' => $db->escape_string($template['template'])), "tid='{$template['tid']}'"); 1985 } 1986 1987 echo "<p>Your themes have successfully been converted to the new theme system.</p>"; 1988 echo "<p>Click next to continue with the upgrade process.</p>"; 1989 1990 global $footer_extra; 1991 //$footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>"; 1992 1993 $output->print_footer("12_done"); 1994 } 1995 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |