From 80130158d4f4baa47cf1212cf28da1dc84b9d096 Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Fri, 14 May 2010 07:20:05 -0700 Subject: Bug 556731 - Make Bugzilla::Milestone, Bugzilla::Version, and Bugzilla::Component use VALIDATOR_DEPENDENCIES instead of UPDATE_VALIDATORS r=LpSolit, a=LpSolit --- Bugzilla/Component.pm | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'Bugzilla/Component.pm') diff --git a/Bugzilla/Component.pm b/Bugzilla/Component.pm index 5fb911031..a1f5144e5 100644 --- a/Bugzilla/Component.pm +++ b/Bugzilla/Component.pm @@ -28,6 +28,8 @@ use Bugzilla::User; use Bugzilla::FlagType; use Bugzilla::Series; +use Scalar::Util qw(blessed); + ############################### #### Initialization #### ############################### @@ -66,10 +68,11 @@ use constant VALIDATORS => { initialqacontact => \&_check_initialqacontact, description => \&_check_description, initial_cc => \&_check_cc_list, + name => \&_check_name, }; -use constant UPDATE_VALIDATORS => { - name => \&_check_name, +use constant VALIDATOR_DEPENDENCIES => { + name => ['product'], }; ############################### @@ -116,8 +119,11 @@ sub create { my $params = $class->run_create_validators(@_); my $cc_list = delete $params->{initial_cc}; my $create_series = delete $params->{create_series}; + my $product = delete $params->{product}; + $params->{product_id} = $product->id; my $component = $class->insert_create_data($params); + $component->{product} = $product; # We still have to fill the component_cc table. $component->_update_cc_list($cc_list) if $cc_list; @@ -129,17 +135,6 @@ sub create { return $component; } -sub run_create_validators { - my $class = shift; - my $params = $class->SUPER::run_create_validators(@_); - - my $product = delete $params->{product}; - $params->{product_id} = $product->id; - $params->{name} = $class->_check_name($params->{name}, $product); - - return $params; -} - sub update { my $self = shift; my $changes = $self->SUPER::update(@_); @@ -190,7 +185,8 @@ sub remove_from_db { ################################ sub _check_name { - my ($invocant, $name, $product) = @_; + my ($invocant, $name, undef, $params) = @_; + my $product = blessed($invocant) ? $invocant->product : $params->{product}; $name = trim($name); $name || ThrowUserError('component_blank_name'); @@ -199,7 +195,6 @@ sub _check_name { ThrowUserError('component_name_too_long', {'name' => $name}); } - $product = $invocant->product if (ref $invocant); my $component = new Bugzilla::Component({product => $product, name => $name}); if ($component && (!ref $invocant || $component->id != $invocant->id)) { ThrowUserError('component_already_exists', { name => $component->name, -- cgit v1.2.3-24-g4f1b