From 9451fe4f8c5662127d53c23b6976ec5f203d0f0e Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Fri, 6 Sep 2013 12:43:59 -0400 Subject: Bug 913208 - Allow deleting of tracking flags that do not have bug values set but have activity entries in bugs_activity r=glob --- extensions/TrackingFlags/lib/Admin.pm | 1 - extensions/TrackingFlags/lib/Flag.pm | 19 ++++++++++++------- .../default/hook/global/user-error-errors.html.tmpl | 5 ----- .../default/pages/tracking_flags_admin_edit.html.tmpl | 4 ++-- 4 files changed, 14 insertions(+), 15 deletions(-) (limited to 'extensions/TrackingFlags') diff --git a/extensions/TrackingFlags/lib/Admin.pm b/extensions/TrackingFlags/lib/Admin.pm index 2796a102d..719b4f248 100644 --- a/extensions/TrackingFlags/lib/Admin.pm +++ b/extensions/TrackingFlags/lib/Admin.pm @@ -75,7 +75,6 @@ sub admin_edit { $vars->{flag} = $flag_obj; $vars->{values} = _flag_values_to_json($values); $vars->{visibility} = _flag_visibility_to_json($visibilities); - $vars->{can_delete} = !$flag_obj->bug_count; if ($vars->{mode} eq 'new') { $vars->{message} = 'tracking_flag_created'; diff --git a/extensions/TrackingFlags/lib/Flag.pm b/extensions/TrackingFlags/lib/Flag.pm index 26780a2b1..29f81669d 100644 --- a/extensions/TrackingFlags/lib/Flag.pm +++ b/extensions/TrackingFlags/lib/Flag.pm @@ -215,13 +215,6 @@ sub remove_from_db { my $self = shift; my $dbh = Bugzilla->dbh; - # Check to see if bug activity table has records - my $has_activity = $dbh->selectrow_array("SELECT COUNT(*) FROM bugs_activity - WHERE fieldid = ?", undef, $self->id); - if ($has_activity) { - ThrowUserError('tracking_flag_has_activity', { flag => $self }); - } - # Check to see if tracking_flags_bugs table has records if ($self->bug_count) { ThrowUserError('tracking_flag_has_contents', { flag => $self }); @@ -234,6 +227,7 @@ sub remove_from_db { eval { $dbh->bz_start_transaction(); + $dbh->do('DELETE FROM bugs_activity WHERE fieldid = ?', undef, $self->id); $dbh->do('DELETE FROM fielddefs WHERE name = ?', undef, $self->name); $dbh->bz_commit_transaction(); @@ -407,6 +401,17 @@ sub bug_count { undef, $self->flag_id); } +sub activity_count { + my ($self) = @_; + return $self->{'activity_count'} if defined $self->{'activity_count'}; + my $dbh = Bugzilla->dbh; + return $self->{'activity_count'} = scalar $dbh->selectrow_array(" + SELECT COUNT(bug_id) + FROM bugs_activity + WHERE fieldid = ?", + undef, $self->id); +} + ###################################### # Compatibility with Bugzilla::Field # ###################################### diff --git a/extensions/TrackingFlags/template/en/default/hook/global/user-error-errors.html.tmpl b/extensions/TrackingFlags/template/en/default/hook/global/user-error-errors.html.tmpl index 13f9980dc..7987c7d8d 100644 --- a/extensions/TrackingFlags/template/en/default/hook/global/user-error-errors.html.tmpl +++ b/extensions/TrackingFlags/template/en/default/hook/global/user-error-errors.html.tmpl @@ -54,11 +54,6 @@ [% title = "Invalid flag type" %] The flag type '[% type FILTER html %]' is invalid. -[% ELSIF error == "tracking_flag_has_activity" %] - [% title = "Tracking Flag Has Activity" %] - The tracking flag '[% flag.name FILTER html %]' cannot be deleted because - it has recorded activity. - [% ELSIF error == "tracking_flag_has_contents" %] [% title = "Tracking Flag Has Contents" %] The tracking flag '[% flag.name FILTER html %]' cannot be deleted because diff --git a/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_edit.html.tmpl b/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_edit.html.tmpl index 97a9e5a02..85915dbde 100644 --- a/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_edit.html.tmpl +++ b/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_edit.html.tmpl @@ -174,9 +174,9 @@ var selected_components = [
- [% IF can_delete %] + [% IF !flag.bug_count %] - [% END %]
-- cgit v1.2.3-24-g4f1b