summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--extensions/TrackingFlags/Extension.pm12
-rw-r--r--extensions/TrackingFlags/lib/Admin.pm19
-rw-r--r--extensions/TrackingFlags/lib/Flag.pm117
-rw-r--r--extensions/TrackingFlags/template/en/default/hook/global/messages-messages.html.tmpl11
-rw-r--r--extensions/TrackingFlags/template/en/default/hook/global/user-error-errors.html.tmpl10
-rw-r--r--extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_edit.html.tmpl12
6 files changed, 118 insertions, 63 deletions
diff --git a/extensions/TrackingFlags/Extension.pm b/extensions/TrackingFlags/Extension.pm
index 5a4b24611..fb7278420 100644
--- a/extensions/TrackingFlags/Extension.pm
+++ b/extensions/TrackingFlags/Extension.pm
@@ -101,7 +101,8 @@ sub db_schema_abstract_schema {
NOTNULL => 1,
REFERENCES => {
TABLE => 'fielddefs',
- COLUMN => 'id'
+ COLUMN => 'id',
+ DELETE => 'CASCADE'
}
},
name => {
@@ -262,6 +263,15 @@ sub db_schema_abstract_schema {
};
}
+sub install_update_db {
+ my $dbh = Bugzilla->dbh;
+ my $fk = $dbh->bz_fk_info('tracking_flags', 'field_id');
+ if ($fk and !defined $fk->{DELETE}) {
+ $fk->{DELETE} = 'CASCADE';
+ $dbh->bz_alter_fk('tracking_flags', 'field_id', $fk);
+ }
+}
+
sub active_custom_fields {
my ($self, $args) = @_;
my $fields = $args->{'fields'};
diff --git a/extensions/TrackingFlags/lib/Admin.pm b/extensions/TrackingFlags/lib/Admin.pm
index 9e8b33b43..3529d30a7 100644
--- a/extensions/TrackingFlags/lib/Admin.pm
+++ b/extensions/TrackingFlags/lib/Admin.pm
@@ -55,8 +55,15 @@ sub admin_edit {
|| ThrowCodeError('tracking_flags_invalid_item_id', { item => 'flag', id => $vars->{flag_id} });
$flag->remove_from_db();
- $vars->{mode} = 'deleted';
- $vars->{flag_name} = $flag->name;
+ $vars->{message} = 'tracking_flag_deleted';
+ $vars->{flag} = $flag;
+ $vars->{flags} = [ Bugzilla::Extension::TrackingFlags::Flag->get_all() ];
+
+ print Bugzilla->cgi->header;
+ my $template = Bugzilla->template;
+ $template->process('pages/tracking_flags_admin_list.html.tmpl', $vars)
+ || ThrowTemplateError($template->error());
+ exit;
} elsif ($input->{save}) {
# save
@@ -68,12 +75,12 @@ 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->has_values;
+ $vars->{can_delete} = !$flag_obj->has_bug_values;
if ($vars->{mode} eq 'new') {
- $vars->{message} = 'tracking_flags_created';
+ $vars->{message} = 'tracking_flag_created';
} else {
- $vars->{message} = 'tracking_flags_updated';
+ $vars->{message} = 'tracking_flag_updated';
}
} else {
@@ -86,7 +93,7 @@ sub admin_edit {
$vars->{flag} = $flag;
$vars->{values} = _flag_values_to_json($flag->values);
$vars->{visibility} = _flag_visibility_to_json($flag->visibility);
- $vars->{can_delete} = !$flag->has_values;
+ $vars->{can_delete} = !$flag->has_bug_values;
} elsif ($vars->{mode} eq 'copy') {
# copy - load the source flag
diff --git a/extensions/TrackingFlags/lib/Flag.pm b/extensions/TrackingFlags/lib/Flag.pm
index 5daa47508..54b2afcf7 100644
--- a/extensions/TrackingFlags/lib/Flag.pm
+++ b/extensions/TrackingFlags/lib/Flag.pm
@@ -15,6 +15,7 @@ use warnings;
use Bugzilla::Error;
use Bugzilla::Constants;
use Bugzilla::Util qw(detaint_natural trim);
+use Bugzilla::Config qw(SetParam write_params);
use Bugzilla::Extension::TrackingFlags::Constants;
use Bugzilla::Extension::TrackingFlags::Flag::Bug;
@@ -87,35 +88,46 @@ sub create {
my $class = shift;
my $params = shift;
my $dbh = Bugzilla->dbh;
-
- $dbh->bz_start_transaction();
-
- $params = $class->run_create_validators($params);
-
- # We have to create an entry for this new flag
- # in the fielddefs table for use elsewhere. We cannot
- # use Bugzilla::Field->create as it will create the
- # additional tables needed by custom fields which we
- # do not need. Also we do this so as not to add a
- # another column to the bugs table.
- # We will create the entry as a custom field with a
- # type of FIELD_TYPE_EXTENSION so Bugzilla will skip
- # these field types in certain parts of the core code.
- $dbh->do("INSERT INTO fielddefs
- (name, description, sortkey, type, custom, obsolete, buglist)
- VALUES
- (?, ?, ?, ?, ?, ?, ?)",
- undef,
- $params->{'name'},
- $params->{'description'},
- $params->{'sortkey'},
- FIELD_TYPE_EXTENSION,
- 1, 0, 1);
- $params->{'field_id'} = $dbh->bz_last_key;
-
- my $flag = $class->SUPER::create($params);
-
- $dbh->bz_commit_transaction();
+ my $flag;
+
+ # Disable bug updates temporarily to avoid conflicts.
+ SetParam('disable_bug_updates', 1);
+ write_params();
+
+ eval {
+ $dbh->bz_start_transaction();
+
+ $params = $class->run_create_validators($params);
+
+ # We have to create an entry for this new flag
+ # in the fielddefs table for use elsewhere. We cannot
+ # use Bugzilla::Field->create as it will create the
+ # additional tables needed by custom fields which we
+ # do not need. Also we do this so as not to add a
+ # another column to the bugs table.
+ # We will create the entry as a custom field with a
+ # type of FIELD_TYPE_EXTENSION so Bugzilla will skip
+ # these field types in certain parts of the core code.
+ $dbh->do("INSERT INTO fielddefs
+ (name, description, sortkey, type, custom, obsolete, buglist)
+ VALUES
+ (?, ?, ?, ?, ?, ?, ?)",
+ undef,
+ $params->{'name'},
+ $params->{'description'},
+ $params->{'sortkey'},
+ FIELD_TYPE_EXTENSION,
+ 1, 0, 1);
+ $params->{'field_id'} = $dbh->bz_last_key;
+
+ $flag = $class->SUPER::create($params);
+
+ $dbh->bz_commit_transaction();
+ };
+ my $error = "$@";
+ SetParam('disable_bug_updates', 0);
+ write_params();
+ die $error if $error;
return $flag;
}
@@ -197,16 +209,40 @@ sub get_all {
sub remove_from_db {
my $self = shift;
my $dbh = Bugzilla->dbh;
- $dbh->bz_start_transaction();
- $dbh->do('DELETE FROM fielddefs WHERE name = ?', undef, $self->name);
- $self->SUPER::remove_from_db(@_);
- $dbh->bz_commit_transaction();
- # Remove from request cache
- my $cache = Bugzilla->request_cache;
- if (exists $cache->{'tracking_flags'}) {
- delete $cache->{'tracking_flags'}->{$self->flag_id};
+ # 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->has_bug_values) {
+ ThrowUserError('tracking_flag_has_contents', { flag => $self });
}
+
+ # Disable bug updates temporarily to avoid conflicts.
+ SetParam('disable_bug_updates', 1);
+ write_params();
+
+ eval {
+ $dbh->bz_start_transaction();
+
+ $dbh->do('DELETE FROM fielddefs WHERE name = ?', undef, $self->name);
+
+ $dbh->bz_commit_transaction();
+
+ # Remove from request cache
+ my $cache = Bugzilla->request_cache;
+ if (exists $cache->{'tracking_flags'}) {
+ delete $cache->{'tracking_flags'}->{$self->flag_id};
+ }
+ };
+ my $error = "$@";
+ SetParam('disable_bug_updates', 0);
+ write_params();
+ die $error if $error;
}
sub preload_all_the_things {
@@ -355,17 +391,16 @@ sub bug_flag {
return $self->{'bug_flag'} = Bugzilla::Extension::TrackingFlags::Flag::Bug->new($params);
}
-sub has_values {
+sub has_bug_values {
my ($self) = @_;
- return $self->{'has_values'} if defined $self->{'has_values'};
+ return $self->{'has_bug_values'} if defined $self->{'has_bug_values'};
my $dbh = Bugzilla->dbh;
- $self->{'has_values'} = scalar $dbh->selectrow_array("
+ return $self->{'has_bug_values'} = scalar $dbh->selectrow_array("
SELECT 1
FROM tracking_flags_bugs
WHERE tracking_flag_id = ? " .
$dbh->sql_limit(1),
undef, $self->flag_id);
- return $self->{'has_values'};
}
######################################
diff --git a/extensions/TrackingFlags/template/en/default/hook/global/messages-messages.html.tmpl b/extensions/TrackingFlags/template/en/default/hook/global/messages-messages.html.tmpl
index 45bb7332c..ce254b8cc 100644
--- a/extensions/TrackingFlags/template/en/default/hook/global/messages-messages.html.tmpl
+++ b/extensions/TrackingFlags/template/en/default/hook/global/messages-messages.html.tmpl
@@ -6,10 +6,13 @@
# defined by the Mozilla Public License, v. 2.0.
#%]
-[% IF message_tag == 'tracking_flags_created' %]
- The tracking flag has been created.
+[% IF message_tag == 'tracking_flag_created' %]
+ The tracking flag '[% flag.name FILTER html %]' has been created.
-[% ELSIF message_tag == 'tracking_flags_updated' %]
- The tracking flag has been updated.
+[% ELSIF message_tag == 'tracking_flag_updated' %]
+ The tracking flag '[% flag.name FILTER html %]' has been updated.
+
+[% ELSIF message_tag == "tracking_flag_deleted" %]
+ The tracking flag '[% flag.name FILTER html %]' has been deleted.
[% END %]
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 f17df1bdf..13f9980dc 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,4 +54,14 @@
[% 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
+ at least one [% terms.bug %] has a non empty value for this field.
+
[% END %]
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 d9f11fa2a..0c4a443f9 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
@@ -29,16 +29,6 @@ var selected_components = [
style_urls = [ 'extensions/TrackingFlags/web/styles/admin.css' ]
%]
-[% IF mode == 'deleted' %]
-
- <p>The tracking flag [% flag_name FILTER html %] has been deleted.</p>
- <hr>
- <p>Return to the <a href="page.cgi?id=tracking_flags_admin_list.html">list of Tracking Flags</a>.</p>
-
- [% RETURN %]
-
-[% END %]
-
<script>
var groups = [% groups || '[]' FILTER none %];
var flag_values = [% values || '[]' FILTER none %];
@@ -56,7 +46,7 @@ var selected_components = [
<form method="POST" action="page.cgi" onsubmit="return on_submit()">
<input type="hidden" name="id" value="tracking_flags_admin_edit.html">
<input type="hidden" name="mode" value="[% mode FILTER html %]">
-<input type="hidden" name="flag_id" value="[% mode == 'edit' ? flag.flag_id : 0 FILTER html %]">
+<input type="hidden" name="flag_id" value="[% flag ? flag.flag_id : 0 FILTER html %]">
<input type="hidden" name="values" id="values" value="">
<input type="hidden" name="visibility" id="visibility" value="">
<input type="hidden" name="save" value="1">