From 89349ea168f06c243b5fd1d3b7fff9b7532bf4d6 Mon Sep 17 00:00:00 2001 From: vfilippov Date: Tue, 16 Nov 2010 15:12:08 +0000 Subject: [PATCH] Bug 69481 - Log activity when renaming versions/milestones git-svn-id: svn://svn.office.custis.ru/3rdparty/bugzilla.org/trunk@1075 6955db30-a419-402b-8a0d-67ecbb4d7f56 --- Bugzilla/Component.pm | 2 ++ Bugzilla/Milestone.pm | 47 ++++++++++++++++++++++++++++++++++--------- Bugzilla/Product.pm | 4 +++- Bugzilla/Version.pm | 24 +++++++++++++++++----- 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/Bugzilla/Component.pm b/Bugzilla/Component.pm index 1a3e9d565..75245f074 100644 --- a/Bugzilla/Component.pm +++ b/Bugzilla/Component.pm @@ -160,6 +160,8 @@ sub run_create_validators sub update { my $self = shift; + # Bugzilla::Field::Choice is not a threat as we don't have 'value' field + # Yet do not call its update() for the future my $changes = Bugzilla::Object::update($self, @_); # Fill visibility values diff --git a/Bugzilla/Milestone.pm b/Bugzilla/Milestone.pm index 762daf5a1..4d1c019f9 100644 --- a/Bugzilla/Milestone.pm +++ b/Bugzilla/Milestone.pm @@ -120,21 +120,50 @@ sub create return $self; } +sub update +{ + my $self = shift; + + my $dbh = Bugzilla->dbh; + $dbh->bz_start_transaction(); + + # Not Bugzilla::Field::Choice! It will overwrite other products' bug values + my ($changes, $old_self) = Bugzilla::Object::update($self, @_); + + if (exists $changes->{value}) + { + # Record activity + $dbh->do( + 'INSERT INTO bugs_activity (bug_id, who, bug_when, fieldid, added, removed)'. + ' SELECT bug_id, ?, NOW(), ?, ?, ? FROM bugs WHERE target_milestone = ? AND product_id = ?', undef, + Bugzilla->user->id, $self->field->id, $self->name, $changes->{value}->[0], $changes->{value}->[0], $self->product_id + ); + # The milestone value is stored in the bugs table instead of its ID. + $dbh->do( + 'UPDATE bugs SET target_milestone = ? WHERE target_milestone = ? AND product_id = ?', + undef, $self->name, $changes->{value}->[0], $self->product_id + ); + # The default milestone also stores the value instead of the ID. + $dbh->do( + 'UPDATE products SET defaultmilestone = ? WHERE id = ? AND defaultmilestone = ?', + undef, $self->name, $self->product_id, $changes->{value}->[0] + ); + } + + # Fill visibility values + $self->set_visibility_values([ $self->product_id ]); + $dbh->bz_commit_transaction(); + + return $changes; +} + + sub update { my $self = shift; my $changes = Bugzilla::Object::update($self, @_); if (exists $changes->{value}) { my $dbh = Bugzilla->dbh; - # The milestone value is stored in the bugs table instead of its ID. - $dbh->do('UPDATE bugs SET target_milestone = ? - WHERE target_milestone = ? AND product_id = ?', - undef, ($self->name, $changes->{value}->[0], $self->product_id)); - - # The default milestone also stores the value instead of the ID. - $dbh->do('UPDATE products SET defaultmilestone = ? - WHERE id = ? AND defaultmilestone = ?', - undef, ($self->name, $self->product_id, $changes->{value}->[0])); } # Fill visibility values diff --git a/Bugzilla/Product.pm b/Bugzilla/Product.pm index 0a1c6b87f..c87155a4a 100644 --- a/Bugzilla/Product.pm +++ b/Bugzilla/Product.pm @@ -181,7 +181,9 @@ sub update { # Don't update the DB if something goes wrong below -> transaction. $dbh->bz_start_transaction(); - my ($changes, $old_self) = $self->SUPER::update(@_); + # Bugzilla::Field::Choice is not a threat as we don't have 'value' field + # Yet do not call its update() for the future + my ($changes, $old_self) = Bugzilla::Object::update(@_); # We also have to fix votes. my @msgs; # Will store emails to send to voters. diff --git a/Bugzilla/Version.pm b/Bugzilla/Version.pm index 902574eec..0523b8c6f 100644 --- a/Bugzilla/Version.pm +++ b/Bugzilla/Version.pm @@ -144,17 +144,31 @@ sub create sub update { my $self = shift; + + my $dbh = Bugzilla->dbh; + $dbh->bz_start_transaction(); + + # Not Bugzilla::Field::Choice! It will overwrite other products' bug values my ($changes, $old_self) = Bugzilla::Object::update($self, @_); - if (exists $changes->{value}) { - my $dbh = Bugzilla->dbh; - $dbh->do('UPDATE bugs SET version = ? - WHERE version = ? AND product_id = ?', - undef, ($self->name, $old_self->name, $self->product_id)); + if (exists $changes->{value}) + { + # Record activity + $dbh->do( + 'INSERT INTO bugs_activity (bug_id, who, bug_when, fieldid, added, removed)'. + ' SELECT bug_id, ?, NOW(), ?, ?, ? FROM bugs WHERE version = ? AND product_id = ?', undef, + Bugzilla->user->id, $self->field->id, $self->name, $old_self->name, $old_self->name, $self->product_id + ); + # Rename version + $dbh->do( + 'UPDATE bugs SET version = ? WHERE version = ? AND product_id = ?', + undef, $self->name, $old_self->name, $self->product_id + ); } # Fill visibility values $self->set_visibility_values([ $self->product_id ]); + $dbh->bz_commit_transaction(); return $changes; }