[ Index ]

PHP Cross Reference of MyBB 1.8.40

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


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