Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
336 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p1.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* | ||
* This file is part of the phpBB Forum Software package. | ||
* | ||
* @copyright (c) phpBB Limited <https://www.phpbb.com> | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
* For full copyright and license information, please see | ||
* the docs/CREDITS.txt file. | ||
* | ||
*/ | ||
|
||
namespace phpbb\db\migration\data\v32x; | ||
|
||
class user_notifications_table_index_p1 extends \phpbb\db\migration\migration | ||
{ | ||
static public function depends_on() | ||
{ | ||
return array( | ||
'\phpbb\db\migration\data\v32x\cookie_notice_p2', | ||
); | ||
} | ||
|
||
public function update_schema() | ||
{ | ||
return array( | ||
'add_index' => array( | ||
$this->table_prefix . 'user_notifications' => array( | ||
'user_id' => array('user_id'), | ||
), | ||
), | ||
); | ||
} | ||
|
||
public function revert_schema() | ||
{ | ||
return array( | ||
'drop_keys' => array( | ||
$this->table_prefix . 'user_notifications' => array( | ||
'user_id', | ||
), | ||
), | ||
); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p2.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* | ||
* This file is part of the phpBB Forum Software package. | ||
* | ||
* @copyright (c) phpBB Limited <https://www.phpbb.com> | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
* For full copyright and license information, please see | ||
* the docs/CREDITS.txt file. | ||
* | ||
*/ | ||
|
||
namespace phpbb\db\migration\data\v32x; | ||
|
||
class user_notifications_table_index_p2 extends \phpbb\db\migration\migration | ||
{ | ||
static public function depends_on() | ||
{ | ||
return array( | ||
'\phpbb\db\migration\data\v32x\user_notifications_table_index_p1', | ||
); | ||
} | ||
|
||
public function update_schema() | ||
{ | ||
return array( | ||
'add_index' => array( | ||
$this->table_prefix . 'user_notifications' => array( | ||
'uid_itm_id' => array('user_id', 'item_id'), | ||
), | ||
), | ||
); | ||
} | ||
|
||
public function revert_schema() | ||
{ | ||
return array( | ||
'drop_keys' => array( | ||
$this->table_prefix . 'user_notifications' => array( | ||
'uid_itm_id', | ||
), | ||
), | ||
); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p3.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* | ||
* This file is part of the phpBB Forum Software package. | ||
* | ||
* @copyright (c) phpBB Limited <https://www.phpbb.com> | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
* For full copyright and license information, please see | ||
* the docs/CREDITS.txt file. | ||
* | ||
*/ | ||
|
||
namespace phpbb\db\migration\data\v32x; | ||
|
||
class user_notifications_table_index_p3 extends \phpbb\db\migration\migration | ||
{ | ||
static public function depends_on() | ||
{ | ||
return array( | ||
'\phpbb\db\migration\data\v32x\user_notifications_table_index_p2', | ||
); | ||
} | ||
|
||
public function update_schema() | ||
{ | ||
return array( | ||
'add_index' => array( | ||
$this->table_prefix . 'user_notifications' => array( | ||
'usr_itm_tpe' => array('user_id', 'item_type', 'item_id'), | ||
), | ||
), | ||
); | ||
} | ||
|
||
public function revert_schema() | ||
{ | ||
return array( | ||
'drop_keys' => array( | ||
$this->table_prefix . 'user_notifications' => array( | ||
'usr_itm_tpe', | ||
), | ||
), | ||
); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
phpBB/phpbb/db/migration/data/v32x/user_notifications_table_reduce_column_sizes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* | ||
* This file is part of the phpBB Forum Software package. | ||
* | ||
* @copyright (c) phpBB Limited <https://www.phpbb.com> | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
* For full copyright and license information, please see | ||
* the docs/CREDITS.txt file. | ||
* | ||
*/ | ||
|
||
namespace phpbb\db\migration\data\v32x; | ||
|
||
class user_notifications_table_reduce_column_sizes extends \phpbb\db\migration\migration | ||
{ | ||
static public function depends_on() | ||
{ | ||
return array( | ||
'\phpbb\db\migration\data\v32x\user_notifications_table_remove_duplicates', | ||
); | ||
} | ||
|
||
public function update_schema() | ||
{ | ||
return array( | ||
'change_columns' => array( | ||
$this->table_prefix . 'user_notifications' => array( | ||
'item_type' => array('VCHAR:165', ''), | ||
'method' => array('VCHAR:165', ''), | ||
), | ||
), | ||
); | ||
} | ||
|
||
public function revert_schema() | ||
{ | ||
return array( | ||
'change_columns' => array( | ||
$this->table_prefix . 'user_notifications' => array( | ||
'item_type' => array('VCHAR:255', ''), | ||
'method' => array('VCHAR:255', ''), | ||
), | ||
), | ||
); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
phpBB/phpbb/db/migration/data/v32x/user_notifications_table_remove_duplicates.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* | ||
* This file is part of the phpBB Forum Software package. | ||
* | ||
* @copyright (c) phpBB Limited <https://www.phpbb.com> | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
* For full copyright and license information, please see | ||
* the docs/CREDITS.txt file. | ||
* | ||
*/ | ||
|
||
namespace phpbb\db\migration\data\v32x; | ||
|
||
class user_notifications_table_remove_duplicates extends \phpbb\db\migration\migration | ||
{ | ||
static public function depends_on() | ||
{ | ||
return array( | ||
'\phpbb\db\migration\data\v32x\user_notifications_table_index_p3', | ||
); | ||
} | ||
|
||
public function update_data() | ||
{ | ||
return array( | ||
array('custom', array(array($this, 'remove_duplicates'))), | ||
); | ||
} | ||
|
||
public function remove_duplicates() | ||
{ | ||
$insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->table_prefix . 'user_notifications'); | ||
|
||
$sql = "SELECT item_type, item_id, user_id, method, MAX(notify) AS notify | ||
FROM {$this->table_prefix}user_notifications | ||
GROUP BY item_type, item_id, user_id, method | ||
HAVING COUNT(item_type) > 1"; | ||
|
||
$result = $this->sql_query($sql); | ||
while ($row = $this->db->sql_fetchrow($result)) | ||
{ | ||
// Delete the duplicate entries | ||
$this->sql_query("DELETE FROM {$this->table_prefix}user_notifications | ||
WHERE user_id = {$row['user_id']} | ||
AND item_type = '{$row['item_type']}' | ||
AND method = '{$row['method']}'"); | ||
|
||
// And re-insert as a single one | ||
$insert_buffer->insert($row); | ||
} | ||
$this->db->sql_freeresult($result); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
phpBB/phpbb/db/migration/data/v32x/user_notifications_table_unique_index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* | ||
* This file is part of the phpBB Forum Software package. | ||
* | ||
* @copyright (c) phpBB Limited <https://www.phpbb.com> | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
* For full copyright and license information, please see | ||
* the docs/CREDITS.txt file. | ||
* | ||
*/ | ||
|
||
namespace phpbb\db\migration\data\v32x; | ||
|
||
class user_notifications_table_unique_index extends \phpbb\db\migration\migration | ||
{ | ||
static public function depends_on() | ||
{ | ||
return array( | ||
'\phpbb\db\migration\data\v32x\user_notifications_table_reduce_column_sizes', | ||
); | ||
} | ||
|
||
public function update_schema() | ||
{ | ||
return array( | ||
'add_unique_index' => array( | ||
$this->table_prefix . 'user_notifications' => array( | ||
'itm_usr_mthd' => array('item_type', 'item_id', 'user_id', 'method'), | ||
), | ||
), | ||
); | ||
} | ||
|
||
public function revert_schema() | ||
{ | ||
return array( | ||
'drop_keys' => array( | ||
$this->table_prefix . 'user_notifications' => array( | ||
'itm_usr_mthd', | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.