From da9ac9431cc959eedef78a5118ac3b4c6fbf7d03 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Tue, 21 Feb 2006 21:08:18 +0000 Subject: Bug 287325: Ability to add custom plain-text fields to a Bug - Patch by Myk Melez r=mkanat a=justdave --- Bugzilla/Bug.pm | 116 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 39 deletions(-) (limited to 'Bugzilla/Bug.pm') diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index cab54d7da..22f62f186 100755 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -69,41 +69,6 @@ use constant MAX_COMMENT_LENGTH => 65535; ##################################################################### -sub fields { - # Keep this ordering in sync with bugzilla.dtd - my @fields = qw(bug_id alias creation_ts short_desc delta_ts - reporter_accessible cclist_accessible - classification_id classification - product component version rep_platform op_sys - bug_status resolution - bug_file_loc status_whiteboard keywords - priority bug_severity target_milestone - dependson blocked votes everconfirmed - reporter assigned_to cc - ); - - if (Param('useqacontact')) { - push @fields, "qa_contact"; - } - - if (Param('timetrackinggroup')) { - push @fields, qw(estimated_time remaining_time actual_time deadline); - } - - return @fields; -} - -my %ok_field; -foreach my $key (qw(error groups - longdescs milestoneurl attachments - isopened isunconfirmed - flag_types num_attachment_flag_types - show_attachment_flags use_keywords any_flags_requesteeble - ), - fields()) { - $ok_field{$key}++; -} - # create a new empty bug # sub new { @@ -162,6 +127,11 @@ sub initBug { $self->{'who'} = new Bugzilla::User($user_id); + my $custom_fields = ""; + if (length(Bugzilla->custom_field_names) > 0) { + $custom_fields = ", " . join(", ", Bugzilla->custom_field_names); + } + my $query = " SELECT bugs.bug_id, alias, products.classification_id, classifications.name, @@ -175,7 +145,8 @@ sub initBug { delta_ts, COALESCE(SUM(votes.vote_count), 0), everconfirmed, reporter_accessible, cclist_accessible, estimated_time, remaining_time, " . - $dbh->sql_date_format('deadline', '%Y-%m-%d') . " + $dbh->sql_date_format('deadline', '%Y-%m-%d') . + $custom_fields . " FROM bugs LEFT JOIN votes ON bugs.bug_id = votes.bug_id @@ -212,7 +183,8 @@ sub initBug { "target_milestone", "qa_contact_id", "status_whiteboard", "creation_ts", "delta_ts", "votes", "everconfirmed", "reporter_accessible", "cclist_accessible", - "estimated_time", "remaining_time", "deadline") + "estimated_time", "remaining_time", "deadline", + Bugzilla->custom_field_names) { $fields{$field} = shift @row; if (defined $fields{$field}) { @@ -290,8 +262,41 @@ sub remove_from_db { return $self; } + ##################################################################### -# Accessors +# Class Accessors +##################################################################### + +sub fields { + my $class = shift; + + return ( + # Standard Fields + # Keep this ordering in sync with bugzilla.dtd. + qw(bug_id alias creation_ts short_desc delta_ts + reporter_accessible cclist_accessible + classification_id classification + product component version rep_platform op_sys + bug_status resolution + bug_file_loc status_whiteboard keywords + priority bug_severity target_milestone + dependson blocked votes + reporter assigned_to cc), + + # Conditional Fields + Param('useqacontact') ? "qa_contact" : (), + Param('timetrackinggroup') ? qw(estimated_time remaining_time + actual_time deadline) + : (), + + # Custom Fields + Bugzilla->custom_field_names + ); +} + + +##################################################################### +# Instance Accessors ##################################################################### # These subs are in alphabetical order, as much as possible. @@ -1299,13 +1304,46 @@ sub ValidateDependencies { return %deps; } + +##################################################################### +# Autoloaded Accessors +##################################################################### + +# Determines whether an attribute access trapped by the AUTOLOAD function +# is for a valid bug attribute. Bug attributes are properties and methods +# predefined by this module as well as bug fields for which an accessor +# can be defined by AUTOLOAD at runtime when the accessor is first accessed. +# +# XXX Strangely, some predefined attributes are on the list, but others aren't, +# and the original code didn't specify why that is. Presumably the only +# attributes that need to be on this list are those that aren't predefined; +# we should verify that and update the list accordingly. +# +sub _validate_attribute { + my ($attribute) = @_; + + my @valid_attributes = ( + # Miscellaneous properties and methods. + qw(error groups + longdescs milestoneurl attachments + isopened isunconfirmed + flag_types num_attachment_flag_types + show_attachment_flags use_keywords any_flags_requesteeble), + + # Bug fields. + Bugzilla::Bug->fields + ); + + return grep($attribute eq $_, @valid_attributes) ? 1 : 0; +} + sub AUTOLOAD { use vars qw($AUTOLOAD); my $attr = $AUTOLOAD; $attr =~ s/.*:://; return unless $attr=~ /[^A-Z]/; - confess ("invalid bug attribute $attr") unless $ok_field{$attr}; + confess("invalid bug attribute $attr") unless _validate_attribute($attr); no strict 'refs'; *$AUTOLOAD = sub { -- cgit v1.2.3-24-g4f1b