From: lpsolit%gmail.com <> Date: Sat, 12 Apr 2008 04:43:05 +0000 (+0000) Subject: Bug 314454: Incorrect SQL query in editproducts.cgi when making a group mandatory... X-Git-Tag: bugzilla-3.0.4~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d49b3358a1dbced4a4fa6ef129bd12306c821347;p=thirdparty%2Fbugzilla.git Bug 314454: Incorrect SQL query in editproducts.cgi when making a group mandatory - Patch by Elliotte Martin r/a=LpSolit --- diff --git a/editproducts.cgi b/editproducts.cgi index 7105981200..df92187aef 100755 --- a/editproducts.cgi +++ b/editproducts.cgi @@ -26,10 +26,7 @@ # Frédéric Buclin # Greg Hendricks # Lance Larsh -# -# Direct any questions on this source code to -# -# Holger Schurig +# Elliotte Martin use strict; use lib "."; @@ -537,20 +534,28 @@ if ($action eq 'updategroupcontrols') { {'Slice' => {}}, $product->id); } +# +# return the mandatory groups which need to have bug entries added to the bug_group_map +# and the corresponding bug count +# my $mandatory_groups; if (@now_mandatory) { $mandatory_groups = $dbh->selectall_arrayref( - 'SELECT groups.name, COUNT(bugs.bug_id) AS count - FROM bugs - LEFT JOIN bug_group_map - ON bug_group_map.bug_id = bugs.bug_id - INNER JOIN groups - ON bug_group_map.group_id = groups.id - WHERE groups.id IN (' . join(', ', @now_mandatory) . ') - AND bugs.product_id = ? - AND bug_group_map.bug_id IS NULL ' . - $dbh->sql_group_by('groups.name'), + 'SELECT groups.name, + (SELECT COUNT(bugs.bug_id) + FROM bugs + WHERE bugs.product_id = ? + AND bugs.bug_id NOT IN + (SELECT bug_group_map.bug_id FROM bug_group_map + WHERE bug_group_map.group_id = groups.id)) + AS count + FROM groups + WHERE groups.id IN (' . join(', ', @now_mandatory) . ') + ORDER BY groups.name', {'Slice' => {}}, $product->id); + # remove zero counts + @$mandatory_groups = grep { $_->{count} } @$mandatory_groups; + } if (($na_groups && scalar(@$na_groups)) || ($mandatory_groups && scalar(@$mandatory_groups)))