summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Bug.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla/Bug.pm')
-rw-r--r--Bugzilla/Bug.pm674
1 files changed, 528 insertions, 146 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 90bd8b66d..39a0f2596 100644
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -50,6 +50,7 @@ use Bugzilla::Group;
use Bugzilla::Status;
use Bugzilla::Comment;
use Bugzilla::BugUrl;
+use Bugzilla::BugUserLastVisit;
use List::MoreUtils qw(firstidx uniq part);
use List::Util qw(min max first);
@@ -76,11 +77,14 @@ use constant LIST_ORDER => ID_FIELD;
# Bugs have their own auditing table, bugs_activity.
use constant AUDIT_CREATES => 0;
use constant AUDIT_UPDATES => 0;
+# This will be enabled later
+use constant USE_MEMCACHED => 0;
# This is a sub because it needs to call other subroutines.
sub DB_COLUMNS {
my $dbh = Bugzilla->dbh;
- my @custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT}
+ my @custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT
+ && $_->type != FIELD_TYPE_EXTENSION}
Bugzilla->active_custom_fields;
my @custom_names = map {$_->name} @custom;
@@ -93,6 +97,7 @@ sub DB_COLUMNS {
bug_status
cclist_accessible
component_id
+ creation_ts
delta_ts
estimated_time
everconfirmed
@@ -111,12 +116,11 @@ sub DB_COLUMNS {
version
),
'reporter AS reporter_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',
@custom_names);
-
+
Bugzilla::Hook::process("bug_columns", { columns => \@columns });
-
+
return @columns;
}
@@ -166,6 +170,9 @@ sub VALIDATORS {
elsif ($field->type == FIELD_TYPE_DATETIME) {
$validator = \&_check_datetime_field;
}
+ elsif ($field->type == FIELD_TYPE_DATE) {
+ $validator = \&_check_date_field;
+ }
elsif ($field->type == FIELD_TYPE_FREETEXT) {
$validator = \&_check_freetext_field;
}
@@ -211,7 +218,8 @@ sub VALIDATOR_DEPENDENCIES {
};
sub UPDATE_COLUMNS {
- my @custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT}
+ my @custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT
+ && $_->type != FIELD_TYPE_EXTENSION}
Bugzilla->active_custom_fields;
my @custom_names = map {$_->name} @custom;
my @columns = qw(
@@ -248,7 +256,8 @@ use constant NUMERIC_COLUMNS => qw(
);
sub DATE_COLUMNS {
- my @fields = @{ Bugzilla->fields({ type => FIELD_TYPE_DATETIME }) };
+ my @fields = (@{ Bugzilla->fields({ type => FIELD_TYPE_DATETIME }) },
+ @{ Bugzilla->fields({ type => FIELD_TYPE_DATE }) });
return map { $_->name } @fields;
}
@@ -280,10 +289,6 @@ use constant FIELD_MAP => {
summary => 'short_desc',
url => 'bug_file_loc',
whiteboard => 'status_whiteboard',
-
- # These are special values for the WebService Bug.search method.
- limit => 'LIMIT',
- offset => 'OFFSET',
};
use constant REQUIRED_FIELD_MAP => {
@@ -311,21 +316,11 @@ use constant EXTRA_REQUIRED_FIELDS => qw(creation_ts target_milestone cc qa_cont
#####################################################################
-# This and "new" catch every single way of creating a bug, so that we
-# can call _create_cf_accessors.
-sub _do_list_select {
- my $invocant = shift;
- $invocant->_create_cf_accessors();
- return $invocant->SUPER::_do_list_select(@_);
-}
-
sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my $param = shift;
- $class->_create_cf_accessors();
-
# Remove leading "#" mark if we've just been passed an id.
if (!ref $param && $param =~ /^#(\d+)$/) {
$param = $1;
@@ -333,10 +328,14 @@ sub new {
# If we get something that looks like a word (not a number),
# make it the "name" param.
- if (!defined $param || (!ref($param) && $param !~ /^\d+$/)) {
+ if (!defined $param
+ || (!ref($param) && (!$param || $param =~ /\D/))
+ || (ref($param) && (!$param->{id} || $param->{id} =~ /\D/)))
+ {
# But only if aliases are enabled.
if (Bugzilla->params->{'usebugaliases'} && $param) {
- $param = { name => $param };
+ $param = { name => ref($param) ? $param->{id} : $param,
+ cache => ref($param) ? $param->{cache} : 0 };
}
else {
# Aliases are off, and we got something that's not a number.
@@ -370,20 +369,35 @@ sub new {
return $self;
}
-sub check {
+sub initialize {
+ $_[0]->_create_cf_accessors();
+}
+
+sub object_cache_key {
my $class = shift;
- my ($id, $field) = @_;
+ my $key = $class->SUPER::object_cache_key(@_)
+ || return;
+ return $key . ',' . Bugzilla->user->id;
+}
- ThrowUserError('improper_bug_id_field_value', { field => $field }) unless defined $id;
+sub check {
+ my $class = shift;
+ my ($param, $field) = @_;
# Bugzilla::Bug throws lots of special errors, so we don't call
# SUPER::check, we just call our new and do our own checks.
- my $self = $class->new(trim($id));
- # For error messages, use the id that was returned by new(), because
- # it's cleaned up.
- $id = $self->id;
+ my $id = ref($param)
+ ? ($param->{id} = trim($param->{id}))
+ : ($param = trim($param));
+ ThrowUserError('improper_bug_id_field_value', { field => $field }) unless defined $id;
+
+ my $self = $class->new($param);
if ($self->{error}) {
+ # For error messages, use the id that was returned by new(), because
+ # it's cleaned up.
+ $id = $self->id;
+
if ($self->{error} eq 'NotFound') {
ThrowUserError("bug_id_does_not_exist", { bug_id => $id });
}
@@ -493,6 +507,59 @@ sub preload {
# If we don't do this, can_see_bug will do one call per bug in
# the dependency lists, during get_bug_link in Bugzilla::Template.
$user->visible_bugs(\@all_dep_ids);
+
+ # We preload comments here in order to allow us to compare the time it
+ # takes to load comments from the database with the template rendering
+ # time.
+ foreach my $bug (@$bugs) {
+ $bug->comments();
+ }
+
+ foreach my $bug (@$bugs) {
+ $bug->_preload_referenced_bugs();
+ }
+}
+
+# Helps load up bugs referenced in comments by retrieving them with a single
+# query from the database and injecting bug objects into the object-cache.
+sub _preload_referenced_bugs {
+ my $self = shift;
+ my @referenced_bug_ids;
+
+ # inject current duplicates into the object-cache first
+ foreach my $bug (@{ $self->duplicates }) {
+ $bug->object_cache_set()
+ unless Bugzilla::Bug->object_cache_get($bug->id);
+ }
+
+ # preload bugs from comments
+ require Bugzilla::Template;
+ foreach my $comment (@{ $self->comments }) {
+ if ($comment->type == CMT_HAS_DUPE || $comment->type == CMT_DUPE_OF) {
+ # duplicate bugs that aren't currently in $self->duplicates
+ push @referenced_bug_ids, $comment->extra_data
+ unless Bugzilla::Bug->object_cache_get($comment->extra_data);
+ }
+ else {
+ # bugs referenced in comments
+ Bugzilla::Template::quoteUrls($comment->body, undef, undef, undef,
+ sub {
+ my $bug_id = $_[0];
+ push @referenced_bug_ids, $bug_id
+ unless Bugzilla::Bug->object_cache_get($bug_id);
+ });
+ }
+ }
+
+ # inject into object-cache
+ my $referenced_bugs = Bugzilla::Bug->new_from_list(
+ [ uniq @referenced_bug_ids ]);
+ foreach my $bug (@$referenced_bugs) {
+ $bug->object_cache_set();
+ }
+
+ # preload bug visibility
+ Bugzilla->user->visible_bugs(\@referenced_bug_ids);
}
sub possible_duplicates {
@@ -512,8 +579,10 @@ sub possible_duplicates {
my $dbh = Bugzilla->dbh;
my $user = Bugzilla->user;
my @words = split(/[\b\s]+/, $short_desc || '');
- # Exclude punctuation from the array.
- @words = map { /(\w+)/; $1 } @words;
+ # Remove leading/trailing punctuation from words
+ foreach my $word (@words) {
+ $word =~ s/(?:^\W+|\W+$)//g;
+ }
# And make sure that each word is longer than 2 characters.
@words = grep { defined $_ and length($_) > 2 } @words;
@@ -615,6 +684,14 @@ sub create {
my ($class, $params) = @_;
my $dbh = Bugzilla->dbh;
+ # BMO - allow parameter alteration before creation. also add support for
+ # fields which are not bug columns (eg bug_mentors). extensions should move
+ # fields from $params to $stash, then use the bug_end_of_create hook to
+ # update the database
+ my $stash = {};
+ Bugzilla::Hook::process('bug_before_create', { params => $params,
+ stash => $stash });
+
$dbh->bz_start_transaction();
# These fields have default values which we can use if they are undefined.
@@ -640,6 +717,7 @@ sub create {
my $blocked = delete $params->{blocked};
my $keywords = delete $params->{keywords};
my $creation_comment = delete $params->{comment};
+ my $see_also = delete $params->{see_also};
# We don't want the bug to appear in the system until it's correctly
# protected by groups.
@@ -676,21 +754,20 @@ sub create {
# Set up dependencies (blocked/dependson)
my $sth_deps = $dbh->prepare(
'INSERT INTO dependencies (blocked, dependson) VALUES (?, ?)');
- my $sth_bug_time = $dbh->prepare('UPDATE bugs SET delta_ts = ? WHERE bug_id = ?');
foreach my $depends_on_id (@$depends_on) {
$sth_deps->execute($bug->bug_id, $depends_on_id);
# Log the reverse action on the other bug.
LogActivityEntry($depends_on_id, 'blocked', '', $bug->bug_id,
$bug->{reporter_id}, $timestamp);
- $sth_bug_time->execute($timestamp, $depends_on_id);
+ _update_delta_ts($depends_on_id, $timestamp);
}
foreach my $blocked_id (@$blocked) {
$sth_deps->execute($blocked_id, $bug->bug_id);
# Log the reverse action on the other bug.
LogActivityEntry($blocked_id, 'dependson', '', $bug->bug_id,
$bug->{reporter_id}, $timestamp);
- $sth_bug_time->execute($timestamp, $blocked_id);
+ _update_delta_ts($blocked_id, $timestamp);
}
# Insert the values into the multiselect value tables
@@ -703,6 +780,25 @@ sub create {
}
}
+ # Insert any see_also values
+ if ($see_also) {
+ my $see_also_array = $see_also;
+ if (!ref $see_also_array) {
+ $see_also = trim($see_also);
+ $see_also_array = [ split(/[\s,]+/, $see_also) ];
+ }
+ foreach my $value (@$see_also_array) {
+ $bug->add_see_also($value);
+ }
+ foreach my $see_also (@{ $bug->see_also }) {
+ $see_also->insert_create_data($see_also);
+ }
+ foreach my $ref_bug (@{ $bug->{_update_ref_bugs} || [] }) {
+ $ref_bug->update();
+ }
+ delete $bug->{_update_ref_bugs};
+ }
+
# Comment #0 handling...
# We now have a bug id so we can fill this out
@@ -712,8 +808,10 @@ sub create {
# but sometimes it's blank.
Bugzilla::Comment->insert_create_data($creation_comment);
+ # BMO - add the stash param from bug_start_of_create
Bugzilla::Hook::process('bug_end_of_create', { bug => $bug,
timestamp => $timestamp,
+ stash => $stash,
});
$dbh->bz_commit_transaction();
@@ -721,7 +819,10 @@ sub create {
# Because MySQL doesn't support transactions on the fulltext table,
# we do this after we've committed the transaction. That way we're
# sure we're inserting a good Bug ID.
- $bug->_sync_fulltext('new bug');
+ $bug->_sync_fulltext( new_bug => 1 );
+
+ # BMO - some work should happen outside of the transaction block
+ Bugzilla::Hook::process('bug_after_create', { bug => $bug, timestamp => $timestamp });
return $bug;
}
@@ -775,8 +876,9 @@ sub run_create_validators {
sub update {
my $self = shift;
+ my $dbh = Bugzilla->dbh;
+ my $user = Bugzilla->user;
- my $dbh = Bugzilla->dbh;
# XXX This is just a temporary hack until all updating happens
# inside this function.
my $delta_ts = shift || $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)');
@@ -785,6 +887,10 @@ sub update {
my ($changes, $old_bug) = $self->SUPER::update(@_);
+ Bugzilla::Hook::process('bug_start_of_update',
+ { timestamp => $delta_ts, bug => $self,
+ old_bug => $old_bug, changes => $changes });
+
# Certain items in $changes have to be fixed so that they hold
# a name instead of an ID.
foreach my $field (qw(product_id component_id)) {
@@ -863,10 +969,9 @@ sub update {
# Add an activity entry for the other bug.
LogActivityEntry($removed_id, $other, $self->id, '',
- Bugzilla->user->id, $delta_ts);
+ $user->id, $delta_ts);
# Update delta_ts on the other bug so that we trigger mid-airs.
- $dbh->do('UPDATE bugs SET delta_ts = ? WHERE bug_id = ?',
- undef, $delta_ts, $removed_id);
+ _update_delta_ts($removed_id, $delta_ts);
}
foreach my $added_id (@$added) {
$dbh->do("INSERT INTO dependencies ($type, $other) VALUES (?,?)",
@@ -874,10 +979,9 @@ sub update {
# Add an activity entry for the other bug.
LogActivityEntry($added_id, $other, '', $self->id,
- Bugzilla->user->id, $delta_ts);
+ $user->id, $delta_ts);
# Update delta_ts on the other bug so that we trigger mid-airs.
- $dbh->do('UPDATE bugs SET delta_ts = ? WHERE bug_id = ?',
- undef, $delta_ts, $added_id);
+ _update_delta_ts($added_id, $delta_ts);
}
if (scalar(@$removed) || scalar(@$added)) {
@@ -916,7 +1020,7 @@ sub update {
$comment = Bugzilla::Comment->insert_create_data($comment);
if ($comment->work_time) {
LogActivityEntry($self->id, "work_time", "", $comment->work_time,
- Bugzilla->user->id, $delta_ts);
+ $user->id, $delta_ts);
}
}
@@ -927,7 +1031,7 @@ sub update {
my ($from, $to)
= $comment->is_private ? (0, 1) : (1, 0);
LogActivityEntry($self->id, "longdescs.isprivate", $from, $to,
- Bugzilla->user->id, $delta_ts, $comment->id);
+ $user->id, $delta_ts, $comment->id);
}
# Clear the cache of comments
@@ -974,6 +1078,10 @@ sub update {
$changes->{'flagtypes.name'} = [$removed, $added];
}
+ # BMO - allow extensions to alter what is logged into bugs_activity
+ Bugzilla::Hook::process('bug_update_before_logging',
+ { bug => $self, timestamp => $delta_ts, changes => $changes, old_bug => $old_bug });
+
# Log bugs_activity items
# XXX Eventually, when bugs_activity is able to track the dupe_id,
# this code should go below the duplicates-table-updating code below.
@@ -981,8 +1089,8 @@ sub update {
my $change = $changes->{$field};
my $from = defined $change->[0] ? $change->[0] : '';
my $to = defined $change->[1] ? $change->[1] : '';
- LogActivityEntry($self->id, $field, $from, $to, Bugzilla->user->id,
- $delta_ts);
+ LogActivityEntry($self->id, $field, $from, $to,
+ $user->id, $delta_ts);
}
# Check if we have to update the duplicates table and the other bug.
@@ -996,7 +1104,7 @@ sub update {
$update_dup->update();
}
}
-
+
$changes->{'dup_id'} = [$old_dup || undef, $cur_dup || undef];
}
@@ -1008,20 +1116,50 @@ sub update {
if (scalar(keys %$changes) || $self->{added_comments}
|| $self->{comment_isprivate})
{
- $dbh->do('UPDATE bugs SET delta_ts = ? WHERE bug_id = ?',
- undef, ($delta_ts, $self->id));
+ _update_delta_ts($self->id, $delta_ts);
$self->{delta_ts} = $delta_ts;
}
+ # Update last-visited
+ if ($user->is_involved_in_bug($self)) {
+ $self->update_user_last_visit($user, $delta_ts);
+ }
+
+ # If a user is no longer involved, remove their last visit entry
+ my $last_visits = Bugzilla::BugUserLastVisit->match({bug_id => $self->id});
+ foreach my $lv (@$last_visits) {
+ $lv->remove_from_db() unless $lv->user->is_involved_in_bug($self);
+ }
+
+ # Update bug ignore data if user wants to ignore mail for this bug
+ if (exists $self->{'bug_ignored'}) {
+ my $bug_ignored_changed;
+ if ($self->{'bug_ignored'} && !$user->is_bug_ignored($self->id)) {
+ $dbh->do('INSERT INTO email_bug_ignore
+ (user_id, bug_id) VALUES (?, ?)',
+ undef, $user->id, $self->id);
+ $bug_ignored_changed = 1;
+
+ }
+ elsif (!$self->{'bug_ignored'} && $user->is_bug_ignored($self->id)) {
+ $dbh->do('DELETE FROM email_bug_ignore
+ WHERE user_id = ? AND bug_id = ?',
+ undef, $user->id, $self->id);
+ $bug_ignored_changed = 1;
+ }
+ delete $user->{bugs_ignored} if $bug_ignored_changed;
+ }
+
$dbh->bz_commit_transaction();
# The only problem with this here is that update() is often called
# in the middle of a transaction, and if that transaction is rolled
# back, this change will *not* be rolled back. As we expect rollbacks
# to be extremely rare, that is OK for us.
- $self->_sync_fulltext()
- if $self->{added_comments} || $changes->{short_desc}
- || $self->{comment_isprivate};
+ $self->_sync_fulltext(
+ update_short_desc => $changes->{short_desc},
+ update_comments => $self->{added_comments} || $self->{comment_isprivate}
+ );
# Remove obsolete internal variables.
delete $self->{'_old_assigned_to'};
@@ -1029,7 +1167,11 @@ sub update {
# Also flush the visible_bugs cache for this bug as the user's
# relationship with this bug may have changed.
- delete Bugzilla->user->{_visible_bugs_cache}->{$self->id};
+ delete $user->{_visible_bugs_cache}->{$self->id};
+
+ # BMO - some work should happen outside of the transaction block
+ Bugzilla::Hook::process('bug_after_update',
+ { bug => $self, timestamp => $delta_ts, changes => $changes, old_bug => $old_bug });
return $changes;
}
@@ -1055,27 +1197,56 @@ sub _extract_multi_selects {
# Should be called any time you update short_desc or change a comment.
sub _sync_fulltext {
- my ($self, $new_bug) = @_;
+ my ($self, %options) = @_;
my $dbh = Bugzilla->dbh;
- if ($new_bug) {
- $dbh->do('INSERT INTO bugs_fulltext (bug_id, short_desc)
- SELECT bug_id, short_desc FROM bugs WHERE bug_id = ?',
- undef, $self->id);
+
+ my($all_comments, $public_comments);
+ if ($options{new_bug} || $options{update_comments}) {
+ my $comments = $dbh->selectall_arrayref(
+ 'SELECT thetext, isprivate FROM longdescs WHERE bug_id = ?',
+ undef, $self->id);
+ $all_comments = join("\n", map { $_->[0] } @$comments);
+ my @no_private = grep { !$_->[1] } @$comments;
+ $public_comments = join("\n", map { $_->[0] } @no_private);
}
- else {
- $dbh->do('UPDATE bugs_fulltext SET short_desc = ? WHERE bug_id = ?',
- undef, $self->short_desc, $self->id);
+
+ if ($options{new_bug}) {
+ $dbh->do('INSERT INTO bugs_fulltext (bug_id, short_desc, comments,
+ comments_noprivate)
+ VALUES (?, ?, ?, ?)',
+ undef,
+ $self->id, $self->short_desc, $all_comments, $public_comments);
+ } else {
+ my(@names, @values);
+ if ($options{update_short_desc}) {
+ push @names, 'short_desc';
+ push @values, $self->short_desc;
+ }
+ if ($options{update_comments}) {
+ push @names, ('comments', 'comments_noprivate');
+ push @values, ($all_comments, $public_comments);
+ }
+ if (@names) {
+ $dbh->do('UPDATE bugs_fulltext SET ' .
+ join(', ', map { "$_ = ?" } @names) .
+ ' WHERE bug_id = ?',
+ undef,
+ @values, $self->id);
+ }
}
- my $comments = $dbh->selectall_arrayref(
- 'SELECT thetext, isprivate FROM longdescs WHERE bug_id = ?',
- undef, $self->id);
- my $all = join("\n", map { $_->[0] } @$comments);
- my @no_private = grep { !$_->[1] } @$comments;
- my $nopriv_string = join("\n", map { $_->[0] } @no_private);
- $dbh->do('UPDATE bugs_fulltext SET comments = ?, comments_noprivate = ?
- WHERE bug_id = ?', undef, $all, $nopriv_string, $self->id);
}
+# Update a bug's delta_ts without requiring the full object to be loaded.
+sub _update_delta_ts {
+ my ($bug_id, $timestamp) = @_;
+ Bugzilla->dbh->do(
+ "UPDATE bugs SET delta_ts = ? WHERE bug_id = ?",
+ undef,
+ $timestamp, $bug_id
+ );
+ Bugzilla::Hook::process('bug_end_of_update_delta_ts',
+ { bug_id => $bug_id, timestamp => $timestamp });
+}
# This is the correct way to delete bugs from the DB.
# No bug should be deleted from anywhere else except from here.
@@ -1164,15 +1335,15 @@ sub send_changes {
changer => $user,
);
- _send_bugmail({ id => $self->id, type => 'bug', forced => \%forced },
- $vars);
+ my $recipient_count = _send_bugmail(
+ { id => $self->id, type => 'bug', forced => \%forced }, $vars);
# If the bug was marked as a duplicate, we need to notify users on the
# other bug of any changes to that bug.
my $new_dup_id = $changes->{'dup_id'} ? $changes->{'dup_id'}->[1] : undef;
if ($new_dup_id) {
- _send_bugmail({ forced => { changer => $user }, type => "dupe",
- id => $new_dup_id }, $vars);
+ $recipient_count += _send_bugmail(
+ { forced => { changer => $user }, type => "dupe", id => $new_dup_id }, $vars);
}
# If there were changes in dependencies, we need to notify those
@@ -1191,7 +1362,7 @@ sub send_changes {
foreach my $id (@{ $self->blocked }) {
$params->{id} = $id;
- _send_bugmail($params, $vars);
+ $recipient_count += _send_bugmail($params, $vars);
}
}
}
@@ -1209,15 +1380,17 @@ sub send_changes {
delete $changed_deps{''};
foreach my $id (sort { $a <=> $b } (keys %changed_deps)) {
- _send_bugmail({ forced => { changer => $user }, type => "dep",
- id => $id }, $vars);
+ $recipient_count += _send_bugmail(
+ { forced => { changer => $user }, type => "dep", id => $id }, $vars);
}
# Sending emails for the referenced bugs.
foreach my $ref_bug_id (uniq @{ $self->{see_also_changes} || [] }) {
- _send_bugmail({ forced => { changer => $user },
- id => $ref_bug_id }, $vars);
+ $recipient_count += _send_bugmail(
+ { forced => { changer => $user }, id => $ref_bug_id }, $vars);
}
+
+ return $recipient_count;
}
sub _send_bugmail {
@@ -1225,7 +1398,7 @@ sub _send_bugmail {
require Bugzilla::BugMail;
- my $results =
+ my $results =
Bugzilla::BugMail::Send($params->{'id'}, $params->{'forced'}, $params);
if (Bugzilla->usage_mode == USAGE_MODE_BROWSER) {
@@ -1236,6 +1409,8 @@ sub _send_bugmail {
|| ThrowTemplateError($template->error());
$vars->{'header_done'} = 1;
}
+
+ return scalar @{ $results->{sent} };
}
#####################################################################
@@ -1658,7 +1833,9 @@ sub _check_groups {
foreach my $name (@$group_names) {
my $group = Bugzilla::Group->check_no_disclose({ %args, name => $name });
- if (!$product->group_is_settable($group)) {
+ # BMO : allow bugs to be always placed into some groups
+ if (!$product->group_always_settable($group)
+ && !$product->group_is_settable($group)) {
ThrowUserError('group_restriction_not_allowed', { %args, name => $name });
}
$add_groups{$group->id} = $group;
@@ -1667,7 +1844,7 @@ sub _check_groups {
# Now enforce mandatory groups.
$add_groups{$_->id} = $_ foreach @{ $product->groups_mandatory };
-
+
my @add_groups = values %add_groups;
return \@add_groups;
}
@@ -1989,8 +2166,12 @@ sub _check_field_is_mandatory {
}
}
+sub _check_date_field {
+ my ($invocant, $date) = @_;
+ return $invocant->_check_datetime_field($date, undef, {date_only => 1});
+}
sub _check_datetime_field {
- my ($invocant, $date_time) = @_;
+ my ($invocant, $date_time, $field, $params) = @_;
# Empty datetimes are empty strings or strings only containing
# 0's, whitespace, and punctuation.
@@ -2004,6 +2185,10 @@ sub _check_datetime_field {
ThrowUserError('illegal_date', { date => $date,
format => 'YYYY-MM-DD' });
}
+ if ($time && $params->{date_only}) {
+ ThrowUserError('illegal_date', { date => $date_time,
+ format => 'YYYY-MM-DD' });
+ }
if ($time && !validate_time($time)) {
ThrowUserError('illegal_time', { 'time' => $time,
format => 'HH:MM:SS' });
@@ -2254,7 +2439,8 @@ sub set_all {
$self->_add_remove($params, 'see_also');
# And set custom fields.
- my @custom_fields = Bugzilla->active_custom_fields;
+ my @custom_fields = grep { $_->type != FIELD_TYPE_EXTENSION }
+ Bugzilla->active_custom_fields;
foreach my $field (@custom_fields) {
my $fname = $field->name;
if (exists $params->{$fname}) {
@@ -2269,7 +2455,7 @@ sub set_all {
# we have to check that the current assignee, qa, and CCs are still
# valid if we've switched products, under strict_isolation. We can only
# do that here, because if they *did* change the assignee, qa, or CC,
- # then we don't want to check the original ones, only the new ones.
+ # then we don't want to check the original ones, only the new ones.
$self->_check_strict_isolation() if $product_changed;
}
@@ -2299,6 +2485,7 @@ sub reset_assigned_to {
my $comp = $self->component_obj;
$self->set_assigned_to($comp->default_assignee);
}
+sub set_bug_ignored { $_[0]->set('bug_ignored', $_[1]); }
sub set_cclist_accessible { $_[0]->set('cclist_accessible', $_[1]); }
sub set_comment_is_private {
my ($self, $comment_id, $isprivate) = @_;
@@ -2796,20 +2983,26 @@ sub add_group {
# If the bug is already in this group, then there is nothing to do.
return if $self->in_group($group);
-
- # Make sure that bugs in this product can actually be restricted
- # to this group by the current user.
- $self->product_obj->group_is_settable($group)
- || ThrowUserError('group_restriction_not_allowed', $args);
-
- # OtherControl people can add groups only during a product change,
- # and only when the group is not NA for them.
- if (!Bugzilla->user->in_group($group->name)) {
- my $controls = $self->product_obj->group_controls->{$group->id};
- if (!$self->{_old_product_name}
- || $controls->{othercontrol} == CONTROLMAPNA)
- {
- ThrowUserError('group_restriction_not_allowed', $args);
+ # BMO : allow bugs to be always placed into some groups by the bug's
+ # reporter, or by users with editbugs
+ my $user = Bugzilla->user;
+ if (!$self->product_obj->group_always_settable($group)
+ || ($self->{reporter_id} != $user->id && !$user->in_group('editbugs')))
+ {
+ # Make sure that bugs in this product can actually be restricted
+ # to this group by the current user.
+ $self->product_obj->group_is_settable($group)
+ || ThrowUserError('group_restriction_not_allowed', $args);
+
+ # OtherControl people can add groups only during a product change,
+ # and only when the group is not NA for them.
+ if (!$user->in_group($group->name)) {
+ my $controls = $self->product_obj->group_controls->{$group->id};
+ if (!$self->{_old_product_name}
+ || $controls->{othercontrol} == CONTROLMAPNA)
+ {
+ ThrowUserError('group_restriction_not_allowed', $args);
+ }
}
}
@@ -3156,7 +3349,7 @@ sub attachments {
return [] if $self->{'error'};
$self->{'attachments'} =
- Bugzilla::Attachment->get_attachments_by_bug($self->bug_id, {preload => 1});
+ Bugzilla::Attachment->get_attachments_by_bug($self, {preload => 1});
return $self->{'attachments'};
}
@@ -3164,8 +3357,8 @@ sub assigned_to {
my ($self) = @_;
return $self->{'assigned_to_obj'} if exists $self->{'assigned_to_obj'};
$self->{'assigned_to'} = 0 if $self->{'error'};
- $self->{'assigned_to_obj'} ||= new Bugzilla::User($self->{'assigned_to'});
- return $self->{'assigned_to_obj'};
+ return $self->{'assigned_to_obj'}
+ = new Bugzilla::User({ id => $self->{'assigned_to'}, cache => 1 });
}
sub blocked {
@@ -3229,11 +3422,8 @@ sub cc_users {
sub component {
my ($self) = @_;
- return $self->{component} if exists $self->{component};
return '' if $self->{error};
- ($self->{component}) = Bugzilla->dbh->selectrow_array(
- 'SELECT name FROM components WHERE id = ?',
- undef, $self->{component_id});
+ ($self->{component}) //= $self->component_obj->name;
return $self->{component};
}
@@ -3242,7 +3432,8 @@ sub component_obj {
my ($self) = @_;
return $self->{component_obj} if defined $self->{component_obj};
return {} if $self->{error};
- $self->{component_obj} = new Bugzilla::Component($self->{component_id});
+ $self->{component_obj} =
+ new Bugzilla::Component({ id => $self->{component_id}, cache => 1 });
return $self->{component_obj};
}
@@ -3281,6 +3472,26 @@ sub depends_on_obj {
return $self->{depends_on_obj};
}
+sub duplicates {
+ my $self = shift;
+ return $self->{duplicates} if exists $self->{duplicates};
+ return [] if $self->{error};
+ $self->{duplicates} = Bugzilla::Bug->new_from_list($self->duplicate_ids);
+ return $self->{duplicates};
+}
+
+sub duplicate_ids {
+ my $self = shift;
+ return $self->{duplicate_ids} if exists $self->{duplicate_ids};
+ return [] if $self->{error};
+
+ my $dbh = Bugzilla->dbh;
+ $self->{duplicate_ids} =
+ $dbh->selectcol_arrayref('SELECT dupe FROM duplicates WHERE dupe_of = ?',
+ undef, $self->id);
+ return $self->{duplicate_ids};
+}
+
sub flag_types {
my ($self) = @_;
return $self->{'flag_types'} if exists $self->{'flag_types'};
@@ -3289,7 +3500,8 @@ sub flag_types {
my $vars = { target_type => 'bug',
product_id => $self->{product_id},
component_id => $self->{component_id},
- bug_id => $self->bug_id };
+ bug_id => $self->bug_id,
+ active_or_has_flags => $self->bug_id };
$self->{'flag_types'} = Bugzilla::Flag->_flag_types($vars);
return $self->{'flag_types'};
@@ -3338,8 +3550,14 @@ sub comments {
$comment->{count} = $count++;
$comment->{bug} = $self;
}
- Bugzilla::Comment->preload($self->{'comments'});
+ # Some bugs may have no comments when upgrading old installations.
+ Bugzilla::Comment->preload($self->{'comments'}) if @{ $self->{'comments'} };
+ # BMO - for comment deletion support
+ Bugzilla::Hook::process('bug_comments',
+ { bug => $self, comments => $self->{'comments'} });
}
+ return unless defined wantarray;
+
my @comments = @{ $self->{'comments'} };
my $order = $params->{order}
@@ -3378,11 +3596,8 @@ sub percentage_complete {
sub product {
my ($self) = @_;
- return $self->{product} if exists $self->{product};
return '' if $self->{error};
- ($self->{product}) = Bugzilla->dbh->selectrow_array(
- 'SELECT name FROM products WHERE id = ?',
- undef, $self->{product_id});
+ ($self->{product}) //= $self->product_obj->name;
return $self->{product};
}
@@ -3390,7 +3605,8 @@ sub product {
sub product_obj {
my $self = shift;
return {} if $self->{error};
- $self->{product_obj} ||= new Bugzilla::Product($self->{product_id});
+ $self->{product_obj} ||=
+ new Bugzilla::Product({ id => $self->{product_id}, cache => 1 });
return $self->{product_obj};
}
@@ -3400,7 +3616,8 @@ sub qa_contact {
return undef if $self->{'error'};
if (Bugzilla->params->{'useqacontact'} && $self->{'qa_contact'}) {
- $self->{'qa_contact_obj'} = new Bugzilla::User($self->{'qa_contact'});
+ $self->{'qa_contact_obj'}
+ = new Bugzilla::User({ id => $self->{'qa_contact'}, cache => 1 });
} else {
# XXX - This is somewhat inconsistent with the assignee/reporter
# methods, which will return an empty User if they get a 0.
@@ -3414,8 +3631,8 @@ sub reporter {
my ($self) = @_;
return $self->{'reporter'} if exists $self->{'reporter'};
$self->{'reporter_id'} = 0 if $self->{'error'};
- $self->{'reporter'} = new Bugzilla::User($self->{'reporter_id'});
- return $self->{'reporter'};
+ return $self->{'reporter'}
+ = new Bugzilla::User({ id => $self->{'reporter_id'}, cache => 1 });
}
sub see_also {
@@ -3556,6 +3773,49 @@ sub groups {
}
}
+ # BMO: if required, hack in groups exposed by -visible membership
+ # (eg mozilla-employee-confidential-visible), so reporters can add the
+ # bug to a group on show_bug.
+ # if the bug is already in the group, the user will not be able to remove
+ # it unless they are a true group member.
+ my $user = Bugzilla->user;
+ if ($self->{'reporter_id'} == $user->id) {
+ foreach my $group (@{ $user->groups }) {
+ # map from -visible group to the real one
+ my $group_name = $group->name;
+ next unless $group_name =~ s/-visible$//;
+ next if $user->in_group($group_name);
+ $group = Bugzilla::Group->new({ name => $group_name, cache => 1 });
+
+ # only show the group if it's visible to normal members
+ my ($member_control) = $dbh->selectrow_array(
+ "SELECT membercontrol
+ FROM groups
+ LEFT JOIN group_control_map
+ ON group_control_map.group_id = groups.id
+ AND group_control_map.product_id = ?
+ WHERE groups.id = ?",
+ undef,
+ $self->{product_id}, $group->id
+ );
+
+ if (
+ $member_control
+ && $member_control == CONTROLMAPSHOWN
+ && !grep { $_->{bit} == $group->id } @groups)
+ {
+ push(@groups, {
+ bit => $group->id,
+ name => $group->name,
+ ison => 0,
+ ingroup => 1,
+ mandatory => 0,
+ description => $group->description,
+ });
+ }
+ }
+ }
+
$self->{'groups'} = \@groups;
return $self->{'groups'};
@@ -3674,6 +3934,9 @@ sub editable_bug_fields {
# Ensure field exists before attempting to remove it.
splice(@fields, $location, 1) if ($location > -1);
}
+
+ Bugzilla::Hook::process('bug_editable_bug_fields', { fields => \@fields });
+
# Sorted because the old @::log_columns variable, which this replaces,
# was sorted.
return sort(@fields);
@@ -3684,32 +3947,52 @@ sub editable_bug_fields {
# Join with bug_status and bugs tables to show bugs with open statuses first,
# and then the others
sub EmitDependList {
- my ($myfield, $targetfield, $bug_id) = (@_);
+ my ($my_field, $target_field, $bug_id, $exclude_resolved) = @_;
+ my $cache = Bugzilla->request_cache->{bug_dependency_list} ||= {};
+
my $dbh = Bugzilla->dbh;
- my $list_ref = $dbh->selectcol_arrayref(
- "SELECT $targetfield
+ $exclude_resolved = $exclude_resolved ? 1 : 0;
+ my $is_open_clause = $exclude_resolved ? 'AND is_open = 1' : '';
+
+ $cache->{"${target_field}_sth_$exclude_resolved"} ||= $dbh->prepare(
+ "SELECT $target_field
FROM dependencies
- INNER JOIN bugs ON dependencies.$targetfield = bugs.bug_id
+ INNER JOIN bugs ON dependencies.$target_field = bugs.bug_id
INNER JOIN bug_status ON bugs.bug_status = bug_status.value
- WHERE $myfield = ?
- ORDER BY is_open DESC, $targetfield",
- undef, $bug_id);
- return $list_ref;
+ WHERE $my_field = ? $is_open_clause
+ ORDER BY is_open DESC, $target_field");
+
+ return $dbh->selectcol_arrayref(
+ $cache->{"${target_field}_sth_$exclude_resolved"},
+ undef, $bug_id);
}
# Creates a lot of bug objects in the same order as the input array.
sub _bugs_in_order {
my ($self, $bug_ids) = @_;
- my $bugs = $self->new_from_list($bug_ids);
- my %bug_map = map { $_->id => $_ } @$bugs;
- my @result = map { $bug_map{$_} } @$bug_ids;
- return \@result;
+ my %bug_map;
+ # there's no need to load bugs from the database if they are already in the
+ # object-cache
+ my @missing_ids;
+ foreach my $bug_id (@$bug_ids) {
+ if (my $bug = Bugzilla::Bug->object_cache_get($bug_id)) {
+ $bug_map{$bug_id} = $bug;
+ }
+ else {
+ push @missing_ids, $bug_id;
+ }
+ }
+ my $bugs = $self->new_from_list(\@missing_ids);
+ foreach my $bug (@$bugs) {
+ $bug_map{$bug->id} = $bug;
+ }
+ return [ map { $bug_map{$_} } @$bug_ids ];
}
# Get the activity of a bug, starting from $starttime (if given).
# This routine assumes Bugzilla::Bug->check has been previously called.
sub GetBugActivity {
- my ($bug_id, $attach_id, $starttime) = @_;
+ my ($bug_id, $attach_id, $starttime, $include_comment_tags) = @_;
my $dbh = Bugzilla->dbh;
# Arguments passed to the SQL query.
@@ -3720,7 +4003,7 @@ sub GetBugActivity {
if (defined $starttime) {
trick_taint($starttime);
push (@args, $starttime);
- $datepart = "AND bugs_activity.bug_when > ?";
+ $datepart = "AND bug_when > ?";
}
my $attachpart = "";
@@ -3741,7 +4024,7 @@ sub GetBugActivity {
my $query = "SELECT fielddefs.name, bugs_activity.attach_id, " .
$dbh->sql_date_format('bugs_activity.bug_when', '%Y.%m.%d %H:%i:%s') .
- ", bugs_activity.removed, bugs_activity.added, profiles.login_name,
+ " AS bug_when, bugs_activity.removed, bugs_activity.added, profiles.login_name,
bugs_activity.comment_id
FROM bugs_activity
$suppjoins
@@ -3752,8 +4035,42 @@ sub GetBugActivity {
WHERE bugs_activity.bug_id = ?
$datepart
$attachpart
- $suppwhere
- ORDER BY bugs_activity.bug_when";
+ $suppwhere ";
+
+ if (Bugzilla->params->{'comment_taggers_group'}
+ && $include_comment_tags
+ && !$attach_id)
+ {
+ # Only includes comment tag activity for comments the user is allowed to see.
+ $suppjoins = "";
+ $suppwhere = "";
+ if (!Bugzilla->user->is_insider) {
+ $suppjoins = "INNER JOIN longdescs
+ ON longdescs.comment_id = longdescs_tags_activity.comment_id";
+ $suppwhere = "AND longdescs.isprivate = 0";
+ }
+
+ $query .= "
+ UNION ALL
+ SELECT 'comment_tag' AS name,
+ NULL AS attach_id," .
+ $dbh->sql_date_format('longdescs_tags_activity.bug_when', '%Y.%m.%d %H:%i:%s') . " AS bug_when,
+ longdescs_tags_activity.removed,
+ longdescs_tags_activity.added,
+ profiles.login_name,
+ longdescs_tags_activity.comment_id as comment_id
+ FROM longdescs_tags_activity
+ INNER JOIN profiles ON profiles.userid = longdescs_tags_activity.who
+ $suppjoins
+ WHERE longdescs_tags_activity.bug_id = ?
+ $datepart
+ $suppwhere
+ ";
+ push @args, $bug_id;
+ push @args, $starttime if defined $starttime;
+ }
+
+ $query .= "ORDER BY bug_when, comment_id";
my $list = $dbh->selectall_arrayref($query, undef, @args);
@@ -3808,16 +4125,29 @@ sub GetBugActivity {
$changes = [];
}
+ # If this is the same field as the previoius item, then concatenate
+ # the data into the same change.
+ if ($operation->{'who'} && $who eq $operation->{'who'}
+ && $when eq $operation->{'when'}
+ && $fieldname eq $operation->{'fieldname'}
+ && ($comment_id || 0) == ($operation->{'comment_id'} || 0)
+ && ($attachid || 0) == ($operation->{'attachid'} || 0))
+ {
+ my $old_change = pop @$changes;
+ $removed = _join_activity_entries($fieldname, $old_change->{'removed'}, $removed);
+ $added = _join_activity_entries($fieldname, $old_change->{'added'}, $added);
+ }
+
$operation->{'who'} = $who;
$operation->{'when'} = $when;
+ $operation->{'fieldname'} = $change{'fieldname'} = $fieldname;
+ $operation->{'attachid'} = $change{'attachid'} = $attachid;
- $change{'fieldname'} = $fieldname;
- $change{'attachid'} = $attachid;
$change{'removed'} = $removed;
$change{'added'} = $added;
-
+
if ($comment_id) {
- $change{'comment'} = Bugzilla::Comment->new($comment_id);
+ $operation->{comment_id} = $change{'comment'} = Bugzilla::Comment->new($comment_id);
}
push (@$changes, \%change);
@@ -3832,9 +4162,40 @@ sub GetBugActivity {
return(\@operations, $incomplete_data);
}
+sub _join_activity_entries {
+ my ($field, $current_change, $new_change) = @_;
+ # We need to insert characters as these were removed by old
+ # LogActivityEntry code.
+
+ return $new_change if $current_change eq '';
+
+ # Buglists and see_also need the comma restored
+ if ($field eq 'dependson' || $field eq 'blocked' || $field eq 'see_also') {
+ if (substr($new_change, 0, 1) eq ',' || substr($new_change, 0, 1) eq ' ') {
+ return $current_change . $new_change;
+ } else {
+ return $current_change . ', ' . $new_change;
+ }
+ }
+
+ # Assume bug_file_loc contain a single url, don't insert a delimiter
+ if ($field eq 'bug_file_loc') {
+ return $current_change . $new_change;
+ }
+
+ # All other fields get a space unless the first character of the second
+ # string is a comma or space
+ if (substr($new_change, 0, 1) eq ',' || substr($new_change, 0, 1) eq ' ') {
+ return $current_change . $new_change;
+ } else {
+ return $current_change . ' ' . $new_change;
+ }
+}
+
# Update the bugs_activity table to reflect changes made in bugs.
sub LogActivityEntry {
- my ($i, $col, $removed, $added, $whoid, $timestamp, $comment_id) = @_;
+ my ($i, $col, $removed, $added, $whoid, $timestamp, $comment_id,
+ $attach_id) = @_;
my $dbh = Bugzilla->dbh;
# in the case of CCs, deps, and keywords, there's a possibility that someone
# might try to add or remove a lot of them at once, which might take more
@@ -3846,7 +4207,6 @@ sub LogActivityEntry {
my $commaposition = find_wrap_point($removed, MAX_LINE_LENGTH);
$removestr = substr($removed, 0, $commaposition);
$removed = substr($removed, $commaposition);
- $removed =~ s/^[,\s]+//; # remove any comma or space
} else {
$removed = ""; # no more entries
}
@@ -3854,17 +4214,36 @@ sub LogActivityEntry {
my $commaposition = find_wrap_point($added, MAX_LINE_LENGTH);
$addstr = substr($added, 0, $commaposition);
$added = substr($added, $commaposition);
- $added =~ s/^[,\s]+//; # remove any comma or space
} else {
$added = ""; # no more entries
}
trick_taint($addstr);
trick_taint($removestr);
my $fieldid = get_field_id($col);
- $dbh->do("INSERT INTO bugs_activity
- (bug_id, who, bug_when, fieldid, removed, added, comment_id)
- VALUES (?, ?, ?, ?, ?, ?, ?)",
- undef, ($i, $whoid, $timestamp, $fieldid, $removestr, $addstr, $comment_id));
+ $dbh->do(
+ "INSERT INTO bugs_activity
+ (bug_id, who, bug_when, fieldid, removed, added, comment_id, attach_id)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
+ undef,
+ ($i, $whoid, $timestamp, $fieldid, $removestr, $addstr, $comment_id,
+ $attach_id));
+ }
+}
+
+# Update bug_user_last_visit table
+sub update_user_last_visit {
+ my ($self, $user, $last_visit_ts) = @_;
+ my $lv = Bugzilla::BugUserLastVisit->match({ bug_id => $self->id,
+ user_id => $user->id })->[0];
+
+ if ($lv) {
+ $lv->set(last_visit_ts => $last_visit_ts);
+ $lv->update;
+ }
+ else {
+ Bugzilla::BugUserLastVisit->create({ bug_id => $self->id,
+ user_id => $user->id,
+ last_visit_ts => $last_visit_ts });
}
}
@@ -3941,8 +4320,8 @@ sub check_can_change_field {
return 1;
}
- # Allow anyone to change comments.
- if ($field =~ /^longdesc/) {
+ # Allow anyone to change comments, or set flags
+ if ($field =~ /^longdesc/ || $field eq 'flagtypes.name') {
return 1;
}
@@ -4148,6 +4527,7 @@ sub _create_cf_accessors {
my $fields = Bugzilla->fields({ custom => 1 });
foreach my $field (@$fields) {
+ next if $field->type == FIELD_TYPE_EXTENSION;
my $accessor = $class->_accessor_for($field);
my $name = "${class}::" . $field->name;
{
@@ -4157,6 +4537,8 @@ sub _create_cf_accessors {
}
}
+ Bugzilla::Hook::process('bug_create_cf_accessors');
+
Bugzilla->request_cache->{"${class}_cf_accessors_created"} = 1;
}