[ticket/9687] Properly display error messages in ACP

PHPBB3-9687
This commit is contained in:
Marc Alexander 2023-07-29 23:10:51 +02:00
parent 1a4e6fe3e8
commit 872439b8f4
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
6 changed files with 38 additions and 26 deletions

View file

@ -103,7 +103,14 @@ class acp_ban
$ban_end = $ban_manager->get_ban_end($ban_start, $ban_length, $ban_length_other);
$ban = explode("\n", $ban);
$ban_manager->ban($mode, $ban, $ban_start, $ban_end, $ban_reason, $ban_give_reason);
try
{
$ban_manager->ban($mode, $ban, $ban_start, $ban_end, $ban_reason, $ban_give_reason);
}
catch (\phpbb\exception\exception_interface $exception)
{
trigger_error($language->lang_array($exception->getMessage(), $exception->get_parameters()), E_USER_WARNING);
}
/**
* Use this event to perform actions after the ban has been performed

View file

@ -79,14 +79,14 @@ class manager
{
if ($start > $end && $end->getTimestamp() !== 0)
{
throw new invalid_length_exception(); // TODO
throw new invalid_length_exception('LENGTH_BAN_INVALID');
}
/** @var type_interface $ban_mode */
$ban_mode = $this->find_type($mode);
if ($ban_mode === false)
{
throw new type_not_found_exception(); // TODO
throw new type_not_found_exception();
}
if (!empty($this->user))
@ -154,31 +154,36 @@ class manager
$ban_mode = $this->find_type($mode);
if ($ban_mode === false)
{
throw new type_not_found_exception(); // TODO
throw new type_not_found_exception();
}
$this->tidy();
$sql_ids = array_map('intval', $items);
$sql = 'SELECT ban_item
FROM ' . $this->bans_table . '
WHERE ' . $this->db->sql_in_set('ban_id', $sql_ids); // TODO (what if empty?)
$result = $this->db->sql_query($sql);
$unbanned_items = [];
while ($row = $this->db->sql_fetchrow($result))
if (count($sql_ids))
{
$unbanned_items[] = $row['ban_item'];
$sql = 'SELECT ban_item
FROM ' . $this->bans_table . '
WHERE ' . $this->db->sql_in_set('ban_id', $sql_ids);
$result = $this->db->sql_query($sql);
$unbanned_items = [];
while ($row = $this->db->sql_fetchrow($result))
{
$unbanned_items[] = $row['ban_item'];
}
$this->db->sql_freeresult($result);
$sql = 'DELETE FROM ' . $this->bans_table . '
WHERE ' . $this->db->sql_in_set('ban_id', $sql_ids);
$this->db->sql_query($sql);
$unban_data = [
'items' => $unbanned_items,
];
$unbanned_users = $ban_mode->after_unban($unban_data);
// @todo: add logging for unbanned users
}
$this->db->sql_freeresult($result);
$sql = 'DELETE FROM ' . $this->bans_table . '
WHERE ' . $this->db->sql_in_set('ban_id', $sql_ids);
$this->db->sql_query($sql);
$unban_data = [
'items' => $unbanned_items,
];
$unbanned_users = $ban_mode->after_unban($unban_data);
$this->cache->destroy(self::CACHE_KEY_INFO);
$this->cache->destroy(self::CACHE_KEY_USERS);
@ -389,7 +394,7 @@ class manager
}
else
{
throw new invalid_length_exception();
throw new invalid_length_exception('LENGTH_BAN_INVALID');
}
}
}

View file

@ -56,7 +56,7 @@ class email extends base
if (empty($ban_items))
{
throw new no_valid_emails_exception(); // TODO
throw new no_valid_emails_exception('NO_EMAILS_DEFINED');
}
return $ban_items;

View file

@ -85,7 +85,7 @@ class ip extends base
if (empty($ban_items))
{
throw new no_valid_ips_exception(); // TODO
throw new no_valid_ips_exception('NO_IPS_DEFINED');
}
return $ban_items;

View file

@ -147,7 +147,7 @@ class user extends base
if (empty($ban_items))
{
throw new no_valid_users_exception(); // TODO
throw new no_valid_users_exception('NO_USER_SPECIFIED');
}
return $ban_items;

View file

@ -1136,7 +1136,7 @@ class session
*/
function check_ban($user_id = false, $user_ips = false, $user_email = false, $return = false)
{
global $db, $phpbb_container, $phpbb_dispatcher;
global $phpbb_container, $phpbb_dispatcher;
if (defined('IN_CHECK_BAN') || defined('SKIP_CHECK_BAN'))
{