From 91986ae4f25eed69862b8d0b5f176e84339c6052 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Fri, 11 Aug 2006 00:53:07 +0000 Subject: Bug 347061: Create Bugzilla::Object->create and make Bugzilla::Keyword use it Patch By Max Kanat-Alexander r=bkor, a=myk --- Bugzilla/Keyword.pm | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'Bugzilla/Keyword.pm') diff --git a/Bugzilla/Keyword.pm b/Bugzilla/Keyword.pm index 2e0f19f4c..fead77821 100644 --- a/Bugzilla/Keyword.pm +++ b/Bugzilla/Keyword.pm @@ -20,6 +20,9 @@ package Bugzilla::Keyword; use base qw(Bugzilla::Object); +use Bugzilla::Error; +use Bugzilla::Util; + ############################### #### Initialization #### ############################### @@ -32,6 +35,13 @@ use constant DB_COLUMNS => qw( use constant DB_TABLE => 'keyworddefs'; +use constant REQUIRED_CREATE_FIELDS => qw(name description); + +use constant VALIDATORS => { + name => \&_check_name, + description => \&_check_description, +}; + ############################### #### Accessors ###### ############################### @@ -81,6 +91,30 @@ sub get_all_with_bug_count { return $keywords; } +############################### +### Validators ### +############################### + +sub _check_name { + my ($name) = @_; + $name = trim($name); + $name eq "" && ThrowUserError("keyword_blank_name"); + if ($name =~ /[\s,]/) { + ThrowUserError("keyword_invalid_name"); + } + my $keyword = new Bugzilla::Keyword({ name => $name }); + ThrowUserError("keyword_already_exists", { name => $name }) if $keyword; + + return $name; +} + +sub _check_description { + my ($desc) = @_; + $desc = trim($desc); + $desc eq '' && ThrowUserError("keyword_blank_description"); + return $desc; +} + 1; __END__ -- cgit v1.2.3-24-g4f1b