]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 556731 - Make Bugzilla::Milestone, Bugzilla::Version, and
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Fri, 14 May 2010 14:20:05 +0000 (07:20 -0700)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Fri, 14 May 2010 14:20:05 +0000 (07:20 -0700)
Bugzilla::Component use VALIDATOR_DEPENDENCIES instead of UPDATE_VALIDATORS
r=LpSolit, a=LpSolit

Bugzilla/Component.pm
Bugzilla/Migrate.pm
Bugzilla/Milestone.pm
Bugzilla/Product.pm
Bugzilla/Version.pm
editmilestones.cgi
editversions.cgi

index 5fb9110318ea25e25faef21ac006bce0934b7f4f..a1f5144e5dd12fd407ac71f35af37973ec5d9703 100644 (file)
@@ -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,
index 6c353357d98843519b3eea14e129968a2690ad0c..2ae638e4fd844238c0a1743d18c35083c70b46a7 100644 (file)
@@ -654,7 +654,7 @@ sub create_legal_values {
             next if new Bugzilla::Version({ product => $prod_obj,
                                             name    => $version });
             my $created = Bugzilla::Version->create({ product => $prod_obj,
-                                                      name    => $version });
+                                                      value   => $version });
             my $field = $self->bug_fields->{version};
             print get_text('migrate_value_created', { product => $prod_obj,
                                                       field   => $field,
@@ -663,8 +663,8 @@ sub create_legal_values {
         foreach my $milestone (keys %{ $product_values{$product}->{target_milestone} }) {
             next if new Bugzilla::Milestone({ product => $prod_obj,
                                               name    => $milestone });
-            my $created = Bugzilla::Milestone->create({ product => $prod_obj,
-                                                        name => $milestone });
+            my $created = Bugzilla::Milestone->create(
+                { product => $prod_obj, value => $milestone });
             my $field = $self->bug_fields->{target_milestone};
             print get_text('migrate_value_created', { product => $prod_obj,
                                                       field   => $field,
index fc44cf1afd71940f3d0561b0468ef211cfd60dbf..fafd14ad01aeb78987873543221b0466b2e20814 100644 (file)
@@ -26,6 +26,8 @@ use Bugzilla::Constants;
 use Bugzilla::Util;
 use Bugzilla::Error;
 
+use Scalar::Util qw(blessed);
+
 ################################
 #####    Initialization    #####
 ################################
@@ -44,7 +46,7 @@ use constant DB_COLUMNS => qw(
 );
 
 use constant REQUIRED_CREATE_FIELDS => qw(
-    name
+    value
     product
 );
 
@@ -56,10 +58,11 @@ use constant UPDATE_COLUMNS => qw(
 use constant VALIDATORS => {
     product => \&_check_product,
     sortkey => \&_check_sortkey,
+    value   => \&_check_value,
 };
 
-use constant UPDATE_VALIDATORS => {
-    value => \&_check_value,
+use constant VALIDATOR_DEPENDENCIES => {
+    value => ['product'],
 };
 
 ################################
@@ -94,14 +97,10 @@ sub new {
 }
 
 sub run_create_validators {
-    my $class  = shift;
+    my $class = shift;
     my $params = $class->SUPER::run_create_validators(@_);
-
     my $product = delete $params->{product};
     $params->{product_id} = $product->id;
-    $params->{value} = $class->_check_value($params->{name}, $product);
-    delete $params->{name};
-
     return $params;
 }
 
@@ -165,7 +164,8 @@ sub remove_from_db {
 ################################
 
 sub _check_value {
-    my ($invocant, $name, $product) = @_;
+    my ($invocant, $name, undef, $params) = @_;
+    my $product = blessed($invocant) ? $invocant->product : $params->{product};
 
     $name = trim($name);
     $name || ThrowUserError('milestone_blank_name');
@@ -173,7 +173,6 @@ sub _check_value {
         ThrowUserError('milestone_name_too_long', {name => $name});
     }
 
-    $product = $invocant->product if (ref $invocant);
     my $milestone = new Bugzilla::Milestone({product => $product, name => $name});
     if ($milestone && (!ref $invocant || $milestone->id != $invocant->id)) {
         ThrowUserError('milestone_already_exists', { name    => $milestone->name,
@@ -255,7 +254,7 @@ Bugzilla::Milestone - Bugzilla product milestone class.
     my $sortkey    = $milestone->sortkey;
 
     my $milestone = Bugzilla::Milestone->create(
-        { name => $name, product => $product, sortkey => $sortkey });
+        { value => $name, product => $product, sortkey => $sortkey });
 
     $milestone->set_name($new_name);
     $milestone->set_sortkey($new_sortkey);
@@ -361,11 +360,11 @@ Milestone.pm represents a Product Milestone object.
 
 =over
 
-=item C<create({name => $name, product => $product, sortkey => $sortkey})>
+=item C<create({value => $value, product => $product, sortkey => $sortkey})>
 
  Description: Create a new milestone for the given product.
 
- Params:      $name    - name of the new milestone (string). This name
+ Params:      $value   - name of the new milestone (string). This name
                          must be unique within the product.
               $product - a Bugzilla::Product object.
               $sortkey - the sortkey of the new milestone (signed integer)
index 9416d3eef7cabd7c32e4ddf8f950c77ca9a5339d..4426dda38bc55934e2e8f777324fb95399847771 100644 (file)
@@ -101,8 +101,8 @@ sub create {
     Bugzilla->user->clear_product_cache();
 
     # Add the new version and milestone into the DB as valid values.
-    Bugzilla::Version->create({name => $version, product => $product});
-    Bugzilla::Milestone->create({ name => $product->default_milestone, 
+    Bugzilla::Version->create({ value => $version, product => $product });
+    Bugzilla::Milestone->create({ value => $product->default_milestone, 
                                   product => $product });
 
     # Create groups and series for the new product, if requested.
index 1c96003f1e69f8bd875a56c1088a0890dab3793b..e40a022c430311181cbdfa2f0c4af685830d2d12 100644 (file)
@@ -26,6 +26,8 @@ use Bugzilla::Install::Util qw(vers_cmp);
 use Bugzilla::Util;
 use Bugzilla::Error;
 
+use Scalar::Util qw(blessed);
+
 ################################
 #####   Initialization     #####
 ################################
@@ -45,7 +47,7 @@ use constant DB_COLUMNS => qw(
 );
 
 use constant REQUIRED_CREATE_FIELDS => qw(
-    name
+    value
     product
 );
 
@@ -55,10 +57,11 @@ use constant UPDATE_COLUMNS => qw(
 
 use constant VALIDATORS => {
     product => \&_check_product,
+    value   => \&_check_value,
 };
 
-use constant UPDATE_VALIDATORS => {
-    value => \&_check_value,
+use constant VALIDATOR_DEPENDENCIES => {
+    value => ['product'],
 };
 
 ################################
@@ -103,12 +106,8 @@ sub new_from_list {
 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->{value} = $class->_check_value($params->{name}, $product);
-    delete $params->{name};
-
     return $params;
 }
 
@@ -171,14 +170,14 @@ sub product {
 sub set_name { $_[0]->set('value', $_[1]); }
 
 sub _check_value {
-    my ($invocant, $name, $product) = @_;
+    my ($invocant, $name, undef, $params) = @_;
+    my $product = blessed($invocant) ? $invocant->product : $params->{product};
 
     $name = trim($name);
     $name || ThrowUserError('version_blank_name');
     # Remove unprintable characters
     $name = clean_text($name);
 
-    $product = $invocant->product if (ref $invocant);
     my $version = new Bugzilla::Version({ product => $product, name => $name });
     if ($version && (!ref $invocant || $version->id != $invocant->id)) {
         ThrowUserError('version_already_exists', { name    => $version->name,
@@ -211,7 +210,7 @@ Bugzilla::Version - Bugzilla product version class.
     my $product = $version->product;
 
     my $version = Bugzilla::Version->create(
-        { name => $name, product => $product });
+        { value => $name, product => $product });
 
     $version->set_name($new_name);
     $version->update();
index a5f0c3d637a44fa5fc9cd3e53916eb6799000f96..ff13b61145c985dde7efce8e0c6d85df4b9224a4 100755 (executable)
@@ -115,7 +115,7 @@ if ($action eq 'add') {
 
 if ($action eq 'new') {
     check_token_data($token, 'add_milestone');
-    my $milestone = Bugzilla::Milestone->create({ name    => $milestone_name,
+    my $milestone = Bugzilla::Milestone->create({ value   => $milestone_name,
                                                   product => $product,
                                                   sortkey => $sortkey });
     delete_token($token);
index 7e6b9247de7cb73adf9c1596722234aa9145da16..b4cf9febc6f8f28a9a212d42a8f85b5dc84e0eaf 100755 (executable)
@@ -120,7 +120,7 @@ if ($action eq 'add') {
 if ($action eq 'new') {
     check_token_data($token, 'add_version');
     my $version = Bugzilla::Version->create(
-        {name => $version_name, product => $product});
+        { value => $version_name, product => $product });
     delete_token($token);
 
     $vars->{'message'} = 'version_created';