use strict;
-use vars qw($legal_keywords @legal_platform
+use vars qw(@legal_platform
@legal_priority @legal_severity @legal_opsys @legal_bug_status
@settable_resolution %components %target_milestone
@enterable_products %milestoneurl %prodmaxvotes);
return $self->{'show_attachment_flags'};
}
-
-sub use_keywords {
- return @::legal_keywords;
-}
-
sub use_votes {
my ($self) = @_;
return 0 if $self->{'error'};
longdescs milestoneurl attachments
isopened isunconfirmed
flag_types num_attachment_flag_types
- show_attachment_flags use_keywords any_flags_requesteeble),
+ show_attachment_flags any_flags_requesteeble),
# Bug fields.
Bugzilla::Bug->fields
--- /dev/null
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Bug Tracking System.
+#
+# Contributor(s): Max Kanat-Alexander <mkanat@bugzilla.org>
+
+use strict;
+
+package Bugzilla::Keyword;
+
+use Bugzilla::Util;
+use Bugzilla::Error;
+
+###############################
+#### Initialization ####
+###############################
+
+use constant DB_COLUMNS => qw(
+ keyworddefs.id
+ keyworddefs.name
+ keyworddefs.description
+);
+
+my $columns = join(", ", DB_COLUMNS);
+
+sub new {
+ my $invocant = shift;
+ my $class = ref($invocant) || $invocant;
+ my $self = {};
+ bless($self, $class);
+ return $self->_init(@_);
+}
+
+sub _init {
+ my $self = shift;
+ my ($param) = @_;
+ my $dbh = Bugzilla->dbh;
+
+ my $id = $param unless (ref $param eq 'HASH');
+ my $keyword;
+
+ if (defined $id) {
+ detaint_natural($id)
+ || ThrowCodeError('param_must_be_numeric',
+ {function => 'Bugzilla::Keyword::_init'});
+
+ $keyword = $dbh->selectrow_hashref(qq{
+ SELECT $columns FROM keyworddefs
+ WHERE id = ?}, undef, $id);
+ } elsif (defined $param->{'name'}) {
+ trick_taint($param->{'name'});
+ $keyword = $dbh->selectrow_hashref(qq{
+ SELECT $columns FROM keyworddefs
+ WHERE name = ?}, undef, $param->{'name'});
+ } else {
+ ThrowCodeError('bad_arg',
+ {argument => 'param',
+ function => 'Bugzilla::Keyword::_init'});
+ }
+
+ return undef unless (defined $keyword);
+
+ foreach my $field (keys %$keyword) {
+ $self->{$field} = $keyword->{$field};
+ }
+ return $self;
+}
+
+sub new_from_list {
+ my $class = shift;
+ my ($id_list) = @_;
+ my $dbh = Bugzilla->dbh;
+
+ my $keywords;
+ if ($id_list) {
+ my @detainted_ids;
+ foreach my $id (@$id_list) {
+ detaint_natural($id) ||
+ ThrowCodeError('param_must_be_numeric',
+ {function => 'Bugzilla::Keyword::new_from_list'});
+ push(@detainted_ids, $id);
+ }
+ $keywords = $dbh->selectall_arrayref(
+ "SELECT $columns FROM keyworddefs WHERE id IN ("
+ . join(',', @detainted_ids) . ")", {Slice=>{}}) || [];
+ } else {
+ ThrowCodeError('bad_arg',
+ {argument => 'id_list',
+ function => 'Bugzilla::Keyword::new_from_list'});
+ }
+
+ foreach my $keyword (@$keywords) {
+ bless($keyword, $class);
+ }
+ return $keywords;
+}
+
+###############################
+#### Accessors ######
+###############################
+
+sub id { return $_[0]->{'id'}; }
+sub name { return $_[0]->{'name'}; }
+sub description { return $_[0]->{'description'}; }
+
+###############################
+#### Subroutines ######
+###############################
+
+sub get_all_keywords {
+ my $dbh = Bugzilla->dbh;
+
+ my $ids = $dbh->selectcol_arrayref(q{
+ SELECT id FROM keyworddefs ORDER BY name});
+
+ my $keywords = Bugzilla::Keyword->new_from_list($ids);
+ return @$keywords;
+}
+
+sub keyword_count {
+ my ($count) =
+ Bugzilla->dbh->selectrow_array('SELECT COUNT(*) FROM keyworddefs');
+ return $count;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Bugzilla::Keyword - A Keyword that can be added to a bug.
+
+=head1 SYNOPSIS
+
+ use Bugzilla::Keyword;
+
+ my $keyword = new Bugzilla::Keyword(1);
+ my $keyword = new Bugzilla::Keyword({name => 'perf'});
+
+ my $id = $keyword->id;
+ my $name = $keyword->name;
+ my $description = $keyword->description;
+
+=head1 DESCRIPTION
+
+Bugzilla::Keyword represents a keyword that can be added to a bug.
+
+=head1 METHODS
+
+=over
+
+=item C<new($param)>
+
+ Description: The constructor is used to load an existing keyword
+ by passing a keyword id or a hash.
+
+ Params: $param - If you pass an integer, the integer is the
+ keyword id from the database that we want to
+ read in. If you pass in a hash with 'name' key,
+ then the value of the name key is the name of a
+ keyword from the DB.
+
+ Returns: A Bugzilla::Keyword object.
+
+=item C<new_from_list(\@id_list)>
+
+ Description: Creates an array of Keyword objects, given an
+ array of ids.
+
+ Params: \@id_list - A reference to an array of numbers, keyword ids.
+ If any of these are not numeric, the function
+ will throw an error. If any of these are not
+ valid keyword ids, they will simply be skipped.
+
+ Returns: A reference to an array of C<Bugzilla::Keyword> objects.
+
+=back
+
+=head1 SUBROUTINES
+
+=over
+
+=item C<get_all_keywords()>
+
+ Description: Returns all keywords from the database.
+
+ Params: none.
+
+ Returns: A list of C<Bugzilla::Keyword> objects,
+ or an empty list if there are none.
+
+=item C<keyword_count()>
+
+ Description: A utility function to get the total number
+ of keywords defined. Mostly used to see
+ if there are any keywords defined at all.
+ Params: none
+ Returns: An integer, the count of keywords.
+
+=back
+
+=cut
use Bugzilla::User;
use Bugzilla::Field;
use Bugzilla::Bug;
+use Bugzilla::Keyword;
use Date::Format;
use Date::Parse;
if ($value eq '') {
next;
}
- my $id = &::GetKeywordIdFromName($value);
- if ($id) {
- push(@list, "$table.keywordid = $id");
+ my $keyword = new Bugzilla::Keyword({name => $value});
+ if ($keyword) {
+ push(@list, "$table.keywordid = " . $keyword->id);
}
else {
ThrowUserError("unknown_keyword",
use Bugzilla::Config;
use Bugzilla::Error;
use Bugzilla::Constants;
+use Bugzilla::Keyword;
use Bugzilla::Bug;
use base qw(Exporter);
$word, $negate);
}
if (grep({lc($word) eq $_}
- @::legal_keywords)) {
+ map($_->name, Bugzilla::Keyword::get_all_keywords()))) {
addChart('keywords', 'substring',
$word, $negate);
if (length($word)>2) {
use Bugzilla::User;
use Bugzilla::Bug;
use Bugzilla::Product;
+use Bugzilla::Keyword;
# Include the Bugzilla CGI and general utility library.
require "globals.pl";
use vars qw(@components
- @legal_keywords
@legal_platform
@legal_priority
@legal_product
# The following variables are used when the user is making changes to multiple bugs.
if ($dotweak) {
$vars->{'dotweak'} = 1;
- $vars->{'use_keywords'} = 1 if @::legal_keywords;
+ $vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
$vars->{'products'} = Bugzilla->user->get_enterable_products;
$vars->{'platforms'} = \@::legal_platform;
use lib qw(.);
-use vars qw(
- @legal_keywords
-);
-
use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::User;
+use Bugzilla::Keyword;
require "globals.pl";
Bugzilla->login();
if (Param("usestatuswhiteboard")) {
push(@masterlist, "status_whiteboard");
}
-if (@::legal_keywords) {
+if (Bugzilla::Keyword::keyword_count()) {
push(@masterlist, "keywords");
}
require "globals.pl";
use Bugzilla;
use Bugzilla::Constants;
+use Bugzilla::Keyword;
use Bugzilla::Bug;
# Suppress "used only once" warnings.
@legal_components
@legal_target_milestone
- @legal_keywords
);
# Use the global template variables defined in globals.pl
$vars->{'severity'} = \@::legal_severity;
$vars->{'platform'} = \@::legal_platform;
$vars->{'op_sys'} = \@::legal_opsys;
-$vars->{'keyword'} = \@::legal_keywords;
+$vars->{'keyword'} = [map($_->name, Bugzilla::Keyword::get_all_keywords())];
$vars->{'resolution'} = \@::legal_resolution;
$vars->{'status'} = \@::legal_bug_status;
use Bugzilla::User;
use Bugzilla::Hook;
use Bugzilla::Product;
+use Bugzilla::Keyword;
require "globals.pl";
use vars qw(
@legal_platform
@legal_priority
@legal_severity
- @legal_keywords
%target_milestone
);
$vars->{'rep_platform'} = \@legal_platform;
$vars->{'op_sys'} = \@legal_opsys;
-$vars->{'use_keywords'} = 1 if (@::legal_keywords);
+$vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
$vars->{'assigned_to'} = formvalue('assigned_to');
$vars->{'assigned_to_disabled'} = !UserInGroup('editbugs');
sub globals_pl_sillyness {
my $zz;
$zz = @main::enterable_products;
- $zz = %main::keywordsbyname;
$zz = @main::legal_bug_status;
$zz = @main::legal_components;
- $zz = @main::legal_keywords;
$zz = @main::legal_opsys;
$zz = @main::legal_platform;
$zz = @main::legal_priority;
'*::milestoneurl']));
}
- SendSQL("SELECT id, name FROM keyworddefs ORDER BY name");
- while (MoreSQLData()) {
- my ($id, $name) = FetchSQLData();
- push(@::legal_keywords, $name);
- $name = lc($name);
- $::keywordsbyname{$name} = $id;
- }
-
- print $fh (Data::Dumper->Dump([\@::legal_keywords, \%::keywordsbyname],
- ['*::legal_keywords', '*::keywordsbyname']));
-
print $fh "1;\n";
close $fh;
}
-sub GetKeywordIdFromName {
- my ($name) = (@_);
- $name = lc($name);
- return $::keywordsbyname{$name};
-}
-
-
$::VersionTableLoaded = 0;
sub GetVersionTable {
return if $::VersionTableLoaded;
use Bugzilla::User;
use Bugzilla::Util;
use Bugzilla::Constants;
+use Bugzilla::Keyword;
use MIME::Base64;
use MIME::Parser;
);
foreach my $keyword ( split( /[\s,]+/, $bug_fields{'keywords'} )) {
next unless $keyword;
- my $i = GetKeywordIdFromName($keyword);
- if ( !$i ) {
+ my $keyword_obj = new Bugzilla::Keyword({name => $keyword});
+ if (!$keyword_obj) {
$err .= "Skipping unknown keyword: $keyword.\n";
next;
}
- if ( !$keywordseen{$i} ) {
- $key_sth->execute( $id, $i );
- $keywordseen{$i} = 1;
+ if (!$keywordseen{$keyword_obj->id}) {
+ $key_sth->execute($id, $keyword_obj->id);
+ $keywordseen{$keyword_obj->id} = 1;
}
}
my ($keywordarray) = $dbh->selectcol_arrayref(
use Bugzilla::User;
use Bugzilla::Field;
use Bugzilla::Product;
+use Bugzilla::Keyword;
# Shut up misguided -w warnings about "used only once". For some reason,
# "use vars" chokes on me when I try it here.
if ($keyword eq '') {
next;
}
- my $i = GetKeywordIdFromName($keyword);
- if (!$i) {
+ my $keyword_obj = new Bugzilla::Keyword({name => $keyword});
+ if (!$keyword_obj) {
ThrowUserError("unknown_keyword",
{ keyword => $keyword });
}
- if (!$keywordseen{$i}) {
- push(@keywordlist, $i);
- $keywordseen{$i} = 1;
+ if (!$keywordseen{$keyword_obj->id}) {
+ push(@keywordlist, $keyword_obj->id);
+ $keywordseen{$keyword_obj->id} = 1;
}
}
}
@bug_list = split(/:/, $cgi->cookie("BUGLIST"));
}
$vars->{'bug_list'} = \@bug_list;
+$vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
print $cgi->header();
$template->process("bug/create/created.html.tmpl", $vars)
use Bugzilla::Util;
use Bugzilla::Field;
use Bugzilla::Product;
+use Bugzilla::Keyword;
# Use the Flag module to modify flag data if the user set flags.
use Bugzilla::Flag;
my $dbh = Bugzilla->dbh;
my $template = Bugzilla->template;
my $vars = {};
+$vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
my $requiremilestone = 0;
if ($keyword eq '') {
next;
}
- my $i = GetKeywordIdFromName($keyword);
- if (!$i) {
+ my $keyword_obj = new Bugzilla::Keyword({name => $keyword});
+ if (!$keyword_obj) {
ThrowUserError("unknown_keyword",
{ keyword => $keyword });
}
- if (!$keywordseen{$i}) {
- push(@keywordlist, $i);
- $keywordseen{$i} = 1;
+ if (!$keywordseen{$keyword_obj->id}) {
+ push(@keywordlist, $keyword_obj->id);
+ $keywordseen{$keyword_obj->id} = 1;
}
}
}
if ($::comma eq ""
&& (! @groupAdd) && (! @groupDel)
- && (! @::legal_keywords || (0 == @keywordlist && $keywordaction ne "makeexact"))
+ && (!Bugzilla::Keyword::keyword_count()
+ || (0 == @keywordlist && $keywordaction ne "makeexact"))
&& defined $cgi->param('masscc') && ! $cgi->param('masscc')
) {
if (!defined $cgi->param('comment') || $cgi->param('comment') =~ /^\s*$/) {
$bug_changed = 1;
}
- if (@::legal_keywords && defined $cgi->param('keywords')) {
+ if (Bugzilla::Keyword::keyword_count()
+ && defined $cgi->param('keywords'))
+ {
# There are three kinds of "keywordsaction": makeexact, add, delete.
# For makeexact, we delete everything, and then add our things.
# For add, we delete things we're adding (to make sure we don't
use Bugzilla::Util;
use Bugzilla::Product;
use Bugzilla::Version;
+use Bugzilla::Keyword;
use vars qw(
@legal_resolution
@legal_bug_status
@legal_components
- @legal_keywords
@legal_opsys
@legal_platform
@legal_priority
$vars->{'target_milestone'} = \@milestones;
}
-$vars->{'have_keywords'} = scalar(@::legal_keywords);
+$vars->{'have_keywords'} = Bugzilla::Keyword::keyword_count();
push @::legal_resolution, "---"; # Oy, what a hack.
shift @::legal_resolution;
use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::User;
+use Bugzilla::Keyword;
require "globals.pl";
$vars->{'bugs'} = \@bugs;
$vars->{'marks'} = \%marks;
-$vars->{'use_keywords'} = 1 if (@::legal_keywords);
+$vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
# Next bug in list (if there is one)
my @bug_list;
</tr>
[% END %]
- [% IF bug.use_keywords %]
+ [% IF use_keywords %]
<tr>
<td align="right">
<b>