[ Index ]

PHP Cross Reference of MyBB 1.8.37

title

Body

[close]

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

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


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref