]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 509045: Make "use_keywords" a global template variable instead of having to pass...
authormkanat%bugzilla.org <>
Tue, 11 Aug 2009 04:34:17 +0000 (04:34 +0000)
committermkanat%bugzilla.org <>
Tue, 11 Aug 2009 04:34:17 +0000 (04:34 +0000)
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=LpSolit

12 files changed:
Bugzilla/Keyword.pm
Bugzilla/Object.pm
Bugzilla/Template.pm
attachment.cgi
buglist.cgi
colchange.cgi
enter_bug.cgi
post_bug.cgi
process_bug.cgi
query.cgi
show_bug.cgi
template/en/default/search/form.html.tmpl

index 2152b338d0b4b0ecd7e31913b7c1cacb5c3f1bdd..f4742bebd93c19119d19b052cd785fdd5b97602f 100644 (file)
@@ -74,12 +74,6 @@ sub set_description { $_[0]->set('description', $_[1]); }
 ####      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;
@@ -145,8 +139,6 @@ Bugzilla::Keyword - A Keyword that can be added to a bug.
 
  use Bugzilla::Keyword;
 
- my $count = Bugzilla::Keyword::keyword_count;
-
  my $description = $keyword->description;
 
  my $keywords = Bugzilla::Keyword->get_all_with_bug_count();
@@ -166,14 +158,6 @@ implements.
 
 =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
index d2e5a8dda7d5740f41cdce96a3b78875c9f29d94..cfa2bfeb6b77a73d2c0113147804636350ed947c 100644 (file)
@@ -170,14 +170,16 @@ sub match {
         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
@@ -335,6 +337,15 @@ sub remove_from_db {
 ####      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;
@@ -880,6 +891,11 @@ Returns C<1> if the passed-in value is true, C<0> otherwise.
 
 =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.
index 49954a5215601470f4e927a088d33ae9f0c2b957..22ea4b7ccb6e369a7590d663b8aec30994393447 100644 (file)
@@ -37,7 +37,9 @@ use strict;
 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;
@@ -752,6 +754,10 @@ sub create {
                 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 => 
index 8614026db59a84ae7525154f688be46d606b42c1..bbbf4afb3b32dc293259af93134e2dd10790299a 100755 (executable)
@@ -523,7 +523,6 @@ sub insert {
   $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.
@@ -644,7 +643,6 @@ sub update {
     $vars->{'attachment'} = $attachment;
     $vars->{'bugs'} = [$bug];
     $vars->{'header_done'} = 1;
-    $vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
 
     print $cgi->header();
 
@@ -716,7 +714,6 @@ sub delete_attachment {
         # 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());
index 35d0c0291a5524dc735fbf12b1b27aefab8b2ca1..47e1f4ba5b965c1a78887a9a0eaa76f88f22c23d 100755 (executable)
@@ -575,7 +575,10 @@ elsif (($cmdtype eq "doit") && defined $cgi->param('remtype')) {
             # 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')) {
@@ -599,9 +602,10 @@ elsif (($cmdtype eq "doit") && defined $cgi->param('remtype')) {
             # 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;
         }
@@ -1135,7 +1139,6 @@ if ($dotweak && scalar @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();
index a521ee1681afb3bfec031a220a0213c5e75a1a4c..5aef57ff8a1ae3294c14a008d87ce918abd8bcb5 100755 (executable)
@@ -71,7 +71,7 @@ if (Bugzilla->params->{"useqacontact"}) {
 if (Bugzilla->params->{"usestatuswhiteboard"}) {
     push(@masterlist, "status_whiteboard");
 }
-if (Bugzilla::Keyword::keyword_count()) {
+if (Bugzilla::Keyword->any_exist) {
     push(@masterlist, "keywords");
 }
 
index 408336121df0977e4e33f7c7dff6d3bd3d818d59..071276f1db1abc24017511a49f9cefd5082380c2 100755 (executable)
@@ -380,8 +380,6 @@ $vars->{'bug_severity'}          = get_legal_field_values('bug_severity');
 $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;
index 997b621ad3766cfe69f4466a027cfe9f9c97b76e..c6e4006e04ecf9466101d5c497dda747e69226ae 100755 (executable)
@@ -279,7 +279,6 @@ if ($cgi->cookie("BUGLIST")) {
     @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);
index f10467d4e6a75093fa7ba9f4449fe76a1786a35c..85e6c60fc6fc71303cfcae600277f11d675fdf1e 100755 (executable)
@@ -69,7 +69,6 @@ my $cgi = Bugzilla->cgi;
 my $dbh = Bugzilla->dbh;
 my $template = Bugzilla->template;
 my $vars = {};
-$vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
 
 ######################################################################
 # Subroutines
index 5774106816640ed86eb1e52508c5f345948769a9..ab07fbf0fa38abef6cbfb547b4014f7463d17600 100755 (executable)
--- a/query.cgi
+++ b/query.cgi
@@ -230,8 +230,6 @@ if (Bugzilla->params->{'usetargetmilestone'}) {
     $vars->{'target_milestone'} = \@milestones;
 }
 
-$vars->{'have_keywords'} = Bugzilla::Keyword::keyword_count();
-
 my @chfields;
 
 push @chfields, "[Bug creation]";
index 42fad7121973dde11818eebad23c61a1dd8aa8fd..c0e54323488bee73c851151d732b66224e6b5c41 100755 (executable)
@@ -99,7 +99,6 @@ eval {
 
 $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);
index 078ff8c6b3549a1f260a938a8a5312542f37c3b6..5df8bc0a949c133737361e45c877cf2c782435fc 100644 (file)
@@ -285,7 +285,7 @@ function doOnSelectProduct(selectmode) {
     [% 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>: