[ Index ]

PHP Cross Reference of MyBB 1.8.37

title

Body

[close]

/install/resources/ -> upgrade15.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.4.4
  13   */
  14  
  15  
  16  $upgrade_detail = array(
  17      "revert_all_templates" => 0,
  18      "revert_all_themes" => 0,
  19      "revert_all_settings" => 0
  20  );
  21  
  22  @set_time_limit(0);
  23  
  24  function upgrade15_dbchanges()
  25  {
  26      global $db, $output, $mybb, $cache;
  27  
  28      $output->print_header("Performing Queries");
  29  
  30      echo "<p>Performing necessary upgrade queries..</p>";
  31      flush();
  32  
  33      if($db->type != "pgsql")
  34      {
  35          $db->update_query("settinggroups", array('isdefault' => '1'), "isdefault='yes'");
  36          $db->update_query("settinggroups", array('isdefault' => '0'), "isdefault='no'");
  37  
  38          $db->write_query("ALTER TABLE ".TABLE_PREFIX."events CHANGE timezone timezone varchar(4) NOT NULL default '0'");
  39      }
  40  
  41      if($db->type == "pgsql")
  42      {
  43          $db->write_query("ALTER TABLE ".TABLE_PREFIX."warnings ALTER COLUMN revokereason SET default ''");
  44          $db->write_query("ALTER TABLE ".TABLE_PREFIX."warnings ALTER COLUMN notes SET default ''");
  45      }
  46  
  47      $cache->update("internal_settings", array('encryption_key' => random_str(32)));
  48  
  49      if($db->type != "sqlite")
  50      {
  51          $ip_index = $db->index_exists("sessions", "ip");
  52  
  53          if($ip_index == false)
  54          {
  55              if($db->type == "pgsql")
  56              {
  57                  $db->write_query("CREATE INDEX ip ON ".TABLE_PREFIX."sessions (ip)");
  58              }
  59              else
  60              {
  61                  $db->write_query("ALTER TABLE ".TABLE_PREFIX."sessions ADD INDEX (`ip`)");
  62              }
  63          }
  64      }
  65  
  66      $contents .= "Click next to continue with the upgrade process.</p>";
  67      $output->print_contents($contents);
  68      $output->print_footer("15_usernameverify");
  69  }
  70  
  71  function upgrade15_usernameverify()
  72  {
  73      global $db, $output, $mybb;
  74  
  75      $output->print_header("Performing Queries");
  76  
  77      echo "<p><span style=\"font-size: xx-large\">WARNING - PLEASE READ THE FOLLOWING:</span> The next step of this process will remove <strong>ALL</strong> commas (,) from the <i>usernames</i> of your forum whom contain them. The reason for this change is commas in usernames can make the private messages in MyBB return errors when sending to these users.</p>";
  78      flush();
  79  
  80      $contents .= "Click next to continue with the upgrade process once you have read the warning.</p>";
  81      $output->print_contents($contents);
  82      $output->print_footer("15_usernameupdate");
  83  }
  84  
  85  function upgrade15_usernameupdate()
  86  {
  87      global $db, $output, $mybb, $plugins;
  88  
  89      $output->print_header("Performing Queries");
  90  
  91      echo "<p>Performing username updates..</p>";
  92      flush();
  93  
  94      require_once  MYBB_ROOT."inc/datahandler.php";
  95      require_once  MYBB_ROOT."inc/datahandlers/user.php";
  96      // Load plugin system for datahandler
  97      require_once  MYBB_ROOT."inc/class_plugins.php";
  98      $plugins = new pluginSystem;
  99  
 100      $not_renameable = array();
 101  
 102      // Because commas can cause some problems with private message sending in usernames we have to remove them
 103      $query = $db->simple_select("users", "uid, username", "username LIKE '%,%'");
 104      while($user = $db->fetch_array($query))
 105      {
 106          $prefix = '';
 107          $userhandler = new UserDataHandler('update');
 108  
 109          do
 110          {
 111              $username = str_replace(',', '', $user['username']).'_'.$prefix;
 112  
 113              $updated_user = array(
 114                  "uid" => $user['uid'],
 115                  "username" => $username
 116              );
 117              $userhandler->set_data($updated_user);
 118  
 119              ++$prefix;
 120          }
 121          while(!$userhandler->verify_username() || $userhandler->verify_username_exists());
 122  
 123          if(!$userhandler->validate_user())
 124          {
 125              $not_renameable[] = htmlspecialchars_uni($user['username']);
 126          }
 127          else
 128          {
 129              $db->update_query("users", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
 130              $db->update_query("posts", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
 131              $db->update_query("threads", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
 132              $db->update_query("threads", array('lastposter' => $db->escape_string($username)), "lastposteruid='{$user['uid']}'");
 133              $db->update_query("forums", array('lastposter' => $db->escape_string($username)), "lastposteruid='{$user['uid']}'");
 134  
 135              update_stats(array("numusers" => "+0"));
 136          }
 137      }
 138  
 139      if(!empty($not_renameable))
 140      {
 141          echo "<span style=\"color: red;\">NOTICE:</span> The following users could not be renamed automatically. Please rename these users in the Admin CP manually after the upgrade process has finished completing:<br />
 142          <ul>
 143          <li>";
 144          echo implode('</li>\n<li>', $not_renameable);
 145          echo "</li>
 146          </ul>";
 147      }
 148  
 149      $contents .= "Click next to continue with the upgrade process.</p>";
 150      $output->print_contents($contents);
 151      $output->print_footer("15_done");
 152  }
 153  


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