diff options
-rw-r--r-- | phpBB/includes/functions_privmsgs.php | 25 | ||||
-rw-r--r-- | tests/functions_privmsgs/fixtures/get_max_setting_from_group.xml | 21 | ||||
-rw-r--r-- | tests/functions_privmsgs/get_max_setting_from_group_test.php | 4 |
3 files changed, 30 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; } /** diff --git a/tests/functions_privmsgs/fixtures/get_max_setting_from_group.xml b/tests/functions_privmsgs/fixtures/get_max_setting_from_group.xml index b10bf782ec..c78d63f7cb 100644 --- a/tests/functions_privmsgs/fixtures/get_max_setting_from_group.xml +++ b/tests/functions_privmsgs/fixtures/get_max_setting_from_group.xml @@ -23,6 +23,12 @@ <value>0</value> <value>0</value> </row> + <row> + <value>4</value> + <value></value> + <value>0</value> + <value>5</value> + </row> </table> <table name="phpbb_user_group"> <column>user_id</column> @@ -58,5 +64,20 @@ <value>3</value> <value>0</value> </row> + <row> + <value>4</value> + <value>4</value> + <value>0</value> + </row> + <row> + <value>5</value> + <value>3</value> + <value>1</value> + </row> + <row> + <value>5</value> + <value>2</value> + <value>0</value> + </row> </table> </dataset> diff --git a/tests/functions_privmsgs/get_max_setting_from_group_test.php b/tests/functions_privmsgs/get_max_setting_from_group_test.php index 48d42ec48a..3eb7866802 100644 --- a/tests/functions_privmsgs/get_max_setting_from_group_test.php +++ b/tests/functions_privmsgs/get_max_setting_from_group_test.php @@ -36,9 +36,13 @@ class phpbb_functions_privmsgs_get_max_setting_from_group_test extends phpbb_dat array(1, 0, 'message_limit'), array(2, 2, 'message_limit'), array(3, 0, 'message_limit'), + array(4, 0, 'message_limit'), + array(5, 2, 'message_limit'), array(1, 0, 'max_recipients'), array(2, 4, 'max_recipients'), array(3, 0, 'max_recipients'), + array(4, 5, 'max_recipients'), + array(5, 4, 'max_recipients'), ); } |