From d4f1fd5168130441b735497bac94810a3ccc34c3 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Wed, 6 Feb 2008 22:15:34 +0000 Subject: Bug 349369: Allow unused custom fields to be deleted from editfields.cgi - Patch by Alex Eiser r/a=LpSolit --- editfields.cgi | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'editfields.cgi') diff --git a/editfields.cgi b/editfields.cgi index 50564c190..138c6b729 100644 --- a/editfields.cgi +++ b/editfields.cgi @@ -117,6 +117,49 @@ elsif ($action eq 'update') { $template->process('admin/custom_fields/list.html.tmpl', $vars) || ThrowTemplateError($template->error()); } +elsif ($action eq 'del') { + my $name = $cgi->param('name'); + + # Validate field. + $name || ThrowUserError('field_missing_name'); + # Custom field names must start with "cf_". + if ($name !~ /^cf_/) { + $name = 'cf_' . $name; + } + my $field = new Bugzilla::Field({'name' => $name}); + $field || ThrowUserError('customfield_nonexistent', {'name' => $name}); + + $vars->{'field'} = $field; + $vars->{'token'} = issue_session_token('delete_field'); + + $template->process('admin/custom_fields/confirm-delete.html.tmpl', $vars) + || ThrowTemplateError($template->error()); +} +elsif ($action eq 'delete') { + check_token_data($token, 'delete_field'); + my $name = $cgi->param('name'); + + # Validate fields. + $name || ThrowUserError('field_missing_name'); + # Custom field names must start with "cf_". + if ($name !~ /^cf_/) { + $name = 'cf_' . $name; + } + my $field = new Bugzilla::Field({'name' => $name}); + $field || ThrowUserError('customfield_nonexistent', {'name' => $name}); + + # Calling remove_from_db will check if field can be deleted. + # If the field cannot be deleted, it will throw an error. + $field->remove_from_db(); + + $vars->{'field'} = $field; + $vars->{'message'} = 'custom_field_deleted'; + + delete_token($token); + + $template->process('admin/custom_fields/list.html.tmpl', $vars) + || ThrowTemplateError($template->error()); +} else { ThrowUserError('no_valid_action', {'field' => 'custom_field'}); } -- cgit v1.2.3-24-g4f1b