From 0d2869cdc8bf59db57e80e7e3a0c0c377fc0ffb5 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Sun, 18 Jun 2006 06:12:35 +0000 Subject: Bug 338796: Remove get_product_* from globals.pl - Patch by Frédéric Buclin r=wicked a=justdave MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- editflagtypes.cgi | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'editflagtypes.cgi') diff --git a/editflagtypes.cgi b/editflagtypes.cgi index 822f00744..e055e9d9d 100755 --- a/editflagtypes.cgi +++ b/editflagtypes.cgi @@ -278,15 +278,20 @@ sub processCategoryChange { sub clusion_array_to_hash { my $array = shift; my %hash; + my %products; my %components; foreach my $ids (@$array) { trick_taint($ids); my ($product_id, $component_id) = split(":", $ids); - my $product_name = get_product_name($product_id) || "__Any__"; + my $product_name = "__Any__"; + if ($product_id) { + $products{$product_id} ||= new Bugzilla::Product($product_id); + $product_name = $products{$product_id}->name if $products{$product_id}; + } my $component_name = "__Any__"; if ($component_id) { $components{$component_id} ||= new Bugzilla::Component($component_id); - $component_name = $components{$component_id}->name; + $component_name = $components{$component_id}->name if $components{$component_id}; } $hash{"$product_name:$component_name"} = $ids; } @@ -656,6 +661,8 @@ sub validateAndSubmit { my ($id) = @_; my $dbh = Bugzilla->dbh; + # Cache product objects. + my %products; foreach my $category_type ("inclusions", "exclusions") { # Will be used several times below. my $sth = $dbh->prepare("INSERT INTO flag$category_type " . @@ -666,15 +673,18 @@ sub validateAndSubmit { foreach my $category ($cgi->param($category_type)) { trick_taint($category); my ($product_id, $component_id) = split(":", $category); - # The product does not exist. - next if ($product_id && !get_product_name($product_id)); + # Does the product exist? + if ($product_id) { + $products{$product_id} ||= new Bugzilla::Product($product_id); + next unless defined $products{$product_id}; + } # A component was selected without a product being selected. next if (!$product_id && $component_id); - # The component does not belong to this product. - next if ($component_id - && !$dbh->selectrow_array("SELECT id FROM components - WHERE id = ? AND product_id = ?", - undef, ($component_id, $product_id))); + # Does the component belong to this product? + if ($component_id) { + my @match = grep {$_->id == $component_id} @{$products{$product_id}->components}; + next unless scalar(@match); + } $product_id ||= undef; $component_id ||= undef; $sth->execute($id, $product_id, $component_id); -- cgit v1.2.3-24-g4f1b