From d8f36cac89e6e054e884cbf54fbe130ec7424f9e Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Tue, 30 May 2006 00:24:53 +0000 Subject: Bug 337054: Remove get_component_id() and get_component_name() from globals.pl - Patch by Frédéric Buclin r=mkanat a=myk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- editflagtypes.cgi | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'editflagtypes.cgi') diff --git a/editflagtypes.cgi b/editflagtypes.cgi index bcab4e189..8f6bf601f 100755 --- a/editflagtypes.cgi +++ b/editflagtypes.cgi @@ -19,6 +19,7 @@ # Rights Reserved. # # Contributor(s): Myk Melez +# Frédéric Buclin ################################################################################ # Script Initialization @@ -39,6 +40,7 @@ use Bugzilla::FlagType; use Bugzilla::Group; use Bugzilla::Util; use Bugzilla::Product; +use Bugzilla::Component; my $template = Bugzilla->template; my $vars = {}; @@ -51,8 +53,6 @@ $user->in_group('editcomponents') object => "flagtypes"}); my $cgi = Bugzilla->cgi; -my $product_id; -my $component_id; ################################################################################ # Main Body Execution @@ -190,15 +190,17 @@ sub processCategoryChange { my @inclusions = $cgi->param('inclusions'); my @exclusions = $cgi->param('exclusions'); if ($categoryAction eq 'include') { - validateProduct(); - validateComponent(); - my $category = ($product_id || 0) . ":" . ($component_id || 0); + my $product = validateProduct(scalar $cgi->param('product')); + my $component = validateComponent($product, scalar $cgi->param('component')); + my $category = ($product ? $product->id : 0) . ":" . + ($component ? $component->id : 0); push(@inclusions, $category) unless grep($_ eq $category, @inclusions); } elsif ($categoryAction eq 'exclude') { - validateProduct(); - validateComponent(); - my $category = ($product_id || 0) . ":" . ($component_id || 0); + my $product = validateProduct(scalar $cgi->param('product')); + my $component = validateComponent($product, scalar $cgi->param('component')); + my $category = ($product ? $product->id : 0) . ":" . + ($component ? $component->id : 0); push(@exclusions, $category) unless grep($_ eq $category, @exclusions); } elsif ($categoryAction eq 'removeInclusion') { @@ -249,11 +251,16 @@ sub processCategoryChange { sub clusion_array_to_hash { my $array = shift; my %hash; + 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 $component_name = get_component_name($component_id) || "__Any__"; + my $component_name = "__Any__"; + if ($component_id) { + $components{$component_id} ||= new Bugzilla::Component($component_id); + $component_name = $components{$component_id}->name; + } $hash{"$product_name:$component_name"} = $ids; } return %hash; @@ -531,27 +538,22 @@ sub validateCCList { } sub validateProduct { - return if !$cgi->param('product'); - - $product_id = get_product_id($cgi->param('product')); - - defined($product_id) - || ThrowCodeError("flag_type_product_nonexistent", - { product => $cgi->param('product') }); + my $product_name = shift; + return unless $product_name; + + my $product = Bugzilla::Product::check_product($product_name); + return $product; } sub validateComponent { - return if !$cgi->param('component'); - - $product_id + my ($product, $component_name) = @_; + return unless $component_name; + + ($product && $product->id) || ThrowCodeError("flag_type_component_without_product"); - - $component_id = get_component_id($product_id, $cgi->param('component')); - defined($component_id) - || ThrowCodeError("flag_type_component_nonexistent", - { product => $cgi->param('product'), - name => $cgi->param('component') }); + my $component = Bugzilla::Component::check_component($product, $component_name); + return $component; } sub validateSortKey { -- cgit v1.2.3-24-g4f1b