Commit 015e3363 authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 339386: Make Bugzilla::Bug use Bugzilla::Object

Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=myk
parent 0e70cd46
...@@ -42,7 +42,7 @@ use Bugzilla::Product; ...@@ -42,7 +42,7 @@ use Bugzilla::Product;
use List::Util qw(min); use List::Util qw(min);
use base qw(Exporter); use base qw(Bugzilla::Object Exporter);
@Bugzilla::Bug::EXPORT = qw( @Bugzilla::Bug::EXPORT = qw(
AppendComment ValidateComment AppendComment ValidateComment
bug_alias_to_id ValidateBugAlias ValidateBugID bug_alias_to_id ValidateBugAlias ValidateBugID
...@@ -56,6 +56,45 @@ use base qw(Exporter); ...@@ -56,6 +56,45 @@ use base qw(Exporter);
# Constants # Constants
##################################################################### #####################################################################
use constant DB_TABLE => 'bugs';
use constant ID_FIELD => 'bug_id';
use constant NAME_FIELD => 'alias';
use constant LIST_ORDER => ID_FIELD;
# This is a sub because it needs to call other subroutines.
sub DB_COLUMNS {
my $dbh = Bugzilla->dbh;
return qw(
alias
bug_file_loc
bug_id
bug_severity
bug_status
cclist_accessible
component_id
delta_ts
estimated_time
everconfirmed
op_sys
priority
product_id
remaining_time
rep_platform
reporter_accessible
resolution
short_desc
status_whiteboard
target_milestone
version
),
'assigned_to AS assigned_to_id',
'reporter AS reporter_id',
'qa_contact AS qa_contact_id',
$dbh->sql_date_format('creation_ts', '%Y.%m.%d %H:%i') . ' AS creation_ts',
$dbh->sql_date_format('deadline', '%Y-%m-%d') . ' AS deadline',
Bugzilla->custom_field_names;
}
# Used in LogActivityEntry(). Gives the max length of lines in the # Used in LogActivityEntry(). Gives the max length of lines in the
# activity table. # activity table.
use constant MAX_LINE_LENGTH => 254; use constant MAX_LINE_LENGTH => 254;
...@@ -66,87 +105,47 @@ use constant MAX_COMMENT_LENGTH => 65535; ...@@ -66,87 +105,47 @@ use constant MAX_COMMENT_LENGTH => 65535;
##################################################################### #####################################################################
sub new { sub new {
my $invocant = shift; my $invocant = shift;
my $class = ref($invocant) || $invocant; my $class = ref($invocant) || $invocant;
my $self = {}; my $param = shift;
bless $self, $class;
$self->_init(@_); # If we get something that looks like a word (not a number),
return $self; # make it the "name" param.
} if (!ref($param) && $param !~ /^\d+$/) {
# But only if aliases are enabled.
sub _init { if (Bugzilla->params->{'usebugaliases'}) {
my $self = shift(); $param = { name => $param };
my ($bug_id) = (@_); }
my $dbh = Bugzilla->dbh; else {
# Aliases are off, and we got something that's not a number.
$bug_id = trim($bug_id || 0); my $error_self = {};
bless $error_self, $class;
my $old_bug_id = $bug_id; $error_self->{'bug_id'} = $param;
$error_self->{'error'} = 'InvalidBugId';
# If the bug ID isn't numeric, it might be an alias, so try to convert it. return $error_self;
$bug_id = bug_alias_to_id($bug_id) if $bug_id !~ /^0*[1-9][0-9]*$/; }
unless ($bug_id && detaint_natural($bug_id)) {
# no bug number given or the alias didn't match a bug
$self->{'bug_id'} = $old_bug_id;
$self->{'error'} = "InvalidBugId";
return $self;
}
my $custom_fields = "";
if (scalar(Bugzilla->custom_field_names) > 0) {
$custom_fields = ", " . join(", ", Bugzilla->custom_field_names);
} }
my $query = " unshift @_, $param;
SELECT my $self = $class->SUPER::new(@_);
bugs.bug_id, alias, bugs.product_id, version,
rep_platform, op_sys, bug_status, resolution, priority, # Bugzilla::Bug->new always returns something, but sets $self->{error}
bug_severity, bugs.component_id, # if the bug wasn't found in the database.
assigned_to AS assigned_to_id, reporter AS reporter_id, if (!$self) {
bug_file_loc, short_desc, target_milestone, my $error_self = {};
qa_contact AS qa_contact_id, status_whiteboard, " . bless $error_self, $class;
$dbh->sql_date_format('creation_ts', '%Y.%m.%d %H:%i') . ", $error_self->{'bug_id'} = ref($param) ? $param->{name} : $param;
delta_ts, everconfirmed, reporter_accessible, cclist_accessible, $error_self->{'error'} = 'NotFound';
estimated_time, remaining_time, " . return $error_self;
$dbh->sql_date_format('deadline', '%Y-%m-%d') .
$custom_fields . "
FROM bugs WHERE bugs.bug_id = ?";
my $bug_sth = $dbh->prepare($query);
$bug_sth->execute($bug_id);
my @row;
if (@row = $bug_sth->fetchrow_array) {
my $count = 0;
my %fields;
foreach my $field ("bug_id", "alias", "product_id", "version",
"rep_platform", "op_sys", "bug_status", "resolution",
"priority", "bug_severity", "component_id",
"assigned_to_id", "reporter_id",
"bug_file_loc", "short_desc",
"target_milestone", "qa_contact_id", "status_whiteboard",
"creation_ts", "delta_ts", "everconfirmed",
"reporter_accessible", "cclist_accessible",
"estimated_time", "remaining_time", "deadline",
Bugzilla->custom_field_names)
{
$fields{$field} = shift @row;
if (defined $fields{$field}) {
$self->{$field} = $fields{$field};
}
$count++;
} }
} else {
$self->{'bug_id'} = $bug_id; # XXX At some point these should be moved into accessors.
$self->{'error'} = "NotFound"; # They only are here because this is how Bugzilla::Bug
return $self; # originally did things, before it was a Bugzilla::Object.
} $self->{'isunconfirmed'} = ($self->{bug_status} eq 'UNCONFIRMED');
$self->{'isopened'} = is_open_state($self->{bug_status});
$self->{'isunconfirmed'} = ($self->{bug_status} eq 'UNCONFIRMED');
$self->{'isopened'} = is_open_state($self->{bug_status}); return $self;
return $self;
} }
# This is the correct way to delete bugs from the DB. # This is the correct way to delete bugs from the DB.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment