summaryrefslogtreecommitdiffstats
path: root/editkeywords.cgi
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2006-08-11 02:53:07 +0200
committermkanat%bugzilla.org <>2006-08-11 02:53:07 +0200
commit91986ae4f25eed69862b8d0b5f176e84339c6052 (patch)
treeb407cef033d75245170e635d95bd7ba40caa4eea /editkeywords.cgi
parent84c1e818ec0e777390042ab89cce496cdc7358a9 (diff)
downloadbugzilla-91986ae4f25eed69862b8d0b5f176e84339c6052.tar.gz
bugzilla-91986ae4f25eed69862b8d0b5f176e84339c6052.tar.xz
Bug 347061: Create Bugzilla::Object->create and make Bugzilla::Keyword use it
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=bkor, a=myk
Diffstat (limited to 'editkeywords.cgi')
-rwxr-xr-xeditkeywords.cgi62
1 files changed, 5 insertions, 57 deletions
diff --git a/editkeywords.cgi b/editkeywords.cgi
index 7b906c30b..7b94dbbe3 100755
--- a/editkeywords.cgi
+++ b/editkeywords.cgi
@@ -34,25 +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;
@@ -102,49 +83,16 @@ if ($action eq 'add') {
#
# action='new' -> add keyword entered in the 'action=add' screen
#
-
if ($action eq 'new') {
- # Cleanups and validity checks
-
- my $name = trim($cgi->param('name') || '');
- my $description = trim($cgi->param('description') || '');
-
- Validate($name, $description);
-
- my $id = $dbh->selectrow_array('SELECT id FROM keyworddefs
- WHERE name = ?', undef, $name);
-
- if ($id) {
- $vars->{'name'} = $name;
- ThrowUserError("keyword_already_exists", $vars);
- }
-
-
- # Pick an unused number. Be sure to recycle numbers that may have been
- # deleted in the past. This code is potentially slow, but it happens
- # rarely enough, and there really aren't ever going to be that many
- # keywords anyway.
-
- my $existing_ids =
- $dbh->selectcol_arrayref('SELECT id FROM keyworddefs ORDER BY id');
+ my $name = $cgi->param('name') || '';
+ my $desc = $cgi->param('description') || '';
- my $newid = 1;
-
- foreach my $oldid (@$existing_ids) {
- if ($oldid > $newid) {
- last;
- }
- $newid = $oldid + 1;
- }
-
- # Add the new keyword.
- $dbh->do('INSERT INTO keyworddefs
- (id, name, description) VALUES (?, ?, ?)',
- undef, ($newid, $name, $description));
+ my $keyword = Bugzilla::Keyword->create(
+ { name => $name, description => $desc });
print $cgi->header();
- $vars->{'name'} = $name;
+ $vars->{'name'} = $keyword->name;
$template->process("admin/keywords/created.html.tmpl", $vars)
|| ThrowTemplateError($template->error());