mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/9687] Update deprecated notices and helper functions
PHPBB3-9687
This commit is contained in:
parent
8e80d734c8
commit
8a15670055
5 changed files with 104 additions and 20 deletions
|
@ -915,7 +915,7 @@ function user_active_flip($mode, $user_id_ary, $reason = INACTIVE_MANUAL)
|
|||
/**
|
||||
* Add a ban or ban exclusion to the banlist. Bans either a user, an IP or an email address
|
||||
*
|
||||
* @deprecated 3.3.0-a1 (To be removed: 4.0.0)
|
||||
* @deprecated 4.0.0-a1 (To be removed: 4.1.0)
|
||||
*
|
||||
* @param string $mode Type of ban. One of the following: user, ip, email
|
||||
* @param mixed $ban Banned entity. Either string or array with usernames, ips or email addresses
|
||||
|
@ -970,14 +970,12 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_reason, $ban_give_
|
|||
$end->setTimestamp($ban_end);
|
||||
|
||||
return $ban_manager->ban($mode, $items, $start, $end, $ban_reason, $ban_give_reason);
|
||||
|
||||
// TODO: logging
|
||||
}
|
||||
|
||||
/**
|
||||
* Unban User
|
||||
*
|
||||
* @deprecated 3.3.0-a1 (To be removed: 4.0.0)
|
||||
* @deprecated 4.0.0-a1 (To be removed: 4.1.0)
|
||||
*/
|
||||
function user_unban($mode, $ban)
|
||||
{
|
||||
|
@ -3254,8 +3252,6 @@ function remove_newly_registered($user_id, $user_data = false)
|
|||
/**
|
||||
* Gets user ids of currently banned registered users.
|
||||
*
|
||||
* @deprecated 3.3.0-a1 (To be removed: 4.0.0)
|
||||
*
|
||||
* @param array $user_ids Array of users' ids to check for banning,
|
||||
* leave empty to get complete list of banned ids
|
||||
* @param bool|int $ban_end Bool True to get users currently banned
|
||||
|
@ -3283,10 +3279,21 @@ function phpbb_get_banned_user_ids($user_ids = array(), $ban_end = true)
|
|||
return $end <= 0 || $end > (int) $ban_end;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
$banned_users = array_filter($banned_users, function ($end) {
|
||||
return $end <= 0 || $end > time();
|
||||
});
|
||||
}
|
||||
|
||||
$result_array = [];
|
||||
foreach ($banned_users as $user_id => $_)
|
||||
{
|
||||
if (count($user_ids) && !in_array($user_id, $user_ids))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$result_array[$user_id] = $user_id;
|
||||
}
|
||||
|
||||
|
|
|
@ -417,9 +417,7 @@ class manager
|
|||
$this->cache->put(self::CACHE_KEY_USERS, $banned_users, self::CACHE_TTL);
|
||||
}
|
||||
|
||||
return array_filter($banned_users, function ($end) {
|
||||
return $end <= 0 || $end > time();
|
||||
});
|
||||
return $banned_users;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -403,6 +403,7 @@ class ban_manager_test extends \phpbb_session_test_case
|
|||
[
|
||||
4 => 0,
|
||||
5 => 0,
|
||||
19 => 1234,
|
||||
20 => 0,
|
||||
],
|
||||
$ban_manager->get_banned_users()
|
||||
|
|
|
@ -2,27 +2,68 @@
|
|||
<dataset>
|
||||
<table name="phpbb_bans">
|
||||
<column>ban_userid</column>
|
||||
<column>ban_mode</column>
|
||||
<column>ban_end</column>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>0</value>
|
||||
<value>user</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>user</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>4</value>
|
||||
<value>user</value>
|
||||
<value>2</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>5</value>
|
||||
<value>999999999999999999999</value>
|
||||
<value>user</value>
|
||||
<value>2147485547</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>6</value>
|
||||
<value>user</value>
|
||||
<value>3</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_users">
|
||||
<column>user_id</column>
|
||||
<column>username_clean</column>
|
||||
<column>user_permissions</column>
|
||||
<column>user_sig</column>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>admin</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>user3</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>4</value>
|
||||
<value>user4</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>5</value>
|
||||
<value>user5</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>6</value>
|
||||
<value>user6</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
||||
|
|
|
@ -20,6 +20,47 @@ class phpbb_get_banned_user_ids_test extends phpbb_database_test_case
|
|||
return $this->createXMLDataSet(__DIR__ . '/fixtures/banned_users.xml');
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
global $db, $phpbb_container, $phpbb_root_path, $phpEx;
|
||||
|
||||
$db = $this->new_dbal();
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$phpbb_container = new phpbb_mock_container_builder();
|
||||
$config = new \phpbb\config\config([]);
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||
$language = new phpbb\language\language(new phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
|
||||
$user = new phpbb\user($language, '\phpbb\datetime');
|
||||
$user->data['user_email'] = '';
|
||||
|
||||
$cache = new \phpbb\cache\service(
|
||||
new \phpbb\cache\driver\dummy(),
|
||||
$config,
|
||||
$db,
|
||||
$phpbb_dispatcher,
|
||||
$phpbb_root_path,
|
||||
$phpEx
|
||||
);
|
||||
$cache->get_driver()->purge();
|
||||
|
||||
$ban_type_email = new \phpbb\ban\type\email($db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
|
||||
$ban_type_user = new \phpbb\ban\type\user($db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
|
||||
$ban_type_ip = new \phpbb\ban\type\ip($db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
|
||||
$phpbb_container->set('ban.type.email', $ban_type_email);
|
||||
$phpbb_container->set('ban.type.user', $ban_type_user);
|
||||
$phpbb_container->set('ban.type.ip', $ban_type_ip);
|
||||
$collection = new \phpbb\di\service_collection($phpbb_container);
|
||||
$collection->add('ban.type.email');
|
||||
$collection->add('ban.type.user');
|
||||
$collection->add('ban.type.ip');
|
||||
$phpbb_log = new \phpbb\log\dummy();
|
||||
|
||||
$ban_manager = new \phpbb\ban\manager($collection, $cache->get_driver(), $db, $language, $phpbb_log, $user, 'phpbb_bans', 'phpbb_users');
|
||||
$phpbb_container->set('ban.manager', $ban_manager);
|
||||
}
|
||||
|
||||
public function phpbb_get_banned_user_ids_data()
|
||||
{
|
||||
return array(
|
||||
|
@ -35,6 +76,11 @@ class phpbb_get_banned_user_ids_test extends phpbb_database_test_case
|
|||
array(array(1, 2, 4, 5, 6), false),
|
||||
array(2 => 2),
|
||||
),
|
||||
array(
|
||||
// True to get users currently banned, but should only return passed user IDs
|
||||
array(array(5, 6, 7), true),
|
||||
array(5 => 5),
|
||||
),
|
||||
array(
|
||||
// Unix timestamp to get users banned until that time
|
||||
array(array(1, 2, 4, 5, 6), 2),
|
||||
|
@ -43,15 +89,6 @@ class phpbb_get_banned_user_ids_test extends phpbb_database_test_case
|
|||
);
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
global $db;
|
||||
|
||||
$db = $this->new_dbal();
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider phpbb_get_banned_user_ids_data
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue