Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 97 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
ban_table_p1 | |
0.00% |
0 / 97 |
|
0.00% |
0 / 7 |
462 | |
0.00% |
0 / 1 |
depends_on | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
update_schema | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
2 | |||
revert_schema | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
update_data | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
revert_data | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
old_to_new | |
0.00% |
0 / 39 |
|
0.00% |
0 / 1 |
110 | |||
new_to_old | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
42 |
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\v400; |
15 | |
16 | use phpbb\db\migration\migration; |
17 | |
18 | class ban_table_p1 extends migration |
19 | { |
20 | public static function depends_on(): array |
21 | { |
22 | return ['\phpbb\db\migration\data\v320\default_data_type_ids']; |
23 | } |
24 | |
25 | public function update_schema(): array |
26 | { |
27 | return [ |
28 | 'add_tables' => [ |
29 | $this->table_prefix . 'bans' => [ |
30 | 'COLUMNS' => [ |
31 | 'ban_id' => ['ULINT', null, 'auto_increment'], |
32 | 'ban_userid' => ['ULINT', 0], |
33 | 'ban_mode' => ['VCHAR', ''], |
34 | 'ban_item' => ['STEXT_UNI', ''], |
35 | 'ban_start' => ['TIMESTAMP', 0], |
36 | 'ban_end' => ['TIMESTAMP', 0], |
37 | 'ban_reason' => ['VCHAR_UNI', ''], |
38 | 'ban_reason_display' => ['VCHAR_UNI', ''], |
39 | ], |
40 | 'PRIMARY_KEY' => 'ban_id', |
41 | 'KEYS' => [ |
42 | 'ban_userid' => ['INDEX', 'ban_userid'], |
43 | 'ban_end' => ['INDEX', 'ban_end'], |
44 | ], |
45 | ], |
46 | ], |
47 | ]; |
48 | } |
49 | |
50 | public function revert_schema(): array |
51 | { |
52 | return [ |
53 | 'drop_tables' => [ |
54 | $this->table_prefix . 'bans', |
55 | ], |
56 | ]; |
57 | } |
58 | |
59 | public function update_data(): array |
60 | { |
61 | return [ |
62 | ['custom', [[$this, 'old_to_new']]], |
63 | ]; |
64 | } |
65 | |
66 | public function revert_data(): array |
67 | { |
68 | return [ |
69 | ['custom', [[$this, 'new_to_old']]], |
70 | ]; |
71 | } |
72 | |
73 | public function old_to_new($start) |
74 | { |
75 | $start = (int) $start; |
76 | $limit = 500; |
77 | $processed_rows = 0; |
78 | |
79 | $sql = 'SELECT * |
80 | FROM ' . $this->table_prefix . 'banlist'; |
81 | $result = $this->db->sql_query_limit($sql, $limit, $start); |
82 | |
83 | $bans = []; |
84 | while ($row = $this->db->sql_fetchrow($result)) |
85 | { |
86 | $processed_rows++; |
87 | |
88 | if ($row['ban_exclude']) |
89 | { |
90 | continue; |
91 | } |
92 | |
93 | $row['ban_userid'] = (int) $row['ban_userid']; |
94 | $item = $mode = ''; |
95 | if ($row['ban_ip'] !== '') |
96 | { |
97 | $mode = 'ip'; |
98 | $item = $row['ban_ip']; |
99 | } |
100 | else if ($row['ban_email'] !== '') |
101 | { |
102 | $mode = 'email'; |
103 | $item = $row['ban_email']; |
104 | } |
105 | else if ($row['ban_userid'] !== 0) |
106 | { |
107 | $mode = 'user'; |
108 | $item = $row['ban_userid']; |
109 | } |
110 | |
111 | if ($mode === '' || $item === '') |
112 | { |
113 | continue; |
114 | } |
115 | |
116 | $bans[] = [ |
117 | 'ban_mode' => $mode, |
118 | 'ban_userid' => $row['ban_userid'], |
119 | 'ban_item' => $item, |
120 | 'ban_start' => $row['ban_start'], |
121 | 'ban_end' => $row['ban_end'], |
122 | 'ban_reason' => $row['ban_reason'], |
123 | 'ban_reason_display' => $row['ban_give_reason'], |
124 | ]; |
125 | } |
126 | $this->db->sql_freeresult($result); |
127 | |
128 | if ($processed_rows > 0) |
129 | { |
130 | $this->db->sql_multi_insert($this->table_prefix . 'bans', $bans); |
131 | } |
132 | else if ($processed_rows < $limit) |
133 | { |
134 | return; |
135 | } |
136 | |
137 | return $limit + $start; |
138 | } |
139 | |
140 | public function new_to_old($start) |
141 | { |
142 | $start = (int) $start; |
143 | $limit = 500; |
144 | $processed_rows = 0; |
145 | |
146 | $sql = 'SELECT * |
147 | FROM ' . $this->table_prefix . 'bans'; |
148 | $result = $this->db->sql_query_limit($sql, $limit, $start); |
149 | |
150 | $bans = []; |
151 | while ($row = $this->db->sql_fetchrow($result)) |
152 | { |
153 | $processed_rows++; |
154 | |
155 | $bans[] = [ |
156 | 'ban_userid' => (int) $row['ban_userid'], |
157 | 'ban_ip' => ($row['ban_mode'] === 'ip') ? $row['ban_item'] : '', |
158 | 'ban_email' => ($row['ban_mode'] === 'email') ? $row['ban_item'] : '', |
159 | 'ban_start' => $row['ban_start'], |
160 | 'ban_end' => $row['ban_end'], |
161 | 'ban_exclude' => false, |
162 | 'ban_reason' => $row['ban_reason'], |
163 | 'ban_give_reason' => $row['ban_reason_display'], |
164 | ]; |
165 | } |
166 | $this->db->sql_freeresult($result); |
167 | |
168 | if ($processed_rows > 0) |
169 | { |
170 | $this->db->sql_multi_insert($this->table_prefix . 'banlist', $bans); |
171 | } |
172 | else if ($processed_rows < $limit) |
173 | { |
174 | return; |
175 | } |
176 | |
177 | return $limit + $start; |
178 | } |
179 | } |