summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Field.pm
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2006-09-09 08:11:40 +0200
committerlpsolit%gmail.com <>2006-09-09 08:11:40 +0200
commita806b298f5bfe5914f27a1419d27366fe59da449 (patch)
tree25d737aeb60f17360de9a67f2017369a4d5d8349 /Bugzilla/Field.pm
parent27c1be36a3cbc57e01c8d51af85be76b0748ece6 (diff)
downloadbugzilla-a806b298f5bfe5914f27a1419d27366fe59da449.tar.gz
bugzilla-a806b298f5bfe5914f27a1419d27366fe59da449.tar.xz
Bug 287326: Ability to add custom single-select fields to a bug - Patch by Frédéric Buclin <LpSolit@gmail.com> and Max Kanat-Alexander <mkanat@bugzilla.org> r=mkanat a=myk
Diffstat (limited to 'Bugzilla/Field.pm')
-rw-r--r--Bugzilla/Field.pm84
1 files changed, 70 insertions, 14 deletions
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<legal_values>
+
+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<match($criteria)>
+=item C<match>
+
+=over
+
+=item B<Description>
-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<Bugzilla/get_fields> and
+L<Bugzilla/get_custom_field_names> instead of this function.
- Note: Bugzilla->get_fields() and Bugzilla->custom_field_names
- wrap this method for most callers.
+=item B<Params>
-Returns: A reference to an array of C<Bugzilla::Field> objects.
+Takes named parameters in a hashref:
+
+=over
+
+=item C<name> - The name of the field.
+
+=item C<custom> - Boolean. True to only return custom fields. False
+to only return non-custom fields.
+
+=item C<obsolete> - Boolean. True to only return obsolete fields.
+False to not return obsolete fields.
+
+=item C<type> - The type of the field. A C<FIELD_TYPE> constant from
+L<Bugzilla::Constants>.
+
+=item C<enter_bug> - Boolean. True to only return fields that appear
+on F<enter_bug.cgi>. False to only return fields that I<don't> appear
+on F<enter_bug.cgi>.
+
+=back
+
+=item B<Returns>
+
+A reference to an array of C<Bugzilla::Field> 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 => {}});