summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Keyword.pm
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 /Bugzilla/Keyword.pm
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 'Bugzilla/Keyword.pm')
-rw-r--r--Bugzilla/Keyword.pm40
1 files changed, 29 insertions, 11 deletions
diff --git a/Bugzilla/Keyword.pm b/Bugzilla/Keyword.pm
index fead77821..2152b338d 100644
--- a/Bugzilla/Keyword.pm
+++ b/Bugzilla/Keyword.pm
@@ -42,6 +42,11 @@ use constant VALIDATORS => {
description => \&_check_description,
};
+use constant UPDATE_COLUMNS => qw(
+ name
+ description
+);
+
###############################
#### Accessors ######
###############################
@@ -49,16 +54,23 @@ use constant VALIDATORS => {
sub description { return $_[0]->{'description'}; }
sub bug_count {
- ($_[0]->{'bug_count'}) ||=
- Bugzilla->dbh->selectrow_array('SELECT COUNT(keywords.bug_id) AS bug_count
- FROM keyworddefs
- LEFT JOIN keywords
- ON keyworddefs.id = keywords.keywordid
- WHERE keyworddefs.id=?', undef, ($_[0]->id));
- return $_[0]->{'bug_count'};
+ my ($self) = @_;
+ return $self->{'bug_count'} if defined $self->{'bug_count'};
+ ($self->{'bug_count'}) =
+ Bugzilla->dbh->selectrow_array(
+ 'SELECT COUNT(*) FROM keywords WHERE keywordid = ?',
+ undef, $self->id);
+ return $self->{'bug_count'};
}
###############################
+#### Mutators #####
+###############################
+
+sub set_name { $_[0]->set('name', $_[1]); }
+sub set_description { $_[0]->set('description', $_[1]); }
+
+###############################
#### Subroutines ######
###############################
@@ -96,20 +108,26 @@ sub get_all_with_bug_count {
###############################
sub _check_name {
- my ($name) = @_;
+ my ($self, $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;
+
+ # We only want to validate the non-existence of the name if
+ # we're creating a new Keyword or actually renaming the keyword.
+ if (!ref($self) || $self->name ne $name) {
+ my $keyword = new Bugzilla::Keyword({ name => $name });
+ ThrowUserError("keyword_already_exists", { name => $name }) if $keyword;
+ }
return $name;
}
sub _check_description {
- my ($desc) = @_;
+ my ($self, $desc) = @_;
$desc = trim($desc);
$desc eq '' && ThrowUserError("keyword_blank_description");
return $desc;