[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/install/resources/ -> upgrade13.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 or 1.4.1
  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 upgrade13_dbchanges()
  26  {
  27      global $db, $output, $mybb;
  28  
  29      $output->print_header("Performing Queries");
  30  
  31      echo "<p>Performing necessary upgrade queries..</p>";
  32      flush();
  33  
  34      if($db->type == "mysql" || $db->type == "mysqli")
  35      {
  36          $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminsessions ADD INDEX ( `uid` )");
  37          $db->write_query("ALTER TABLE ".TABLE_PREFIX."adminsessions ADD INDEX ( `dateline` )");
  38      }
  39      
  40      if($db->type != "sqlite")
  41      {
  42          if($db->index_exists("users", "username"))
  43          {
  44              $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP KEY username");
  45          }
  46          
  47          $query = $db->simple_select("users", "username, uid", "1=1 GROUP BY username HAVING count(*) > 1");
  48          while($user = $db->fetch_array($query))
  49          {
  50              $db->update_query("users", array('username' => $user['username']."_dup".$user['uid']), "uid='{$user['uid']}'", 1);
  51          }
  52          
  53          if($db->type == "pgsql")
  54          {
  55              $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD UNIQUE(username)");
  56          }
  57          else
  58          {
  59              $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD UNIQUE KEY username (username)");
  60          }
  61      }
  62      
  63      if($db->type == "pgsql")
  64      {
  65          $db->write_query("ALTER TABLE ".TABLE_PREFIX."users CHANGE longregip longregip int NOT NULL default '0'");
  66          $db->write_query("ALTER TABLE ".TABLE_PREFIX."users CHANGE longlastip longlastip int NOT NULL default '0'");
  67      
  68          $db->write_query("ALTER TABLE ".TABLE_PREFIX."posts CHANGE longipaddress longipaddress int NOT NULL default '0'");
  69      }
  70      else
  71      {
  72          $db->write_query("ALTER TABLE ".TABLE_PREFIX."users CHANGE longregip longregip int(11) NOT NULL default '0'");
  73          $db->write_query("ALTER TABLE ".TABLE_PREFIX."users CHANGE longlastip longlastip int(11) NOT NULL default '0'");
  74      
  75          $db->write_query("ALTER TABLE ".TABLE_PREFIX."posts CHANGE longipaddress longipaddress int(11) NOT NULL default '0'");
  76      }
  77  
  78      $contents .= "Click next to continue with the upgrade process.</p>";
  79      $output->print_contents($contents);
  80      $output->print_footer("13_dbchanges1");
  81  }
  82  
  83  function upgrade13_dbchanges1()
  84  {
  85      global $db, $output;
  86      
  87      $output->print_header("Post IP Repair Conversion");
  88  
  89      if(!$_POST['ipspage'])
  90      {
  91          $ipp = 5000;
  92      }
  93      else
  94      {
  95          $ipp = $_POST['ipspage'];
  96      }
  97  
  98      if($_POST['ipstart'])
  99      {
 100          $startat = $_POST['ipstart'];
 101          $upper = $startat+$ipp;
 102          $lower = $startat;
 103      }
 104      else
 105      {
 106          $startat = 0;
 107          $upper = $ipp;
 108          $lower = 1;
 109      }
 110  
 111      $query = $db->simple_select("posts", "COUNT(pid) AS ipcount");
 112      $cnt = $db->fetch_array($query);
 113      
 114      if($upper > $cnt['ipcount'])
 115      {
 116          $upper = $cnt['ipcount'];
 117      }
 118  
 119      echo "<p>Repairing ip {$lower} to {$upper} ({$cnt['ipcount']} Total)</p>";
 120      flush();
 121      
 122      $ipaddress = false;
 123      
 124      $query = $db->simple_select("posts", "ipaddress, longipaddress, pid", "", array('limit_start' => $lower, 'limit' => $ipp));
 125      while($post = $db->fetch_array($query))
 126      {
 127          // Have we already converted this ip?
 128          if(my_ip2long($post['ipaddress']) < 0)
 129          {
 130              $db->update_query("posts", array('longipaddress' => my_ip2long($post['ipaddress'])), "pid = '{$post['pid']}'");
 131          }
 132          $ipaddress = true;
 133      }
 134      
 135      $remaining = $upper-$cnt['ipcount'];
 136      if($remaining && $ipaddress)
 137      {
 138          $nextact = "13_dbchanges1";
 139          $startat = $startat+$ipp;
 140          $contents = "<p><input type=\"hidden\" name=\"ipspage\" value=\"$ipp\" /><input type=\"hidden\" name=\"ipstart\" value=\"$startat\" />Done. Click Next to move on to the next set of post ips.</p>";
 141      }
 142      else
 143      {
 144          $nextact = "13_dbchanges2";
 145          $contents = "<p>Done</p><p>All post ips have been converted to the new ip format. Click next to continue.</p>";
 146      }
 147      $output->print_contents($contents);
 148  
 149      global $footer_extra;
 150      $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
 151  
 152      $output->print_footer($nextact);
 153  }
 154  
 155  function upgrade13_dbchanges2()
 156  {
 157      global $db, $output;
 158      
 159      $output->print_header("User IP Repair Conversion");
 160  
 161      if(!$_POST['ipspage'])
 162      {
 163          $ipp = 5000;
 164      }
 165      else
 166      {
 167          $ipp = $_POST['ipspage'];
 168      }
 169  
 170      if($_POST['ipstart'])
 171      {
 172          $startat = $_POST['ipstart'];
 173          $upper = $startat+$ipp;
 174          $lower = $startat;
 175      }
 176      else
 177      {
 178          $startat = 0;
 179          $upper = $ipp;
 180          $lower = 1;
 181      }
 182  
 183      $query = $db->simple_select("users", "COUNT(uid) AS ipcount");
 184      $cnt = $db->fetch_array($query);
 185      
 186      if($upper > $cnt['ipcount'])
 187      {
 188          $upper = $cnt['ipcount'];
 189      }
 190  
 191      $contents .= "<p>Repairing ip {$lower} to {$upper} ({$cnt['ipcount']} Total)</p>";
 192      
 193      $ipaddress = false;
 194      $update_array = array();
 195      
 196      $query = $db->simple_select("users", "regip, lastip, longlastip, longregip, uid", "", array('limit_start' => $lower, 'limit' => $ipp));
 197      while($user = $db->fetch_array($query))
 198      {
 199          // Have we already converted this ip?
 200          if(my_ip2long($user['regip']) < 0)
 201          {
 202              $update_array['longregip'] = intval(my_ip2long($user['regip']));
 203          }
 204          
 205          if(my_ip2long($user['lastip']) < 0)
 206          {
 207              $update_array['longlastip'] = intval(my_ip2long($user['lastip']));
 208          }
 209          
 210          if(!empty($update_array))
 211          {
 212              $db->update_query("users", $update_array, "uid = '{$user['uid']}'");
 213          }
 214          
 215          $update_array = array();
 216          $ipaddress = true;
 217      }
 218  
 219      $remaining = $upper-$cnt['ipcount'];
 220      if($remaining && $ipaddress)
 221      {
 222          $nextact = "13_dbchanges2";
 223          $startat = $startat+$ipp;
 224          $contents .= "<p><input type=\"hidden\" name=\"ipspage\" value=\"$ipp\" /><input type=\"hidden\" name=\"ipstart\" value=\"$startat\" />Done. Click Next to move on to the next set of user ips.</p>";
 225      }
 226      else
 227      {
 228          $nextact = "13_done";
 229          $contents .= "<p>Done</p><p>All user ips have been converted to the new ip format. Click next to continue.</p>";
 230      }
 231      $output->print_contents($contents);
 232  
 233      global $footer_extra;
 234      $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
 235  
 236      $output->print_footer($nextact);    
 237  }
 238  
 239  ?>


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