diff --git a/phpBB/phpbb/ban/manager.php b/phpBB/phpbb/ban/manager.php
index ed05ccafd8..3fed881bf4 100644
--- a/phpBB/phpbb/ban/manager.php
+++ b/phpBB/phpbb/ban/manager.php
@@ -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()}'"],
],
];
diff --git a/phpBB/phpbb/ban/type/user.php b/phpBB/phpbb/ban/type/user.php
index 7dadbf2e43..7ad1195988 100644
--- a/phpBB/phpbb/ban/type/user.php
+++ b/phpBB/phpbb/ban/type/user.php
@@ -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;
}
diff --git a/phpBB/phpbb/db/migration/data/v400/ban_table_p1.php b/phpBB/phpbb/db/migration/data/v400/ban_table_p1.php
index e837a1cf95..f58dff52e3 100644
--- a/phpBB/phpbb/db/migration/data/v400/ban_table_p1.php
+++ b/phpBB/phpbb/db/migration/data/v400/ban_table_p1.php
@@ -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'],
diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php
index bf7402cb6a..e9011ae304 100644
--- a/phpBB/phpbb/session.php
+++ b/phpBB/phpbb/session.php
@@ -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, '', '');
- $message .= ($ban_row['reason']) ? '
' . sprintf($this->lang['BOARD_BAN_REASON'], $ban_row['reason']) : '';
- $message .= '
' . $this->lang['BAN_TRIGGERED_BY_' . strtoupper($ban_triggered_by)] . '';
+ $message .= ($ban_row['reason']) ? '
' . sprintf($this->lang['BOARD_BAN_REASON'], $ban_row['reason']) : '';
+ $message .= '
' . $this->lang['BAN_TRIGGERED_BY_' . strtoupper($ban_triggered_by)] . '';
// 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'))
diff --git a/tests/ban/ban_manager_test.php b/tests/ban/ban_manager_test.php
index 86a770324d..b8af909c7d 100644
--- a/tests/ban/ban_manager_test.php
+++ b/tests/ban/ban_manager_test.php
@@ -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',
diff --git a/tests/ban/fixtures/sessions_banlist.xml b/tests/ban/fixtures/sessions_banlist.xml
index 38f6c41e26..39253d2681 100644
--- a/tests/ban/fixtures/sessions_banlist.xml
+++ b/tests/ban/fixtures/sessions_banlist.xml
@@ -70,6 +70,7 @@