[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/install/resources/ -> upgrade5.php (source)

   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.0.x / 1.1.x
  14   */
  15  
  16  
  17  $upgrade_detail = array(
  18      "revert_all_templates" => 1,
  19      "revert_all_themes" => 1,
  20      "revert_all_settings" => 2,
  21      "requires_deactivated_plugins" => 1,
  22  );
  23  
  24  @set_time_limit(0);
  25  
  26  function upgrade5_dbchanges()
  27  {
  28      global $db, $output, $mybb;
  29  
  30      $output->print_header("Performing Queries");
  31  
  32      echo "<p>Performing necessary upgrade queries..</p>";
  33      
  34      $db->write_query("ALTER TABLE ".TABLE_PREFIX."users CHANGE avatartype avatartype varchar(10) NOT NULL;");
  35      if($db->field_exists('totalpms', "users"))
  36      {
  37          $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP totalpms;");
  38      }
  39      $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD totalpms int(10) NOT NULL default '0' AFTER showcodebuttons;");
  40      
  41      
  42      if($db->field_exists('newpms', "users"))
  43      {
  44          $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP newpms;");
  45      }
  46      $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD newpms int(10) NOT NULL default '0' AFTER totalpms;");
  47      
  48      
  49      if($db->field_exists('unreadpms', "users"))
  50      {
  51          $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP unreadpms;");
  52      }
  53      $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD unreadpms int(10) NOT NULL default '0' AFTER newpms;");
  54      
  55      
  56      if($db->field_exists('showredirect', "users"))
  57      {
  58          $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP showredirect;");
  59      }
  60      $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD showredirect char(3) NOT NULL default '' AFTER showquickreply;");
  61      
  62      
  63      if($db->field_exists('avatardimensions', "users"))
  64      {
  65          $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP avatardimensions;");
  66      }
  67      $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD avatardimensions varchar(10) NOT NULL default '' AFTER avatar;");
  68      
  69      
  70      if($db->field_exists('unapprovedposts', "threads"))
  71      {
  72          $db->write_query("ALTER TABLE ".TABLE_PREFIX."threads DROP unapprovedposts;");
  73      }
  74      $db->write_query("ALTER TABLE ".TABLE_PREFIX."threads ADD unapprovedposts INT(10) unsigned NOT NULL default '0' AFTER visible;");
  75      
  76      
  77      if($db->field_exists('unapprovedthreads', "forums"))
  78      {
  79          $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums DROP unapprovedthreads;");
  80      }
  81      $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums ADD unapprovedthreads INT(10) unsigned NOT NULL default '0' AFTER rules;");
  82      
  83      
  84      if($db->field_exists('unapprovedposts', "forums"))
  85      {
  86          $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums DROP unapprovedposts;");
  87      }
  88      $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums ADD unapprovedposts INT(10) unsigned NOT NULL default '0' AFTER rules;");
  89      
  90      
  91      if($db->field_exists('defaultdatecut', "forums"))
  92      {
  93          $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums DROP defaultdatecut;");
  94      }
  95      $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums ADD defaultdatecut smallint(4) unsigned NOT NULL default '0' AFTER unapprovedposts;");
  96      
  97      
  98      if($db->field_exists('defaultsortby', "forums"))
  99      {
 100          $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums DROP defaultsortby;");
 101      }
 102      $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums ADD defaultsortby varchar(10) NOT NULL default '' AFTER defaultdatecut;");
 103      
 104      
 105      if($db->field_exists('defaultsortorder', "forums"))
 106      {
 107          $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums DROP defaultsortorder;");
 108      }
 109      $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums ADD defaultsortorder varchar(4) NOT NULL default '' AFTER defaultsortby;");
 110      
 111  
 112      if($db->field_exists('lastposteruid', "forums"))
 113      {
 114          $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums DROP lastposteruid;");
 115      }
 116      $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums ADD lastposteruid int(10) unsigned NOT NULL default '0' AFTER lastposter;");
 117      
 118      
 119      if($db->field_exists('lastpostsubject', "forums"))
 120      {
 121          $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums DROP lastpostsubject;");
 122      }
 123      $db->write_query("ALTER TABLE ".TABLE_PREFIX."forums ADD lastpostsubject varchar(120) NOT NULL default '' AFTER lastposttid");
 124      
 125      
 126      if($db->field_exists('lastposteruid', "threads"))
 127      {
 128          $db->write_query("ALTER TABLE ".TABLE_PREFIX."threads DROP lastposteruid;");
 129      }
 130      $db->write_query("ALTER TABLE ".TABLE_PREFIX."threads ADD lastposteruid int unsigned NOT NULL default '0' AFTER lastposter");
 131      
 132      
 133      if($db->field_exists('canmanagemembers', "groupleaders"))
 134      {
 135          $db->write_query("ALTER TABLE ".TABLE_PREFIX."groupleaders DROP canmanagemembers;");
 136      }
 137      $db->write_query("ALTER TABLE ".TABLE_PREFIX."groupleaders ADD canmanagemembers char(3) NOT NULL default '' AFTER uid;");
 138      
 139      
 140      if($db->field_exists('canmanagerequests', "groupleaders"))
 141      {
 142          $db->write_query("ALTER TABLE ".TABLE_PREFIX."groupleaders DROP canmanagerequests;");
 143      }
 144      $db->write_query("ALTER TABLE ".TABLE_PREFIX."groupleaders ADD canmanagerequests char(3) NOT NULL default '' AFTER canmanagemembers;");
 145      
 146      
 147      if($db->field_exists('caneditlangs', "adminoptions"))
 148      {
 149          $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminoptions DROP caneditlangs;");
 150      }
 151      $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminoptions ADD caneditlangs char(3) NOT NULL default '' AFTER canedithelp;");
 152      
 153      
 154      if($db->field_exists('canrundbtools', "adminoptions"))
 155      {
 156          $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminoptions DROP canrundbtools;");
 157      }
 158      $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminoptions ADD canrundbtools char(3) NOT NULL default ''");
 159      
 160      
 161      if($db->field_exists('allowedgroups', "themes"))
 162      {
 163          $db->write_query("ALTER TABLE ".TABLE_PREFIX."themes DROP allowedgroups;");
 164      }
 165      $db->write_query("ALTER TABLE ".TABLE_PREFIX."themes ADD allowedgroups text NOT NULL AFTER extracss;");
 166      
 167      
 168      if($db->field_exists('canmovetononmodforum', "moderators"))
 169      {
 170          $db->write_query("ALTER TABLE ".TABLE_PREFIX."moderators DROP canmovetononmodforum;");
 171      }
 172      $db->write_query("ALTER TABLE ".TABLE_PREFIX."moderators ADD canmovetononmodforum char(3) NOT NULL default '' AFTER canmanagethreads;");
 173      
 174      
 175      if($db->field_exists('csscached', "themes"))
 176      {
 177          $db->write_query("ALTER TABLE ".TABLE_PREFIX."themes DROP csscached;");
 178      }
 179      $db->write_query("ALTER TABLE ".TABLE_PREFIX."themes ADD csscached bigint(30) NOT NULL default '0'");
 180      
 181      
 182      $db->write_query("UPDATE ".TABLE_PREFIX."adminoptions SET caneditlangs='yes' WHERE canrunmaint='yes'");
 183      $db->write_query("UPDATE ".TABLE_PREFIX."adminoptions SET caneditlangs='no' WHERE canrunmaint='no'");
 184      $db->write_query("UPDATE ".TABLE_PREFIX."adminoptions SET canrundbtools='yes' WHERE canrunmaint='yes'");
 185      $db->write_query("UPDATE ".TABLE_PREFIX."adminoptions SET canrundbtools='no' WHERE canrunmaint='no'");
 186      $db->write_query("UPDATE ".TABLE_PREFIX."settings SET optionscode='select\r\ninstant=Instant Activation\r\nverify=Send Email Verification\r\nrandompass=Send Random Password\r\nadmin=Administrator Activation' WHERE name = 'regtype'");
 187      $db->write_query("UPDATE ".TABLE_PREFIX."users SET totalpms='-1', newpms='-1', unreadpms='-1'");
 188      $db->write_query("UPDATE ".TABLE_PREFIX."settings SET name='maxmessagelength' WHERE name='messagelength'");
 189  
 190      $collation = $db->build_create_table_collation();
 191  
 192      $db->drop_table("mycode");
 193      $db->write_query("CREATE TABLE ".TABLE_PREFIX."mycode (
 194              cid int unsigned NOT NULL auto_increment,
 195              title varchar(100) NOT NULL default '',
 196              description text NOT NULL,
 197              regex text NOT NULL,
 198              replacement text NOT NULL,
 199              active char(3) NOT NULL default '',
 200              PRIMARY KEY(cid)
 201          ) ENGINE=MyISAM{$collation};");
 202  
 203      $db->drop_table("templategroups");
 204      $db->write_query("CREATE TABLE ".TABLE_PREFIX."templategroups (
 205              gid int unsigned NOT NULL auto_increment,
 206              prefix varchar(50) NOT NULL default '',
 207              title varchar(100) NOT NULL default '',
 208              PRIMARY KEY (gid)
 209              ) ENGINE=MyISAM{$collation};");
 210  
 211      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('1','calendar','<lang:group_calendar>');");
 212      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('2','editpost','<lang:group_editpost>');");
 213      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('3','email','<lang:group_email>');");
 214      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('4','emailsubject','<lang:group_emailsubject>');");
 215      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('5','forumbit','<lang:group_forumbit>');");
 216      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('6','forumjump','<lang:group_forumjump>');");
 217      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('7','forumdisplay','<lang:group_forumdisplay>');");
 218      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('8','index','<lang:group_index>');");
 219      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('9','error','<lang:group_error>');");
 220      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('10','memberlist','<lang:group_memberlist>');");
 221      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('11','multipage','<lang:group_multipage>');");
 222      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('12','private','<lang:group_private>');");
 223      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('13','portal','<lang:group_portal>');");
 224      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('14','postbit','<lang:group_postbit>');");
 225      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('15','redirect','<lang:group_redirect>');");
 226      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('16','showthread','<lang:group_showthread>');");
 227      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('17','usercp','<lang:group_usercp>');");
 228      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('18','online','<lang:group_online>');");
 229      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('19','moderation','<lang:group_moderation>');");
 230      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('20','nav','<lang:group_nav>');");
 231      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('21','search','<lang:group_search>');");
 232      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('22','showteam','<lang:group_showteam>');");
 233      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('23','reputation','<lang:group_reputation>');");
 234      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('24','newthread','<lang:group_newthread>');");
 235      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('25','newreply','<lang:group_newreply>');");
 236      $db->write_query("INSERT INTO ".TABLE_PREFIX."templategroups (gid,prefix,title) VALUES ('26','member','<lang:group_member>');");
 237  
 238      $db->drop_table("searchlog");
 239      $db->write_query("CREATE TABLE ".TABLE_PREFIX."searchlog (
 240            sid varchar(32) NOT NULL default '',
 241            uid int unsigned NOT NULL default '0',
 242            dateline bigint(30) NOT NULL default '0',
 243            ipaddress varchar(120) NOT NULL default '',
 244            threads text NOT NULL,
 245            posts text NOT NULL,
 246            searchtype varchar(10) NOT NULL default '',
 247            resulttype varchar(10) NOT NULL default '',
 248            querycache text NOT NULL,
 249            keywords text NOT NULL,
 250            PRIMARY KEY  (sid)
 251          ) ENGINE=MyISAM{$collation};");
 252  
 253      $db->write_query("UPDATE ".TABLE_PREFIX."settings SET name='bannedemails' WHERE name='emailban' LIMIT 1");
 254      $db->write_query("UPDATE ".TABLE_PREFIX."settings SET name='bannedips' WHERE name='ipban' LIMIT 1");
 255  
 256      $query = $db->simple_select("settings", "value", "name='bannedusernames'");
 257      $bannedusernames = $db->fetch_field($query, 'sid');
 258      $bannedusernames = explode(" ", $bannedusernames);
 259      $bannedusernames = implode(",", $bannedusernames);
 260      $query = $db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='".$db->escape_string($bannedusernames)."' WHERE name='bannedusernames'");
 261  
 262      $query = $db->simple_select("settings", "value", "name='bannedemails'");
 263      $bannedemails = $db->fetch_field($query, 'sid');
 264      $bannedemails = explode(" ", $bannedemails);
 265      $bannedemails = implode(",", $bannedemails);
 266      $query = $db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='".$db->escape_string($bannedemails)."' WHERE name='bannedemails'");
 267  
 268      $query = $db->simple_select("settings", "value", "name='bannedips'");
 269      $bannedips = $db->fetch_field($query, 'sid');
 270      $bannedips = explode(" ", $bannedips);
 271      $bannedips = implode(",", $bannedips);
 272      $db->update_query("settings", array('value' => $db->escape_string($bannedips)), "name='bannedips'");
 273  
 274      $db->drop_table("reputation");
 275      $db->write_query("CREATE TABLE ".TABLE_PREFIX."reputation (
 276        rid int unsigned NOT NULL auto_increment,
 277        uid int unsigned NOT NULL default '0',
 278        adduid int unsigned NOT NULL default '0',
 279        reputation bigint(30) NOT NULL default '0',
 280        dateline bigint(30) NOT NULL default '0',
 281        comments text NOT NULL,
 282        PRIMARY KEY(rid)
 283      ) ENGINE=MyISAM{$collation};");
 284  
 285      $db->drop_table("mailqueue");
 286      $db->write_query("CREATE TABLE ".TABLE_PREFIX."mailqueue (
 287          mid int unsigned NOT NULL auto_increment,
 288          mailto varchar(200) NOT NULL,
 289          mailfrom varchar(200) NOT NULL,
 290          subject varchar(200) NOT NULL,
 291          message text NOT NULL,
 292          headers text NOT NULL,
 293          PRIMARY KEY(mid)
 294      ) ENGINE=MyISAM{$collation};");
 295  
 296      $db->update_query("users", array('reputation' => 0));
 297  
 298      $db->update_query("usergroups", array('reputationpower' => 1));
 299      $db->update_query("usergroups", array('reputationpower' => 2), "cancp='yes'");
 300  
 301      if($db->field_exists('rating', "users"))
 302      {
 303          $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP rating;");
 304      }
 305      
 306      if($db->field_exists('attachmentcount', "threads"))
 307      {
 308          $db->write_query("ALTER TABLE ".TABLE_PREFIX."threads DROP attachmentcount;");
 309      }
 310      $db->write_query("ALTER TABLE ".TABLE_PREFIX."threads ADD attachmentcount int(10) unsigned NOT NULL default '0'");
 311      
 312      
 313      if($db->field_exists('posthash', "posts"))
 314      {
 315          $db->write_query("ALTER TABLE ".TABLE_PREFIX."posts DROP posthash;");
 316      }
 317      $db->write_query("ALTER TABLE ".TABLE_PREFIX."posts ADD posthash varchar(32) NOT NULL default '' AFTER visible");
 318      
 319      
 320      $db->write_query("ALTER TABLE ".TABLE_PREFIX."attachtypes CHANGE extension extension varchar(10) NOT NULL;");
 321      
 322      if($db->field_exists('deletetime', "threads"))
 323      {
 324          $db->write_query("ALTER TABLE ".TABLE_PREFIX."threads DROP deletetime;");
 325      }
 326      $db->write_query("ALTER TABLE ".TABLE_PREFIX."threads ADD deletetime int(10) unsigned NOT NULL default '0' AFTER attachmentcount");
 327      
 328      
 329      if($db->field_exists('loginattempts', "sessions"))
 330      {
 331          $db->write_query("ALTER TABLE ".TABLE_PREFIX."sessions DROP loginattempts;");
 332      }
 333      $db->write_query("ALTER TABLE ".TABLE_PREFIX."sessions ADD loginattempts tinyint(2) NOT NULL default '1'");
 334      
 335      
 336      if($db->field_exists('failedlogin', "sessions"))
 337      {
 338          $db->write_query("ALTER TABLE ".TABLE_PREFIX."sessions DROP failedlogin;");
 339      }
 340        $db->write_query("ALTER TABLE ".TABLE_PREFIX."sessions ADD failedlogin bigint(30) NOT NULL default '0'");
 341      
 342      
 343      if($db->field_exists('canviewthreads', "usergroups"))
 344      {
 345          $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups DROP canviewthreads;");
 346      }
 347      $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups ADD canviewthreads char(3) NOT NULL default '' AFTER canview");
 348      
 349      
 350      if($db->field_exists('canviewthreads', "forumpermissions"))
 351      {
 352          $db->write_query("ALTER TABLE ".TABLE_PREFIX."forumpermissions DROP canviewthreads;");
 353      }
 354      $db->write_query("ALTER TABLE ".TABLE_PREFIX."forumpermissions ADD canviewthreads char(3) NOT NULL default '' AFTER canview");
 355      
 356      
 357      $db->drop_table("captcha");
 358      $db->write_query("CREATE TABLE ".TABLE_PREFIX."captcha (
 359        imagehash varchar(32) NOT NULL default '',
 360        imagestring varchar(8) NOT NULL default '',
 361        dateline bigint(30) NOT NULL default '0'
 362      ) ENGINE=MyISAM{$collation};");
 363  
 364      if($db->field_exists('data', "moderatorlog"))
 365      {
 366          $db->write_query("ALTER TABLE ".TABLE_PREFIX."moderatorlog DROP data;");
 367      }
 368      $db->write_query("ALTER TABLE ".TABLE_PREFIX."moderatorlog ADD data text NOT NULL AFTER action;");
 369      
 370      
 371      $db->drop_table("adminsessions");
 372      $db->write_query("CREATE TABLE ".TABLE_PREFIX."adminsessions (
 373          sid varchar(32) NOT NULL default '',
 374          uid int unsigned NOT NULL default '0',
 375          loginkey varchar(50) NOT NULL default '',
 376          ip varchar(40) NOT NULL default '',
 377          dateline bigint(30) NOT NULL default '0',
 378          lastactive bigint(30) NOT NULL default '0'
 379      ) ENGINE=MyISAM{$collation};");
 380  
 381      $db->drop_table("modtools");
 382      $db->write_query("CREATE TABLE ".TABLE_PREFIX."modtools (
 383          tid smallint unsigned NOT NULL auto_increment,
 384          name varchar(200) NOT NULL,
 385          description text NOT NULL,
 386          forums text NOT NULL,
 387          type char(1) NOT NULL default '',
 388          postoptions text NOT NULL,
 389          threadoptions text NOT NULL,
 390          PRIMARY KEY (tid)
 391      ) ENGINE=MyISAM{$collation};");
 392  
 393      if($db->field_exists('disporder', "usergroups"))
 394      {
 395          $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups DROP disporder;");
 396      }
 397      $db->write_query("ALTER TABLE ".TABLE_PREFIX."usergroups ADD disporder smallint(6) NOT NULL default '0' AFTER image");
 398      
 399      
 400      $db->write_query("UPDATE ".TABLE_PREFIX."usergroups SET canviewthreads=canview");
 401      $db->write_query("UPDATE ".TABLE_PREFIX."forumpermissions SET canviewthreads=canview");
 402  
 403      $contents .= "Done</p>";
 404      $contents .= "<p>Click next to continue with the upgrade process.</p>";
 405      $output->print_contents($contents);
 406      $output->print_footer("5_redoconfig");
 407  }
 408  
 409  function upgrade5_redoconfig()
 410  {
 411      global $db, $output, $config, $mybb;
 412      $output->print_header("Rewriting config.php");
 413  
 414      $uid = 0;
 415      if($mybb->input['username'] != '' && !$mybb->input['uid'])
 416      {
 417          $query = $db->simple_select("users", "uid", "username='".$db->escape_string($mybb->input['username'])."'");
 418          $uid = $db->fetch_field($query, "uid");
 419          if(!$uid)
 420          {
 421              echo "<p><span style=\"color: red; font-weight: bold;\">The username you entered could not be found.</span><br />Please ensure you corectly enter a valid username.</p>";
 422          }
 423      }
 424      else if($mybb->input['uid'])
 425      {
 426          $uid = $mybb->input['uid'];
 427      }
 428  
 429      if(!$uid)
 430      {
 431          echo "<p>Please enter your primary administrator username. The user ID of the username you enter here will be written in to the new configuration file which will prevent this account from being banned, edited or deleted.</p>";
 432          echo "<p>Username:</p>";
 433          echo "<p><input type=\"text\" name=\"username\" value=\"\" />";
 434          $output->print_footer("5_redoconfig");
 435          exit;
 436      }
 437  
 438      $fh = @fopen(MYBB_ROOT."inc/config.php", "w");
 439      if(!$fh)
 440      {
 441          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><input type=\"hidden\" name=\"uid\" value=\"{$uid}\" />";
 442          $output->print_footer("5_redoconfig");
 443          exit;
 444      }
 445      
 446      if(!$config['admindir'])
 447      {
 448          $config['admindir'] = "admin";
 449      }
 450      
 451      if(!$config['cachestore'])
 452      {
 453          $config['cachestore'] = "db";
 454      }
 455      $configdata = "<?php
 456  /**
 457   * Database configuration
 458   */
 459  
 460  \$config['dbtype'] = '{$config['database']['type']}';
 461  \$config['hostname'] = '{$config['database']['hostname']}';
 462  \$config['username'] = '{$config['database']['username']}';
 463  \$config['password'] = '{$config['database']['password']}';
 464  \$config['database'] = '{$config['database']['database']}';
 465  \$config['table_prefix'] = '{$config['database']['table_prefix']}';
 466  
 467  /**
 468   * Admin CP directory
 469   *  For security reasons, it is recommended you
 470   *  rename your Admin CP directory. You then need
 471   *  to adjust the value below to point to the
 472   *  new directory.
 473   */
 474  
 475  \$config['admin_dir'] = '{$config['admindir']}';
 476  
 477  /**
 478   * Hide all Admin CP links
 479   *  If you wish to hide all Admin CP links
 480   *  on the front end of the board after
 481   *  renaming your Admin CP directory, set this
 482   *  to 1.
 483   */
 484  
 485  \$config['hide_admin_links'] = 0;
 486  
 487  /**
 488   * Data-cache configuration
 489   *  The data cache is a temporary cache
 490   *  of the most commonly accessed data in MyBB.
 491   *  By default, the database is used to store this data.
 492   *
 493   *  If you wish to use the file system (cache/ directory)
 494   *  you can change the value below to 'files' from 'db'.
 495   */
 496  
 497  \$config['cache_store'] = '{$config['cachestore']}';
 498  
 499  /**
 500   * Super Administrators
 501   *  A comma separated list of user IDs who cannot
 502   *  be edited, deleted or banned in the Admin CP.
 503   *  The administrator permissions for these users
 504   *  cannot be altered either.
 505   */
 506  
 507  \$config['super_admins'] = '{$uid}';
 508  
 509  ?".">";
 510  
 511      fwrite($fh, $configdata);
 512      fclose($fh);
 513      echo "<p>The configuration file has successfully been rewritten.</p>";
 514      echo "<p>Click next to continue with the upgrade process.</p>";
 515      $output->print_footer("5_lastposts");
 516  
 517  }
 518  
 519  function upgrade5_lastposts()
 520  {
 521      global $db, $output;
 522      $output->print_header("Rebuilding Last Post Columns");
 523  
 524      if(!$_POST['tpp'])
 525      {
 526          echo "<p>The next step in the upgrade process involves rebuilding the last post information for every thread in your forum. Below, please enter the number of threads to process per page.</p>";
 527          echo "<p><strong>Threads Per Page:</strong> <input type=\"text\" size=\"3\" value=\"200\" name=\"tpp\" /></p>";
 528          echo "<p>Once you're ready, press next to begin the rebuild process.</p>";
 529          $output->print_footer("5_lastposts");
 530      }
 531      else
 532      {
 533          require_once  MYBB_ROOT."inc/functions_rebuild.php";
 534          
 535          $query = $db->simple_select("threads", "COUNT(*) as num_threads", "closed NOT LIKE 'moved|%'");
 536          $num_threads = $db->fetch_field($query, 'num_threads');
 537          $tpp = intval($_POST['tpp']);
 538          $start = intval($_POST['start']);
 539          $end = $start+$tpp;
 540          if($end > $num_threads)
 541          {
 542              $end = $num_threads;
 543          }
 544          echo "<p>Updating {$start} to {$end} of {$num_threads}...</p>";
 545  
 546          $query = $db->simple_select("threads", "tid, firstpost", "closed NOT LIKE 'moved|%'", array("order_by" => "tid", "order_dir" => "asc", "limit" => $tpp, "limit_start" => $start));
 547  
 548          while($thread = $db->fetch_array($query))
 549          {
 550              rebuild_thread_counters($thread['tid']);
 551              if($thread['firstpost'] == 0)
 552              {
 553                  update_first_post($thread['tid']);
 554              }
 555          }
 556          echo "<p>Done</p>";
 557          if($end >= $num_threads)
 558          {
 559              echo "<p>The rebuild process has completed successfully. Click next to continue with the upgrade.";
 560              $output->print_footer("5_forumlastposts");
 561          }
 562          else
 563          {
 564              echo "<p>Click Next to continue with the build process.</p>";
 565              echo "<input type=\"hidden\" name=\"tpp\" value=\"{$tpp}\" />";
 566              echo "<input type=\"hidden\" name=\"start\" value=\"{$end}\" />";
 567              $output->print_footer("5_lastposts");
 568          }
 569      }
 570  }
 571  
 572  function upgrade5_forumlastposts()
 573  {
 574      global $db, $output;
 575      $output->print_header("Rebuilding Forum Last Posts");
 576      echo "<p>Rebuilding last post information for forums..</p>";
 577      $query = $db->simple_select("forums", "fid");
 578      while($forum = $db->fetch_array($query))
 579      {
 580          update_forum_lastpost($forum['fid']);
 581      }
 582      echo "<p>Done";
 583      echo "<p>Click next to continue with the upgrade process.</p>";
 584      $output->print_footer("5_indexes");
 585  }
 586  
 587  function upgrade5_indexes()
 588  {
 589      global $db, $output;
 590  
 591      $output->print_header("Indexing");
 592      echo "<p>Checking and creating fulltext database indexes..</p>";
 593  
 594  
 595      if($db->is_fulltext("threads", "subject"))
 596      {
 597          $db->drop_index("threads", "subject");
 598      }
 599      if($db->is_fulltext("threads", "subject_2"))
 600      {
 601          $db->drop_index("threads", "subject_2");
 602      }
 603  
 604      if($db->supports_fulltext("threads"))
 605      {
 606          $db->create_fulltext_index("threads", "subject");
 607      }
 608      if($db->supports_fulltext_boolean("posts"))
 609      {
 610          if(!$db->is_fulltext("posts", "message"))
 611          {
 612              $db->create_fulltext_index("posts", "message");
 613          }
 614      }
 615  
 616      $contents .= "Click next to continue with the upgrade process.</p>";
 617      $output->print_contents($contents);
 618      $output->print_footer("5_done");
 619  }
 620  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1