[ Index ]

PHP Cross Reference of MyBB 1.6.5

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: upgrade15.php 5297 2010-12-28 22:01:14Z Tomm $
  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;
  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      
  98      $not_renameable = array();
  99      
 100      // Because commas can cause some problems with private message sending in usernames we have to remove them
 101      $query = $db->simple_select("users", "uid, username", "username LIKE '%,%'");
 102      while($user = $db->fetch_array($query))
 103      {
 104          $prefix = '';
 105          $userhandler = new UserDataHandler('update');
 106          
 107          do
 108          {
 109              $username = str_replace(',', '', $user['username']).'_'.$prefix;
 110              
 111              $updated_user = array(
 112                  "uid" => $user['uid'],
 113                  "username" => $username
 114              );
 115              $userhandler->set_data($updated_user);
 116              
 117              ++$prefix;
 118          }
 119          while(!$userhandler->verify_username() || $userhandler->verify_username_exists());
 120          
 121          if(!$userhandler->validate_user())
 122          {
 123              $not_renameable[] = htmlspecialchars_uni($user['username']);
 124          }
 125          else
 126          {
 127              $db->update_query("users", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
 128              $db->update_query("posts", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
 129              $db->update_query("threads", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
 130              $db->update_query("threads", array('lastposter' => $db->escape_string($username)), "lastposteruid='{$user['uid']}'");
 131              $db->update_query("forums", array('lastposter' => $db->escape_string($username)), "lastposteruid='{$user['uid']}'");
 132              
 133              update_stats(array("numusers" => "+0"));
 134          }
 135      }
 136      
 137      if(!empty($not_renameable))
 138      {
 139          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 />
 140          <ul>
 141          <li>";
 142          echo implode('</li>\n<li>', $not_renameable);
 143          echo "</li>
 144          </ul>";
 145      }
 146      
 147      $contents .= "Click next to continue with the upgrade process.</p>";
 148      $output->print_contents($contents);
 149      $output->print_footer("15_done");
 150  }
 151  
 152  ?>


Generated: Sun Dec 11 14:16:27 2011 Cross-referenced by PHPXref 0.7.1