#### Subroutines ######
###############################
-sub keyword_count {
- my ($count) =
- Bugzilla->dbh->selectrow_array('SELECT COUNT(*) FROM keyworddefs');
- return $count;
-}
-
sub get_all_with_bug_count {
my $class = shift;
my $dbh = Bugzilla->dbh;
use Bugzilla::Keyword;
- my $count = Bugzilla::Keyword::keyword_count;
-
my $description = $keyword->description;
my $keywords = Bugzilla::Keyword->get_all_with_bug_count();
=over
-=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.
-
=item C<get_all_with_bug_count()>
Description: Returns all defined keywords. This is an efficient way
elsif ( $field eq 'WHERE' ) {
# the WHERE value is a hashref where the keys are
# "column_name operator ?" and values are the placeholder's
- # value.
- foreach my $k (keys( %$value )) {
- push( @terms, $k );
- push( @values, $value->{$k} );
+ # value (either a scalar or an array of values).
+ foreach my $k (keys %$value) {
+ push(@terms, $k);
+ my @this_value = ref($value->{$k}) ? @{ $value->{$k} }
+ : ($value->{$k});
+ push(@values, @this_value);
}
next;
}
-
+
if (ref $value eq 'ARRAY') {
# IN () is invalid SQL, and if we have an empty list
# to match against, we're just returning an empty
#### Subroutines ######
###############################
+sub any_exist {
+ my $class = shift;
+ my $table = $class->DB_TABLE;
+ my $dbh = Bugzilla->dbh;
+ my $any_exist = $dbh->selectrow_array(
+ "SELECT 1 FROM $table " . $dbh->sql_limit(1));
+ return $any_exist ? 1 : 0;
+}
+
sub create {
my ($class, $params) = @_;
my $dbh = Bugzilla->dbh;
=over
+=item C<any_exist>
+
+Returns C<1> if there are any of these objects in the database,
+C<0> otherwise.
+
=item C<get_all>
Description: Returns all objects in this table from the database.
use Bugzilla::Bug;
use Bugzilla::Constants;
use Bugzilla::Install::Requirements;
-use Bugzilla::Install::Util qw(install_string template_include_path include_languages);
+use Bugzilla::Install::Util qw(install_string template_include_path
+ include_languages);
+use Bugzilla::Keyword;
use Bugzilla::Util;
use Bugzilla::User;
use Bugzilla::Error;
return $cache->{template_bug_fields};
},
+ # Whether or not keywords are enabled, in this Bugzilla.
+ 'use_keywords' => sub { return Bugzilla::Keyword->any_exist; },
+
+
# These don't work as normal constants.
DB_MODULE => \&Bugzilla::Constants::DB_MODULE,
REQUIRED_MODULES =>
$vars->{'bugs'} = [new Bugzilla::Bug($bugid)];
$vars->{'header_done'} = 1;
$vars->{'contenttypemethod'} = $cgi->param('contenttypemethod');
- $vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
print $cgi->header();
# Generate and return the UI (HTML page) from the appropriate template.
$vars->{'attachment'} = $attachment;
$vars->{'bugs'} = [$bug];
$vars->{'header_done'} = 1;
- $vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
print $cgi->header();
# Required to display the bug the deleted attachment belongs to.
$vars->{'bugs'} = [$bug];
$vars->{'header_done'} = 1;
- $vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
$template->process("attachment/updated.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
# exists, add/remove bugs to it, else create it. But if we are
# considering an existing tag, then it has to exist and we throw
# an error if it doesn't (hence the usage of !$is_new_name).
- if (my $old_query = LookupNamedQuery($query_name, undef, LIST_OF_BUGS, !$is_new_name)) {
+ my ($old_query, $query_id) =
+ LookupNamedQuery($query_name, undef, LIST_OF_BUGS, !$is_new_name);
+
+ if ($old_query) {
# We get the encoded query. We need to decode it.
my $old_cgi = new Bugzilla::CGI($old_query);
foreach my $bug_id (split /[\s,]+/, scalar $old_cgi->param('bug_id')) {
# Only keep bug IDs we want to add/keep. Disregard deleted ones.
my @bug_ids = grep { $bug_ids{$_} == 1 } keys %bug_ids;
# If the list is now empty, we could as well delete it completely.
- ThrowUserError('no_bugs_in_list', {'tag' => $query_name})
- unless scalar(@bug_ids);
-
+ if (!scalar @bug_ids) {
+ ThrowUserError('no_bugs_in_list', {name => $query_name,
+ query_id => $query_id});
+ }
$new_query = "bug_id=" . join(',', sort {$a <=> $b} @bug_ids);
$query_type = LIST_OF_BUGS;
}
object => 'multiple_bugs'});
}
$vars->{'dotweak'} = 1;
- $vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
# issue_session_token needs to write to the master DB.
Bugzilla->switch_to_main_db();
if (Bugzilla->params->{"usestatuswhiteboard"}) {
push(@masterlist, "status_whiteboard");
}
-if (Bugzilla::Keyword::keyword_count()) {
+if (Bugzilla::Keyword->any_exist) {
push(@masterlist, "keywords");
}
$vars->{'rep_platform'} = get_legal_field_values('rep_platform');
$vars->{'op_sys'} = get_legal_field_values('op_sys');
-$vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
-
$vars->{'assigned_to'} = formvalue('assigned_to');
$vars->{'assigned_to_disabled'} = !$has_editbugs;
$vars->{'cc_disabled'} = 0;
@bug_list = split(/:/, $cgi->cookie("BUGLIST"));
}
$vars->{'bug_list'} = \@bug_list;
-$vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
if ($token) {
trick_taint($token);
my $dbh = Bugzilla->dbh;
my $template = Bugzilla->template;
my $vars = {};
-$vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
######################################################################
# Subroutines
$vars->{'target_milestone'} = \@milestones;
}
-$vars->{'have_keywords'} = Bugzilla::Keyword::keyword_count();
-
my @chfields;
push @chfields, "[Bug creation]";
$vars->{'bugs'} = \@bugs;
$vars->{'marks'} = \%marks;
-$vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
my @bugids = map {$_->bug_id} grep {!$_->error} @bugs;
$vars->{'bugids'} = join(", ", @bugids);
[% END %]
[% END %]
- [% IF have_keywords %]
+ [% IF use_keywords %]
<tr>
<th align="right">
<label for="keywords" accesskey="k"><a href="describekeywords.cgi"><u>K</u>eywords</a></label>: