[ Index ]

PHP Cross Reference of MyBB 1.8.40

title

Body

[close]

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


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