]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 279748 : Move GetFieldDefs out of globals.pl (to Bugzilla::DB)
authortravis%sedsystems.ca <>
Wed, 2 Feb 2005 00:26:25 +0000 (00:26 +0000)
committertravis%sedsystems.ca <>
Wed, 2 Feb 2005 00:26:25 +0000 (00:26 +0000)
Patch by Max Kanat-Alexander <mkanat@kerio.com>  r=vladd  a=justdave

Bugzilla/DB.pm
config.cgi
globals.pl
query.cgi

index dcd4199159e92b1aaf9a3d761124dd208dad9102..b500d748b213bf2050c8cdbb4124534edb00f52e 100644 (file)
@@ -183,6 +183,26 @@ sub server_version {
     return $cached_server_version;
 }
 
+sub GetFieldDefs {
+    my $dbh = Bugzilla->dbh;
+
+    my $extra = "";
+    if (!&::UserInGroup(Param('timetrackinggroup'))) {
+        $extra = "WHERE name NOT IN ('estimated time', 'remaining_time', " .
+                 "'work_time', 'percentage_complete', 'deadline')";
+    }
+
+    my @fields;
+    my $sth = $dbh->prepare("SELECT name, description
+                               FROM fielddefs $extra
+                           ORDER BY sortkey");
+    $sth->execute();
+    while (my $field_ref = $sth->fetchrow_hashref()) {
+        push(@fields, $field_ref);
+    }
+    return(@fields);
+}
+
 1;
 
 __END__
@@ -193,9 +213,14 @@ Bugzilla::DB - Database access routines, using L<DBI>
 
 =head1 SYNOPSIS
 
+  # Connection
   my $dbh = Bugzilla::DB->connect_main;
   my $shadow = Bugzilla::DB->connect_shadow;
 
+  # Schema Information
+  my @fields = GetFieldDefs();
+
+  # Deprecated
   SendSQL("SELECT COUNT(*) FROM bugs");
   my $cnt = FetchOneColumn();
 
@@ -209,6 +234,9 @@ Access to the old SendSQL-based database routines are also provided by
 importing the C<:deprecated> tag. These routines should not be used in new
 code.
 
+The only functions that should be used by modern, regular Bugzilla code
+are the "Schema Information" functions.
+
 =head1 CONNECTION
 
 A new database handle to the required database can be created using this
@@ -228,6 +256,18 @@ no shadow database is configured.
 
 =back
 
+=head1 SCHEMA INFORMATION
+
+Bugzilla::DB also contains routines to get schema information about the 
+database.
+
+=over 4
+
+=item C<GetFieldDefs>
+
+Returns a list of all the "bug" fields in Bugzilla. The list contains 
+hashes, with a 'name' key and a 'description' key.
+
 =head1 DEPRECATED ROUTINES
 
 Several database routines are deprecated. They should not be used in new code,
index a2c22d0019b6ec236e03d7002b0c67f40816f7b2..2d0505db8c250722ca7250209a13fe9849f47992 100755 (executable)
@@ -32,6 +32,7 @@ use strict;
 # Include the Bugzilla CGI and general utility library.
 use lib qw(.);
 require "CGI.pl";
+use Bugzilla::DB;
 
 # Retrieve this installation's configuration.
 GetVersionTable();
@@ -82,7 +83,7 @@ $vars->{'open_status'} = \@open_status;
 $vars->{'closed_status'} = \@closed_status;
 
 # Generate a list of fields that can be queried.
-$vars->{'field'} = [GetFieldDefs()];
+$vars->{'field'} = [Bugzilla::DB::GetFieldDefs()];
 
 # Determine how the user would like to receive the output; 
 # default is JavaScript.
index c97467b360de0cf6f44551263727e1a9b550b257..1529a0f6aae76171817c96c4dbdbb64a68bd71a7 100644 (file)
@@ -636,26 +636,6 @@ sub GetSelectableClassifications {
     return (@selectable_classes);
 }
 
-sub GetFieldDefs {
-    my $extra = "";
-    if (!UserInGroup(Param('timetrackinggroup'))) {
-        $extra = "WHERE name NOT IN ('estimated time', 'remaining_time', " .
-                 "'work_time', 'percentage_complete', 'deadline')";
-    }
-
-    my @fields;
-    PushGlobalSQLState();
-    SendSQL("SELECT name, description FROM fielddefs $extra ORDER BY sortkey");
-    while (MoreSQLData()) {
-        my ($name, $description) = FetchSQLData();
-        push(@fields, { name => $name, description => $description });
-    }
-    PopGlobalSQLState();
-
-    return(@fields);
-}
-
-
 
 sub ValidatePassword {
     # Determines whether or not a password is valid (i.e. meets Bugzilla's
index 2de7e1727cfd8ef0b2e68ce60cba781b3ada0865..cfe7702dec1e0e78ecdb0132bff27e1dfed1450f 100755 (executable)
--- a/query.cgi
+++ b/query.cgi
@@ -351,7 +351,7 @@ $vars->{'bug_severity'} = \@::legal_severity;
 # Boolean charts
 my @fields;
 push(@fields, { name => "noop", description => "---" });
-push(@fields, GetFieldDefs());
+push(@fields, Bugzilla::DB::GetFieldDefs());
 $vars->{'fields'} = \@fields;
 
 # Creating new charts - if the cmd-add value is there, we define the field