diff options
author | Marc Alexander <admin@m-a-styles.de> | 2015-02-03 23:13:37 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2015-02-08 21:16:05 +0100 |
commit | 5cc0488f74633a9f28011ed935a3b7e902ba4497 (patch) | |
tree | 0a12336f9cc64e7e408be1ea2f5148490f967096 /phpBB/includes/functions_privmsgs.php | |
parent | 291143fe6a821a07f8097e26e38f69efa3c84848 (diff) | |
download | forums-5cc0488f74633a9f28011ed935a3b7e902ba4497.tar forums-5cc0488f74633a9f28011ed935a3b7e902ba4497.tar.gz forums-5cc0488f74633a9f28011ed935a3b7e902ba4497.tar.bz2 forums-5cc0488f74633a9f28011ed935a3b7e902ba4497.tar.xz forums-5cc0488f74633a9f28011ed935a3b7e902ba4497.zip |
[ticket/9109] Only query database once in phpbb_get_max_setting_from_group
More test cases have been added, too.
PHPBB3-9109
Diffstat (limited to 'phpBB/includes/functions_privmsgs.php')
-rw-r--r-- | phpBB/includes/functions_privmsgs.php | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index ef6532f59d..10a1b8d4ad 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -2162,33 +2162,18 @@ function phpbb_get_max_setting_from_group(\phpbb\db\driver\driver_interface $db, } // Get maximum number of allowed recipients - $sql = 'SELECT MAX(g.group_' . $setting . ') as max_setting + $sql = 'SELECT MIN(g.group_' . $setting . ') as min_setting, MAX(g.group_' . $setting . ') as max_setting FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug WHERE ug.user_id = ' . (int) $user_id . ' AND ug.user_pending = 0 AND ug.group_id = g.group_id'; $result = $db->sql_query($sql); - $max_setting = (int) $db->sql_fetchfield('max_setting'); + $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); + $max_setting = (int) $row['max_setting']; + $min_setting = (int) $row['min_setting']; - if ($max_setting) - { - // If the user is limited by a group, check whether he is also set to - // unlimited in another group (value 0) - $sql = 'SELECT g.group_' . $setting . ' as max_setting - FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug - WHERE ug.user_id = ' . (int) $user_id . ' - AND ug.user_pending = 0 - AND ug.group_id = g.group_id - AND g.group_max_recipients = 0'; - $result = $db->sql_query($sql); - $is_unlimited = $db->sql_fetchfield('max_setting'); - $db->sql_freeresult($result); - - $max_setting = ($is_unlimited === false) ? $max_setting : 0; - } - - return $max_setting; + return ($min_setting > 0) ? $max_setting : 0; } /** |