[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

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

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybboard.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  /**
  13   * Upgrade Script: 1.4.4
  14   */
  15  
  16  
  17  $upgrade_detail = array(
  18      "revert_all_templates" => 0,
  19      "revert_all_themes" => 0,
  20      "revert_all_settings" => 0
  21  );
  22  
  23  @set_time_limit(0);
  24  
  25  function upgrade15_dbchanges()
  26  {
  27      global $db, $output, $mybb, $cache;
  28  
  29      $output->print_header("Performing Queries");
  30  
  31      echo "<p>Performing necessary upgrade queries..</p>";
  32      flush();
  33      
  34      if($db->type != "pgsql")
  35      {
  36          $db->update_query("settinggroups", array('isdefault' => '1'), "isdefault='yes'");
  37          $db->update_query("settinggroups", array('isdefault' => '0'), "isdefault='no'");
  38          
  39          $db->write_query("ALTER TABLE ".TABLE_PREFIX."events CHANGE timezone timezone varchar(4) NOT NULL default '0'");
  40      }
  41      
  42      if($db->type == "pgsql")
  43      {
  44          $db->write_query("ALTER TABLE ".TABLE_PREFIX."warnings ALTER COLUMN revokereason SET default ''");
  45          $db->write_query("ALTER TABLE ".TABLE_PREFIX."warnings ALTER COLUMN notes SET default ''");
  46      }
  47      
  48      $cache->update("internal_settings", array('encryption_key' => random_str(32)));
  49      
  50      if($db->type != "sqlite")
  51      {
  52          $ip_index = $db->index_exists("sessions", "ip");
  53  
  54          if($ip_index == false)
  55          {
  56              if($db->type == "pgsql")
  57              {
  58                  $db->write_query("CREATE INDEX ip ON ".TABLE_PREFIX."sessions (ip)");
  59              }
  60              else
  61              {
  62                  $db->write_query("ALTER TABLE ".TABLE_PREFIX."sessions ADD INDEX (`ip`)");
  63              }
  64          }
  65      }
  66      
  67      $contents .= "Click next to continue with the upgrade process.</p>";
  68      $output->print_contents($contents);
  69      $output->print_footer("15_usernameverify");
  70  }
  71  
  72  function upgrade15_usernameverify()
  73  {
  74      global $db, $output, $mybb;
  75  
  76      $output->print_header("Performing Queries");
  77  
  78      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>";
  79      flush();
  80      
  81      $contents .= "Click next to continue with the upgrade process once you have read the warning.</p>";
  82      $output->print_contents($contents);
  83      $output->print_footer("15_usernameupdate");
  84  }
  85  
  86  function upgrade15_usernameupdate()
  87  {
  88      global $db, $output, $mybb, $plugins;
  89  
  90      $output->print_header("Performing Queries");
  91  
  92      echo "<p>Performing username updates..</p>";
  93      flush();
  94      
  95      require_once  MYBB_ROOT."inc/datahandler.php";
  96      require_once  MYBB_ROOT."inc/datahandlers/user.php";
  97      // Load plugin system for datahandler
  98      require_once  MYBB_ROOT."inc/class_plugins.php";
  99      $plugins = new pluginSystem;
 100      
 101      $not_renameable = array();
 102      
 103      // Because commas can cause some problems with private message sending in usernames we have to remove them
 104      $query = $db->simple_select("users", "uid, username", "username LIKE '%,%'");
 105      while($user = $db->fetch_array($query))
 106      {
 107          $prefix = '';
 108          $userhandler = new UserDataHandler('update');
 109          
 110          do
 111          {
 112              $username = str_replace(',', '', $user['username']).'_'.$prefix;
 113              
 114              $updated_user = array(
 115                  "uid" => $user['uid'],
 116                  "username" => $username
 117              );
 118              $userhandler->set_data($updated_user);
 119              
 120              ++$prefix;
 121          }
 122          while(!$userhandler->verify_username() || $userhandler->verify_username_exists());
 123          
 124          if(!$userhandler->validate_user())
 125          {
 126              $not_renameable[] = htmlspecialchars_uni($user['username']);
 127          }
 128          else
 129          {
 130              $db->update_query("users", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
 131              $db->update_query("posts", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
 132              $db->update_query("threads", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
 133              $db->update_query("threads", array('lastposter' => $db->escape_string($username)), "lastposteruid='{$user['uid']}'");
 134              $db->update_query("forums", array('lastposter' => $db->escape_string($username)), "lastposteruid='{$user['uid']}'");
 135              
 136              update_stats(array("numusers" => "+0"));
 137          }
 138      }
 139      
 140      if(!empty($not_renameable))
 141      {
 142          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 />
 143          <ul>
 144          <li>";
 145          echo implode('</li>\n<li>', $not_renameable);
 146          echo "</li>
 147          </ul>";
 148      }
 149      
 150      $contents .= "Click next to continue with the upgrade process.</p>";
 151      $output->print_contents($contents);
 152      $output->print_footer("15_done");
 153  }
 154  
 155  ?>


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