From 8e808ffbf7b7b28a1cdfda3d188cc156a2e879d9 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Wed, 6 Sep 2006 02:18:26 +0000 Subject: Bug 351098: Make Bugzilla::Object able to update objects in the database, and make Bugzilla::Keyword use it Patch By Max Kanat-Alexander r=LpSolit, a=myk --- Bugzilla/Keyword.pm | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'Bugzilla/Keyword.pm') 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,15 +54,22 @@ 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; -- cgit v1.2.3-24-g4f1b