[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/phpbb/db/migration/data/v32x/ -> user_notifications_table_remove_duplicates.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\v32x;
  15  
  16  class user_notifications_table_remove_duplicates extends \phpbb\db\migration\migration
  17  {
  18  	static public function depends_on()
  19      {
  20          return array(
  21              '\phpbb\db\migration\data\v32x\user_notifications_table_temp_index',
  22          );
  23      }
  24  
  25  	public function update_data()
  26      {
  27          return array(
  28              array('custom', array(array($this, 'remove_duplicates'))),
  29          );
  30      }
  31  
  32  	public function remove_duplicates()
  33      {
  34          $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->table_prefix . 'user_notifications');
  35  
  36          $sql = "SELECT item_type, item_id, user_id, method, MAX(notify) AS notify
  37                  FROM {$this->table_prefix}user_notifications
  38                  GROUP BY item_type, item_id, user_id, method
  39                  HAVING COUNT(item_type) > 1";
  40  
  41          $result = $this->sql_query($sql);
  42          while ($row = $this->db->sql_fetchrow($result))
  43          {
  44              // Delete the duplicate entries
  45              $this->sql_query("DELETE FROM {$this->table_prefix}user_notifications
  46                                  WHERE user_id = {$row['user_id']}
  47                                    AND item_type = '{$row['item_type']}'
  48                                    AND method = '{$row['method']}'");
  49  
  50              // And re-insert as a single one
  51              $insert_buffer->insert($row);
  52          }
  53          $this->db->sql_freeresult($result);
  54      }
  55  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1