Bug 287325: Ability to add custom plain-text fields to a Bug - Patch … · gzgithub/bugzilla@da9ac94 · GitHub
Skip to content

Commit da9ac94

Browse files
author
lpsolit%gmail.com
committed
Bug 287325: Ability to add custom plain-text fields to a Bug - Patch by Myk Melez <myk@mozilla.org> r=mkanat a=justdave
1 parent 7780ace commit da9ac94

17 files changed

Lines changed: 565 additions & 87 deletions

‎Bugzilla.pm‎

Lines changed: 12 additions & 0 deletions

‎Bugzilla/Bug.pm‎

Lines changed: 77 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -69,41 +69,6 @@ use constant MAX_COMMENT_LENGTH => 65535;
6969

7070
#####################################################################
7171

72-
sub fields {
73-
# Keep this ordering in sync with bugzilla.dtd
74-
my @fields = qw(bug_id alias creation_ts short_desc delta_ts
75-
reporter_accessible cclist_accessible
76-
classification_id classification
77-
product component version rep_platform op_sys
78-
bug_status resolution
79-
bug_file_loc status_whiteboard keywords
80-
priority bug_severity target_milestone
81-
dependson blocked votes everconfirmed
82-
reporter assigned_to cc
83-
);
84-
85-
if (Param('useqacontact')) {
86-
push @fields, "qa_contact";
87-
}
88-
89-
if (Param('timetrackinggroup')) {
90-
push @fields, qw(estimated_time remaining_time actual_time deadline);
91-
}
92-
93-
return @fields;
94-
}
95-
96-
my %ok_field;
97-
foreach my $key (qw(error groups
98-
longdescs milestoneurl attachments
99-
isopened isunconfirmed
100-
flag_types num_attachment_flag_types
101-
show_attachment_flags use_keywords any_flags_requesteeble
102-
),
103-
fields()) {
104-
$ok_field{$key}++;
105-
}
106-
10772
# create a new empty bug
10873
#
10974
sub new {
@@ -162,6 +127,11 @@ sub initBug {
162127

163128
$self->{'who'} = new Bugzilla::User($user_id);
164129

130+
my $custom_fields = "";
131+
if (length(Bugzilla->custom_field_names) > 0) {
132+
$custom_fields = ", " . join(", ", Bugzilla->custom_field_names);
133+
}
134+
165135
my $query = "
166136
SELECT
167137
bugs.bug_id, alias, products.classification_id, classifications.name,
@@ -175,7 +145,8 @@ sub initBug {
175145
delta_ts, COALESCE(SUM(votes.vote_count), 0), everconfirmed,
176146
reporter_accessible, cclist_accessible,
177147
estimated_time, remaining_time, " .
178-
$dbh->sql_date_format('deadline', '%Y-%m-%d') . "
148+
$dbh->sql_date_format('deadline', '%Y-%m-%d') .
149+
$custom_fields . "
179150
FROM bugs
180151
LEFT JOIN votes
181152
ON bugs.bug_id = votes.bug_id
@@ -212,7 +183,8 @@ sub initBug {
212183
"target_milestone", "qa_contact_id", "status_whiteboard",
213184
"creation_ts", "delta_ts", "votes", "everconfirmed",
214185
"reporter_accessible", "cclist_accessible",
215-
"estimated_time", "remaining_time", "deadline")
186+
"estimated_time", "remaining_time", "deadline",
187+
Bugzilla->custom_field_names)
216188
{
217189
$fields{$field} = shift @row;
218190
if (defined $fields{$field}) {
@@ -290,8 +262,41 @@ sub remove_from_db {
290262
return $self;
291263
}
292264

265+
293266
#####################################################################
294-
# Accessors
267+
# Class Accessors
268+
#####################################################################
269+
270+
sub fields {
271+
my $class = shift;
272+
273+
return (
274+
# Standard Fields
275+
# Keep this ordering in sync with bugzilla.dtd.
276+
qw(bug_id alias creation_ts short_desc delta_ts
277+
reporter_accessible cclist_accessible
278+
classification_id classification
279+
product component version rep_platform op_sys
280+
bug_status resolution
281+
bug_file_loc status_whiteboard keywords
282+
priority bug_severity target_milestone
283+
dependson blocked votes
284+
reporter assigned_to cc),
285+
286+
# Conditional Fields
287+
Param('useqacontact') ? "qa_contact" : (),
288+
Param('timetrackinggroup') ? qw(estimated_time remaining_time
289+
actual_time deadline)
290+
: (),
291+
292+
# Custom Fields
293+
Bugzilla->custom_field_names
294+
);
295+
}
296+
297+
298+
#####################################################################
299+
# Instance Accessors
295300
#####################################################################
296301

297302
# These subs are in alphabetical order, as much as possible.
@@ -1299,13 +1304,46 @@ sub ValidateDependencies {
12991304
return %deps;
13001305
}
13011306

1307+
1308+
#####################################################################
1309+
# Autoloaded Accessors
1310+
#####################################################################
1311+
1312+
# Determines whether an attribute access trapped by the AUTOLOAD function
1313+
# is for a valid bug attribute. Bug attributes are properties and methods
1314+
# predefined by this module as well as bug fields for which an accessor
1315+
# can be defined by AUTOLOAD at runtime when the accessor is first accessed.
1316+
#
1317+
# XXX Strangely, some predefined attributes are on the list, but others aren't,
1318+
# and the original code didn't specify why that is. Presumably the only
1319+
# attributes that need to be on this list are those that aren't predefined;
1320+
# we should verify that and update the list accordingly.
1321+
#
1322+
sub _validate_attribute {
1323+
my ($attribute) = @_;
1324+
1325+
my @valid_attributes = (
1326+
# Miscellaneous properties and methods.
1327+
qw(error groups
1328+
longdescs milestoneurl attachments
1329+
isopened isunconfirmed
1330+
flag_types num_attachment_flag_types
1331+
show_attachment_flags use_keywords any_flags_requesteeble),
1332+
1333+
# Bug fields.
1334+
Bugzilla::Bug->fields
1335+
);
1336+
1337+
return grep($attribute eq $_, @valid_attributes) ? 1 : 0;
1338+
}
1339+
13021340
sub AUTOLOAD {
13031341
use vars qw($AUTOLOAD);
13041342
my $attr = $AUTOLOAD;
13051343

13061344
$attr =~ s/.*:://;
13071345
return unless $attr=~ /[^A-Z]/;
1308-
confess ("invalid bug attribute $attr") unless $ok_field{$attr};
1346+
confess("invalid bug attribute $attr") unless _validate_attribute($attr);
13091347

13101348
no strict 'refs';
13111349
*$AUTOLOAD = sub {

‎Bugzilla/Constants.pm‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ use base qw(Exporter);
9191
ADMIN_GROUP_NAME
9292
9393
SENDMAIL_EXE
94+
95+
FIELD_TYPE_UNKNOWN
96+
FIELD_TYPE_FREETEXT
9497
);
9598

9699
@Bugzilla::Constants::EXPORT_OK = qw(contenttypes);
@@ -243,4 +246,14 @@ use constant ADMIN_GROUP_NAME => 'admin';
243246
# Path to sendmail.exe (Windows only)
244247
use constant SENDMAIL_EXE => '/usr/lib/sendmail.exe';
245248

249+
# Field types. Match values in fielddefs.type column. These are purposely
250+
# not named after database column types, since Bugzilla fields comprise not
251+
# only storage but also logic. For example, we might add a "user" field type
252+
# whose values are stored in an integer column in the database but for which
253+
# we do more than we would do for a standard integer type (f.e. we might
254+
# display a user picker).
255+
256+
use constant FIELD_TYPE_UNKNOWN => 0;
257+
use constant FIELD_TYPE_FREETEXT => 1;
258+
246259
1;

‎Bugzilla/DB/Schema.pm‎

Lines changed: 5 additions & 0 deletions

0 commit comments

Comments
 (0)