mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/9687] Add separate column for user_id
PHPBB3-9687
This commit is contained in:
parent
f9a0e4d606
commit
0414536727
6 changed files with 34 additions and 29 deletions
|
@ -307,9 +307,12 @@ class manager
|
|||
$manual_modes[] = $ban_mode;
|
||||
continue;
|
||||
}
|
||||
|
||||
$where_column = $user_column == 'user_id' ? 'b.ban_userid' : 'b.ban_item';
|
||||
|
||||
$where_array[] = ['AND',
|
||||
[
|
||||
['b.ban_item', '=', 'u.' . $user_column],
|
||||
[$where_column, '=', 'u.' . $user_column],
|
||||
['b.ban_mode', '=', "'{$ban_mode->get_type()}'"],
|
||||
],
|
||||
];
|
||||
|
|
|
@ -73,40 +73,21 @@ class user extends base
|
|||
public function get_ban_options(): array
|
||||
{
|
||||
$ban_options = [];
|
||||
$ban_data = [];
|
||||
$user_ids = [];
|
||||
|
||||
$sql = 'SELECT b.*
|
||||
FROM ' . $this->bans_table . ' b
|
||||
$sql = 'SELECT b.*, u.user_id, u.username, u.username_clean
|
||||
FROM ' . $this->bans_table . ' b, ' . $this->users_table . ' u
|
||||
WHERE (b.ban_end >= ' . time() . "
|
||||
OR b.ban_end = 0)
|
||||
AND b.ban_mode = '{$this->get_type()}'";
|
||||
AND b.ban_userid = u.user_id
|
||||
AND b.ban_mode = '{$this->get_type()}'
|
||||
ORDER BY username_clean";
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$user_ids[] = $row['ban_item'];
|
||||
$ban_data[$row['ban_item']] = $row;
|
||||
$ban_options[] = $row;
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (count($user_ids))
|
||||
{
|
||||
// Grab usernames for banned user IDs
|
||||
$sql = 'SELECT user_id, username, username_clean
|
||||
FROM ' . $this->users_table . '
|
||||
WHERE ' . $this->db->sql_in_set('user_id', $user_ids) . '
|
||||
ORDER BY username_clean';
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$ban_options[] = array_merge(
|
||||
$ban_data[$row['user_id']],
|
||||
$row
|
||||
);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
return $ban_options;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ class ban_table_p1 extends migration
|
|||
$this->table_prefix . 'bans' => [
|
||||
'COLUMNS' => [
|
||||
'ban_id' => ['ULINT', null, 'auto_increment'],
|
||||
'ban_userid' => ['ULINT', 0],
|
||||
'ban_mode' => ['VCHAR', ''],
|
||||
'ban_item' => ['STEXT_UNI', ''],
|
||||
'ban_start' => ['TIMESTAMP', 0],
|
||||
|
@ -38,6 +39,7 @@ class ban_table_p1 extends migration
|
|||
],
|
||||
'PRIMARY_KEY' => 'ban_id',
|
||||
'KEYS' => [
|
||||
'ban_userid' => ['INDEX', 'ban_userid'],
|
||||
'ban_end' => ['INDEX', 'ban_end'],
|
||||
],
|
||||
],
|
||||
|
@ -113,6 +115,7 @@ class ban_table_p1 extends migration
|
|||
|
||||
$bans[] = [
|
||||
'ban_mode' => $mode,
|
||||
'ban_userid' => $row['ban_userid'],
|
||||
'ban_item' => $item,
|
||||
'ban_start' => $row['ban_start'],
|
||||
'ban_end' => $row['ban_end'],
|
||||
|
@ -150,7 +153,7 @@ class ban_table_p1 extends migration
|
|||
$processed_rows++;
|
||||
|
||||
$bans[] = [
|
||||
'ban_userid' => ($row['ban_mode'] === 'user') ? (int) $row['ban_item'] : 0,
|
||||
'ban_userid' => (int) $row['ban_userid'],
|
||||
'ban_ip' => ($row['ban_mode'] === 'ip') ? $row['ban_item'] : '',
|
||||
'ban_email' => ($row['ban_mode'] === 'email') ? $row['ban_item'] : '',
|
||||
'ban_start' => $row['ban_start'],
|
||||
|
|
|
@ -1209,8 +1209,8 @@ class session
|
|||
|
||||
$contact_link = phpbb_get_board_contact_link($config, $phpbb_root_path, $phpEx);
|
||||
$message = sprintf($this->lang[$message], $till_date, '<a href="' . $contact_link . '">', '</a>');
|
||||
$message .= ($ban_row['reason']) ? '<br /><br />' . sprintf($this->lang['BOARD_BAN_REASON'], $ban_row['reason']) : '';
|
||||
$message .= '<br /><br /><em>' . $this->lang['BAN_TRIGGERED_BY_' . strtoupper($ban_triggered_by)] . '</em>';
|
||||
$message .= ($ban_row['reason']) ? '<br><br>' . sprintf($this->lang['BOARD_BAN_REASON'], $ban_row['reason']) : '';
|
||||
$message .= '<br><br><em>' . $this->lang['BAN_TRIGGERED_BY_' . strtoupper($ban_triggered_by)] . '</em>';
|
||||
|
||||
// A very special case... we are within the cron script which is not supposed to print out the ban message... show blank page
|
||||
if (defined('IN_CRON'))
|
||||
|
|
|
@ -181,6 +181,7 @@ class ban_manager_test extends \phpbb_session_test_case
|
|||
[
|
||||
[
|
||||
'ban_id' => '6',
|
||||
'ban_userid' => 0,
|
||||
'ban_item' => '10.0.0.1/28',
|
||||
'ban_start' => '1111',
|
||||
'ban_end' => '0',
|
||||
|
@ -190,6 +191,7 @@ class ban_manager_test extends \phpbb_session_test_case
|
|||
],
|
||||
[
|
||||
'ban_id' => '2',
|
||||
'ban_userid' => 0,
|
||||
'ban_item' => '127.0.0.1',
|
||||
'ban_start' => '1111',
|
||||
'ban_end' => '0',
|
||||
|
@ -199,6 +201,7 @@ class ban_manager_test extends \phpbb_session_test_case
|
|||
],
|
||||
[
|
||||
'ban_id' => '3',
|
||||
'ban_userid' => 0,
|
||||
'ban_item' => '127.1.1.1',
|
||||
'ban_start' => '1111',
|
||||
'ban_end' => '0',
|
||||
|
@ -208,6 +211,7 @@ class ban_manager_test extends \phpbb_session_test_case
|
|||
],
|
||||
[
|
||||
'ban_id' => '7',
|
||||
'ban_userid' => 0,
|
||||
'ban_item' => '2001:4860:4860::8888/12',
|
||||
'ban_start' => '1111',
|
||||
'ban_end' => '0',
|
||||
|
@ -222,6 +226,7 @@ class ban_manager_test extends \phpbb_session_test_case
|
|||
[
|
||||
[
|
||||
'ban_id' => '9',
|
||||
'ban_userid' => 0,
|
||||
'ban_item' => '*@foo.bar',
|
||||
'ban_start' => '1111',
|
||||
'ban_end' => '0',
|
||||
|
@ -231,6 +236,7 @@ class ban_manager_test extends \phpbb_session_test_case
|
|||
],
|
||||
[
|
||||
'ban_id' => '5',
|
||||
'ban_userid' => 0,
|
||||
'ban_item' => 'bar@example.org',
|
||||
'ban_start' => '1111',
|
||||
'ban_end' => '0',
|
||||
|
@ -251,6 +257,7 @@ class ban_manager_test extends \phpbb_session_test_case
|
|||
'ban_reason' => 'HAHAHA',
|
||||
'ban_reason_display' => '1',
|
||||
'ban_mode' => 'user',
|
||||
'ban_userid' => 4,
|
||||
'user_id' => '4',
|
||||
'username' => '',
|
||||
'username_clean' => 'ipv6_user',
|
||||
|
@ -621,6 +628,7 @@ class ban_manager_test extends \phpbb_session_test_case
|
|||
[
|
||||
[
|
||||
'ban_id' => '4',
|
||||
'ban_userid' => '4',
|
||||
'ban_item' => '4',
|
||||
'ban_start' => '1111',
|
||||
'ban_end' => '0',
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
</table>
|
||||
<table name="phpbb_bans">
|
||||
<column>ban_id</column>
|
||||
<column>ban_userid</column>
|
||||
<column>ban_mode</column>
|
||||
<column>ban_item</column>
|
||||
<column>ban_start</column>
|
||||
|
@ -78,6 +79,7 @@
|
|||
<column>ban_reason_display</column>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>0</value>
|
||||
<value>ip</value>
|
||||
<value>127.0.0.1</value>
|
||||
<value>1111</value>
|
||||
|
@ -87,6 +89,7 @@
|
|||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>0</value>
|
||||
<value>ip</value>
|
||||
<value>127.1.1.1</value>
|
||||
<value>1111</value>
|
||||
|
@ -96,6 +99,7 @@
|
|||
</row>
|
||||
<row>
|
||||
<value>4</value>
|
||||
<value>4</value>
|
||||
<value>user</value>
|
||||
<value>4</value>
|
||||
<value>1111</value>
|
||||
|
@ -105,6 +109,7 @@
|
|||
</row>
|
||||
<row>
|
||||
<value>5</value>
|
||||
<value>0</value>
|
||||
<value>email</value>
|
||||
<value>bar@example.org</value>
|
||||
<value>1111</value>
|
||||
|
@ -114,6 +119,7 @@
|
|||
</row>
|
||||
<row>
|
||||
<value>6</value>
|
||||
<value>0</value>
|
||||
<value>ip</value>
|
||||
<value>10.0.0.1/28</value>
|
||||
<value>1111</value>
|
||||
|
@ -123,6 +129,7 @@
|
|||
</row>
|
||||
<row>
|
||||
<value>7</value>
|
||||
<value>0</value>
|
||||
<value>ip</value>
|
||||
<value>2001:4860:4860::8888/12</value>
|
||||
<value>1111</value>
|
||||
|
@ -132,6 +139,7 @@
|
|||
</row>
|
||||
<row>
|
||||
<value>8</value>
|
||||
<value>0</value>
|
||||
<value>invalid_mode</value>
|
||||
<value>foo</value>
|
||||
<value>1111</value>
|
||||
|
@ -141,6 +149,7 @@
|
|||
</row>
|
||||
<row>
|
||||
<value>9</value>
|
||||
<value>0</value>
|
||||
<value>email</value>
|
||||
<value>*@foo.bar</value>
|
||||
<value>1111</value>
|
||||
|
@ -149,6 +158,7 @@
|
|||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>10</value>
|
||||
<value>10</value>
|
||||
<value>user</value>
|
||||
<value>3</value>
|
||||
|
|
Loading…
Add table
Reference in a new issue