[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/phpbb/db/migration/data/v310/ -> passwords_convert_p1.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\db\migration\data\v310;
  15  
  16  class passwords_convert_p1 extends \phpbb\db\migration\migration
  17  {
  18  	static public function depends_on()
  19      {
  20          return array('\phpbb\db\migration\data\v310\passwords_p2');
  21      }
  22  
  23  	public function update_data()
  24      {
  25          return array(
  26              array('custom', array(array($this, 'update_passwords'))),
  27          );
  28      }
  29  
  30  	public function update_passwords($start)
  31      {
  32          // Nothing to do if user_pass_convert column doesn't exist
  33          if (!$this->db_tools->sql_column_exists($this->table_prefix . 'users', 'user_pass_convert'))
  34          {
  35              return;
  36          }
  37  
  38          $start = (int) $start;
  39          $limit = 1000;
  40          $converted_users = 0;
  41  
  42          $sql = 'SELECT user_password, user_id
  43              FROM ' . $this->table_prefix . 'users
  44              WHERE user_pass_convert = 1
  45              ORDER BY user_id';
  46          $result = $this->db->sql_query_limit($sql, $limit, $start);
  47  
  48          $update_users = array();
  49          while ($row = $this->db->sql_fetchrow($result))
  50          {
  51              $converted_users++;
  52  
  53              $user_id = (int) $row['user_id'];
  54              // Only prefix passwords without proper prefix
  55              if (!isset($update_users[$user_id]) && !preg_match('#^\$([a-zA-Z0-9\\\]*?)\$#', $row['user_password']))
  56              {
  57                  // Use $CP$ prefix for passwords that need to
  58                  // be converted and set pass convert to false.
  59                  $update_users[$user_id] = '$CP$' . $row['user_password'];
  60              }
  61          }
  62          $this->db->sql_freeresult($result);
  63  
  64          foreach ($update_users as $user_id => $user_password)
  65          {
  66              $sql = 'UPDATE ' . $this->table_prefix . "users
  67                  SET user_password = '" . $this->db->sql_escape($user_password) . "'
  68                  WHERE user_id = $user_id";
  69              $this->sql_query($sql);
  70          }
  71  
  72          if ($converted_users < $limit)
  73          {
  74              // There are no more users to be converted
  75              return;
  76          }
  77  
  78          // There are still more users to query, return the next start value
  79          return $start + $limit;
  80      }
  81  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1