[ticket/9687] Update ban migrations and clean up code

PHPBB3-9687
This commit is contained in:
Marc Alexander 2023-07-04 14:55:07 +02:00
parent d4a4dd453a
commit d99968a800
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
2 changed files with 72 additions and 70 deletions

View file

@ -11,59 +11,61 @@
* *
*/ */
namespace phpbb\db\migration\data\v330; namespace phpbb\db\migration\data\v400;
class ban_table_p1 extends \phpbb\db\migration\migration use phpbb\db\migration\migration;
class ban_table_p1 extends migration
{ {
static public function depends_on() static public function depends_on(): array
{ {
return array('\phpbb\db\migration\data\v320\default_data_type_ids'); return ['\phpbb\db\migration\data\v320\default_data_type_ids'];
} }
public function update_schema() public function update_schema(): array
{ {
return array( return [
'add_tables' => array( 'add_tables' => [
$this->table_prefix . 'bans' => array( $this->table_prefix . 'bans' => [
'COLUMNS' => array( 'COLUMNS' => [
'ban_id' => array('ULINT', null, 'auto_increment'), 'ban_id' => ['ULINT', null, 'auto_increment'],
'ban_mode' => array('VCHAR', ''), 'ban_mode' => ['VCHAR', ''],
'ban_item' => array('STEXT_UNI', ''), 'ban_item' => ['STEXT_UNI', ''],
'ban_start' => array('TIMESTAMP', 0), 'ban_start' => ['TIMESTAMP', 0],
'ban_end' => array('TIMESTAMP', 0), 'ban_end' => ['TIMESTAMP', 0],
'ban_reason' => array('VCHAR_UNI', ''), 'ban_reason' => ['VCHAR_UNI', ''],
'ban_reason_display' => array('VCHAR_UNI', ''), 'ban_reason_display' => ['VCHAR_UNI', ''],
), ],
'PRIMARY_KEY' => 'ban_id', 'PRIMARY_KEY' => 'ban_id',
'KEYS' => array( 'KEYS' => [
'ban_end' => array('INDEX', 'ban_end'), 'ban_end' => ['INDEX', 'ban_end'],
), ],
), ],
), ],
); ];
} }
public function revert_schema() public function revert_schema(): array
{ {
return array( return [
'drop_tables' => array( 'drop_tables' => [
$this->table_prefix . 'bans', $this->table_prefix . 'bans',
), ],
); ];
} }
public function update_data() public function update_data(): array
{ {
return array( return [
array('custom', array(array($this, 'old_to_new'))), ['custom', [[$this, 'old_to_new']]],
); ];
} }
public function revert_data() public function revert_data(): array
{ {
return array( return [
array('custom', array(array($this, 'new_to_old'))), ['custom', [[$this, 'new_to_old']]],
); ];
} }
public function old_to_new($start) public function old_to_new($start)
@ -73,7 +75,7 @@ class ban_table_p1 extends \phpbb\db\migration\migration
$processed_rows = 0; $processed_rows = 0;
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . $this->table_prefix . "banlist"; FROM ' . $this->table_prefix . 'banlist';
$result = $this->db->sql_query_limit($sql, $limit, $start); $result = $this->db->sql_query_limit($sql, $limit, $start);
$bans = []; $bans = [];
@ -139,7 +141,7 @@ class ban_table_p1 extends \phpbb\db\migration\migration
$processed_rows = 0; $processed_rows = 0;
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . $this->table_prefix . "bans"; FROM ' . $this->table_prefix . 'bans';
$result = $this->db->sql_query_limit($sql, $limit, $start); $result = $this->db->sql_query_limit($sql, $limit, $start);
$bans = []; $bans = [];

View file

@ -11,49 +11,49 @@
* *
*/ */
namespace phpbb\db\migration\data\v330; namespace phpbb\db\migration\data\v400;
class ban_table_p2 extends \phpbb\db\migration\migration class ban_table_p2 extends \phpbb\db\migration\migration
{ {
static public function depends_on() static public function depends_on(): array
{ {
return array('\phpbb\db\migration\data\v330\ban_table_p1'); return ['\phpbb\db\migration\data\v400\ban_table_p1'];
} }
public function update_schema() public function update_schema(): array
{ {
return array( return [
'drop_tables' => array( 'drop_tables' => [
$this->table_prefix . 'banlist', $this->table_prefix . 'banlist',
), ],
); ];
} }
public function revert_schema() public function revert_schema(): array
{ {
return array( return [
'add_tables' => array( 'add_tables' => [
$this->table_prefix . 'banlist' => array( $this->table_prefix . 'banlist' => [
'COLUMNS' => array( 'COLUMNS' => [
'ban_id' => array('ULINT', null, 'auto_increment'), 'ban_id' => ['ULINT', null, 'auto_increment'],
'ban_userid' => array('ULINT', 0), 'ban_userid' => ['ULINT', 0],
'ban_ip' => array('VCHAR:40', ''), 'ban_ip' => ['VCHAR:40', ''],
'ban_email' => array('VCHAR_UNI:100', ''), 'ban_email' => ['VCHAR_UNI:100', ''],
'ban_start' => array('TIMESTAMP', 0), 'ban_start' => ['TIMESTAMP', 0],
'ban_end' => array('TIMESTAMP', 0), 'ban_end' => ['TIMESTAMP', 0],
'ban_exclude' => array('BOOL', 0), 'ban_exclude' => ['BOOL', 0],
'ban_reason' => array('VCHAR_UNI', ''), 'ban_reason' => ['VCHAR_UNI', ''],
'ban_give_reason' => array('VCHAR_UNI', ''), 'ban_give_reason' => ['VCHAR_UNI', ''],
), ],
'PRIMARY_KEY' => 'ban_id', 'PRIMARY_KEY' => 'ban_id',
'KEYS' => array( 'KEYS' => [
'ban_end' => array('INDEX', 'ban_end'), 'ban_end' => ['INDEX', 'ban_end'],
'ban_user' => array('INDEX', array('ban_userid', 'ban_exclude')), 'ban_user' => ['INDEX', ['ban_userid', 'ban_exclude']],
'ban_email' => array('INDEX', array('ban_email', 'ban_exclude')), 'ban_email' => ['INDEX', ['ban_email', 'ban_exclude']],
'ban_ip' => array('INDEX', array('ban_ip', 'ban_exclude')), 'ban_ip' => ['INDEX', ['ban_ip', 'ban_exclude']],
), ],
), ],
), ],
); ];
} }
} }