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