summaryrefslogtreecommitdiffstats
path: root/editkeywords.cgi
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2006-09-06 04:18:26 +0200
committermkanat%bugzilla.org <>2006-09-06 04:18:26 +0200
commit8e808ffbf7b7b28a1cdfda3d188cc156a2e879d9 (patch)
treecf2d348aa912d94dd8e3fd665deb0b616313d07d /editkeywords.cgi
parent40ee28bac9e9524eeaaa52f48cc24c950b918d1e (diff)
downloadbugzilla-8e808ffbf7b7b28a1cdfda3d188cc156a2e879d9.tar.gz
bugzilla-8e808ffbf7b7b28a1cdfda3d188cc156a2e879d9.tar.xz
Bug 351098: Make Bugzilla::Object able to update objects in the database, and make Bugzilla::Keyword use it
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=myk
Diffstat (limited to 'editkeywords.cgi')
-rwxr-xr-xeditkeywords.cgi111
1 files changed, 21 insertions, 90 deletions
diff --git a/editkeywords.cgi b/editkeywords.cgi
index f2403c372..bf130768e 100755
--- a/editkeywords.cgi
+++ b/editkeywords.cgi
@@ -34,34 +34,6 @@ my $dbh = Bugzilla->dbh;
my $template = Bugzilla->template;
my $vars = {};
-sub Validate {
- my ($name, $description) = @_;
- if ($name eq "") {
- ThrowUserError("keyword_blank_name");
- }
- if ($name =~ /[\s,]/) {
- ThrowUserError("keyword_invalid_name");
- }
- if ($description eq "") {
- ThrowUserError("keyword_blank_description");
- }
- # It is safe to detaint these values as they are only
- # used in placeholders.
- trick_taint($name);
- $_[0] = $name;
- trick_taint($description);
- $_[1] = $description;
-}
-
-sub ValidateKeyID {
- my $id = shift;
-
- $id = trim($id || 0);
- detaint_natural($id) || ThrowCodeError('invalid_keyword_id');
- return $id;
-}
-
-
#
# Preliminary checks:
#
@@ -75,7 +47,8 @@ $user->in_group('editkeywords')
action => "edit",
object => "keywords"});
-my $action = trim($cgi->param('action') || '');
+my $action = trim($cgi->param('action') || '');
+my $key_id = $cgi->param('id');
$vars->{'action'} = $action;
@@ -127,32 +100,14 @@ if ($action eq 'new') {
#
if ($action eq 'edit') {
- my $id = ValidateKeyID(scalar $cgi->param('id'));
-
- # get data of keyword
- my ($name, $description) =
- $dbh->selectrow_array('SELECT name, description FROM keyworddefs
- WHERE id = ?', undef, $id);
-
- if (!$name) {
- $vars->{'id'} = $id;
- ThrowCodeError("invalid_keyword_id", $vars);
- }
-
- my $bugs = $dbh->selectrow_array('SELECT COUNT(*) FROM keywords
- WHERE keywordid = ?',
- undef, $id);
+ my $keyword = new Bugzilla::Keyword($key_id)
+ || ThrowCodeError('invalid_keyword_id', { id => $key_id });
- $vars->{'keyword_id'} = $id;
- $vars->{'name'} = $name;
- $vars->{'description'} = $description;
- $vars->{'bug_count'} = $bugs;
+ $vars->{'keyword'} = $keyword;
print $cgi->header();
-
$template->process("admin/keywords/edit.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
-
exit;
}
@@ -162,27 +117,16 @@ if ($action eq 'edit') {
#
if ($action eq 'update') {
- my $id = ValidateKeyID(scalar $cgi->param('id'));
-
- my $name = trim($cgi->param('name') || '');
- my $description = trim($cgi->param('description') || '');
+ my $keyword = new Bugzilla::Keyword($key_id)
+ || ThrowCodeError('invalid_keyword_id', { id => $key_id });
- Validate($name, $description);
-
- my $tmp = $dbh->selectrow_array('SELECT id FROM keyworddefs
- WHERE name = ?', undef, $name);
-
- if ($tmp && $tmp != $id) {
- $vars->{'name'} = $name;
- ThrowUserError("keyword_already_exists", $vars);
- }
-
- $dbh->do('UPDATE keyworddefs SET name = ?, description = ?
- WHERE id = ?', undef, ($name, $description, $id));
+ $keyword->set_name($cgi->param('name'));
+ $keyword->set_description($cgi->param('description'));
+ $keyword->update();
print $cgi->header();
- $vars->{'name'} = $name;
+ $vars->{'keyword'} = $keyword;
$template->process("admin/keywords/rebuild-cache.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
@@ -191,36 +135,23 @@ if ($action eq 'update') {
if ($action eq 'delete') {
- my $id = ValidateKeyID(scalar $cgi->param('id'));
-
- my $name = $dbh->selectrow_array('SELECT name FROM keyworddefs
- WHERE id= ?', undef, $id);
-
- if (!$cgi->param('reallydelete')) {
- my $bugs = $dbh->selectrow_array('SELECT COUNT(*) FROM keywords
- WHERE keywordid = ?',
- undef, $id);
-
- if ($bugs) {
- $vars->{'bug_count'} = $bugs;
- $vars->{'keyword_id'} = $id;
- $vars->{'name'} = $name;
-
- print $cgi->header();
+ my $keyword = new Bugzilla::Keyword($key_id)
+ || ThrowCodeError('invalid_keyword_id', { id => $key_id });
- $template->process("admin/keywords/confirm-delete.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
+ $vars->{'keyword'} = $keyword;
- exit;
- }
+ if (!$cgi->param('reallydelete') && $keyword->bug_count) {
+ print $cgi->header();
+ $template->process("admin/keywords/confirm-delete.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ exit;
}
- $dbh->do('DELETE FROM keywords WHERE keywordid = ?', undef, $id);
- $dbh->do('DELETE FROM keyworddefs WHERE id = ?', undef, $id);
+ $dbh->do('DELETE FROM keywords WHERE keywordid = ?', undef, $keyword->id);
+ $dbh->do('DELETE FROM keyworddefs WHERE id = ?', undef, $keyword->id);
print $cgi->header();
- $vars->{'name'} = $name;
$template->process("admin/keywords/rebuild-cache.html.tmpl", $vars)
|| ThrowTemplateError($template->error());