summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Keyword.pm
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 /Bugzilla/Keyword.pm
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 'Bugzilla/Keyword.pm')
-rw-r--r--Bugzilla/Keyword.pm34
1 files changed, 34 insertions, 0 deletions
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__