From a806b298f5bfe5914f27a1419d27366fe59da449 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Sat, 9 Sep 2006 06:11:40 +0000 Subject: Bug 287326: Ability to add custom single-select fields to a bug - Patch by Frédéric Buclin and Max Kanat-Alexander r=mkanat a=myk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bugzilla/Field.pm | 84 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 14 deletions(-) (limited to 'Bugzilla/Field.pm') diff --git a/Bugzilla/Field.pm b/Bugzilla/Field.pm index 870e93221..2dfd8aa6e 100644 --- a/Bugzilla/Field.pm +++ b/Bugzilla/Field.pm @@ -103,7 +103,9 @@ use constant DB_COLUMNS => ( use constant SQL_DEFINITIONS => { # Using commas because these are constants and they shouldn't # be auto-quoted by the "=>" operator. - FIELD_TYPE_FREETEXT, { TYPE => 'varchar(255)' }, + FIELD_TYPE_FREETEXT, { TYPE => 'varchar(255)' }, + FIELD_TYPE_SINGLE_SELECT, { TYPE => 'varchar(64)', NOTNULL => 1, + DEFAULT => "'---'" }, }; # Field definitions for the fields that ship with Bugzilla. @@ -266,6 +268,24 @@ enter_bug.cgi sub enter_bug { return $_[0]->{enter_bug} } +=over + +=item C + +A reference to an array with valid active values for this field. + +=back + +=cut + +sub legal_values { + my $self = shift; + + if (!defined $self->{'legal_values'}) { + $self->{'legal_values'} = get_legal_field_values($self->name); + } + return $self->{'legal_values'}; +} =pod @@ -305,9 +325,7 @@ sub create_or_update { my $name = $params->{name}; my $custom = $params->{custom} ? 1 : 0; my $in_new_bugmail = $params->{in_new_bugmail} ? 1 : 0; - # Some day we'll allow invocants to specify the field type. - # We don't care about $params->{type} yet. - my $type = $custom ? FIELD_TYPE_FREETEXT : FIELD_TYPE_UNKNOWN; + my $type = $params->{type} || FIELD_TYPE_UNKNOWN; my $field = new Bugzilla::Field({name => $name}); if ($field) { @@ -353,6 +371,15 @@ sub create_or_update { $dbh->bz_add_column('bugs', $name, SQL_DEFINITIONS->{$type}); } + if ($custom && !$dbh->bz_table_info($name) + && $type eq FIELD_TYPE_SINGLE_SELECT) + { + # Create the table that holds the legal values for this field. + $dbh->bz_add_field_table($name); + # And insert a default value of "---" into it. + $dbh->do("INSERT INTO $name (value) VALUES ('---')"); + } + return new Bugzilla::Field({name => $name}); } @@ -361,19 +388,45 @@ sub create_or_update { =over -=item C +=item C + +=over + +=item B -Description: returns a list of fields that match the specified criteria. +Returns a list of fields that match the specified criteria. -Params: C<$criteria> - hash reference - the criteria to match against. - Hash keys represent field properties; hash values represent - their values. All criteria are optional. Valid criteria are - "custom" and "obsolete", and both take boolean values. +You should be using L and +L instead of this function. - Note: Bugzilla->get_fields() and Bugzilla->custom_field_names - wrap this method for most callers. +=item B -Returns: A reference to an array of C objects. +Takes named parameters in a hashref: + +=over + +=item C - The name of the field. + +=item C - Boolean. True to only return custom fields. False +to only return non-custom fields. + +=item C - Boolean. True to only return obsolete fields. +False to not return obsolete fields. + +=item C - The type of the field. A C constant from +L. + +=item C - Boolean. True to only return fields that appear +on F. False to only return fields that I appear +on F. + +=back + +=item B + +A reference to an array of C objects. + +=back =back @@ -395,8 +448,11 @@ sub match { if (defined $criteria->{enter_bug}) { push(@terms, "enter_bug=" . ($criteria->{enter_bug} ? '1' : '0')); } + if (defined $criteria->{type}) { + push(@terms, "type = " . $criteria->{type}); + } my $where = (scalar(@terms) > 0) ? "WHERE " . join(" AND ", @terms) : ""; - + my $ids = Bugzilla->dbh->selectcol_arrayref( "SELECT id FROM fielddefs $where", {Slice => {}}); -- cgit v1.2.3-24-g4f1b