From 92c064fb79e9b1f7236ac82e1ed9724c65b95b5e Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sat, 7 Jul 2007 07:40:40 +0000 Subject: Bug 385379: Move dependency DB updating from process_bug into Bugzilla::Bug Patch By Max Kanat-Alexander r=LpSolit, a=LpSolit --- Bugzilla/Bug.pm | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'Bugzilla') diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 10c595d94..1f4ac606f 100755 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -505,6 +505,58 @@ sub update_cc { return ($removed_users, $added_users); } +# XXX Temporary hack until all of process_bug uses update() +sub update_dependencies { + # We need to send mail for dependson/blocked bugs if the dependencies + # change or the status or resolution change. This var keeps track of that. + my $check_dep_bugs = 0; + + my $self = shift; + + my $dbh = Bugzilla->dbh; + my $delta_ts = shift || $dbh->selectrow_array("SELECT NOW()"); + + my $old_bug = $self->new($self->id); + + my %changes; + foreach my $pair ([qw(dependson blocked)], [qw(blocked dependson)]) { + my ($type, $other) = @$pair; + my $old = $old_bug->$type; + my $new = $self->$type; + + my ($removed, $added) = diff_arrays($old, $new); + foreach my $removed_id (@$removed) { + $dbh->do("DELETE FROM dependencies WHERE $type = ? AND $other = ?", + undef, $removed_id, $self->id); + + # Add an activity entry for the other bug. + LogActivityEntry($removed_id, $other, $self->id, '', + Bugzilla->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); + } + foreach my $added_id (@$added) { + $dbh->do("INSERT INTO dependencies ($type, $other) VALUES (?,?)", + undef, $added_id, $self->id); + + # Add an activity entry for the other bug. + LogActivityEntry($added_id, $other, '', $self->id, + Bugzilla->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); + } + + LogActivityEntry($self->id, $type, join(', ', @$removed), + join(', ', @$added), Bugzilla->user->id, $delta_ts); + + $changes{$type} = [$removed, $added]; + } + + return \%changes; +} + # XXX Temporary hack until all of process_bug uses update() sub update_keywords { my $self = shift; @@ -1096,6 +1148,16 @@ sub fields { # "Set" Methods # ################# +sub set_dependencies { + my ($self, $dependson, $blocked) = @_; + ($dependson, $blocked) = $self->_check_dependencies($dependson, $blocked); + # These may already be detainted, but all setters are supposed to + # detaint their input if they've run a validator (just as though + # we had used Bugzilla::Object::set), so we do that here. + detaint_natural($_) foreach (@$dependson, @$blocked); + $self->{'dependson'} = $dependson; + $self->{'blocked'} = $blocked; +} sub _set_everconfirmed { $_[0]->set('everconfirmed', $_[1]); } sub set_resolution { $_[0]->set('resolution', $_[1]); } sub set_status { -- cgit v1.2.3-24-g4f1b