]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 328435: Move GroupNameToId into Bugzilla/Group.pm and eliminate GroupExists
authormkanat%kerio.com <>
Thu, 2 Mar 2006 05:33:01 +0000 (05:33 +0000)
committermkanat%kerio.com <>
Thu, 2 Mar 2006 05:33:01 +0000 (05:33 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=wicked, a=justdave

Bugzilla/Group.pm
editgroups.cgi
editproducts.cgi
globals.pl

index 32c4696db8dccae33be4c5378be58e01d5fba169..b561f004038503098400317bf3df32bf657e740d 100644 (file)
@@ -25,6 +25,11 @@ use strict;
 
 package Bugzilla::Group;
 
+use base qw(Exporter);
+@Bugzilla::Group::EXPORT = qw(
+    group_name_to_id
+);
+
 use Bugzilla::Config;
 use Bugzilla::Util;
 use Bugzilla::Error;
@@ -140,6 +145,14 @@ sub get_all_groups {
     return @groups;
 }
 
+sub group_name_to_id {
+    my ($name) = @_;
+    trick_taint($name);
+    my ($id) = Bugzilla->dbh->selectrow_array(
+        "SELECT id FROM groups WHERE name = ?", undef, $name);
+    return $id;
+}
+
 1;
 
 __END__
@@ -163,7 +176,8 @@ Bugzilla::Group - Bugzilla group class.
     my $is_active    = $group->is_active;
 
     my $group_id = Bugzilla::Group::ValidateGroupName('admin', @users);
-    my @groups = Bugzilla::get_all_groups();
+    my @groups   = Bugzilla::Group::get_all_groups();
+    my $group_id = group_name_to_id('admin');
 
 =head1 DESCRIPTION
 
@@ -213,6 +227,18 @@ Group.pm represents a Bugzilla Group object.
 
  Returns:     An array of group objects.
 
+=item C<group_name_to_id($name)>
+
+ Description: Converts a group name to an id.
+              In general, instead of using this function, you should
+              create a Group object and get its name. This function
+              does not offer any real performance advantage.
+
+ Params:      $name - The name of a group.
+
+ Returns:     The numeric id of the group with that name,
+              or C<undef> if the group does not exist.
+
 =back
 
 =cut
index c366c6d798f04c0d3045a1c39c27cc2799c0beb5..026d85b9375da44b183ab5c734b03e4068d06733 100755 (executable)
@@ -294,7 +294,7 @@ if ($action eq 'new') {
               undef, ($name, $desc, $regexp, $isactive));
 
     my $gid = $dbh->bz_last_key('groups', 'id');
-    my $admin = GroupNameToId('admin');
+    my $admin = group_name_to_id('admin');
     # Since we created a new group, give the "admin" group all privileges
     # initially.
     my $sth = $dbh->prepare('INSERT INTO group_group_map
index 1101f3182494b7bea6dfe2d1ca8f83e9081e322f..25bad900d311ea507ca9a07536a3a4777ebe8fbb 100755 (executable)
@@ -43,6 +43,7 @@ use Bugzilla::BugMail;
 use Bugzilla::Product;
 use Bugzilla::Classification;
 use Bugzilla::Milestone;
+use Bugzilla::Group;
 
 # Shut up misguided -w warnings about "used only once".  "use vars" just
 # doesn't work for me.
@@ -234,7 +235,7 @@ if ($action eq 'new') {
     if (Param("makeproductgroups")) {
         # Next we insert into the groups table
         my $productgroup = $product->name;
-        while (GroupExists($productgroup)) {
+        while (group_name_to_id($productgroup)) {
             $productgroup .= '_';
         }
         my $group_description = "Access to bugs in the " .
@@ -249,7 +250,7 @@ if ($action eq 'new') {
 
         # If we created a new group, give the "admin" group priviledges
         # initially.
-        my $admin = GroupNameToId('admin');
+        my $admin = group_name_to_id('admin');
         
         my $sth = $dbh->prepare('INSERT INTO group_group_map
                                  (member_id, grantor_id, grant_type)
index 2c7861c6b93aa742e5e18a18ebd01e36c7760b28..b9b6e02d5a874a2fb3efacefdc1b503788cc95a1 100644 (file)
@@ -499,24 +499,6 @@ sub BugInGroupId {
     return $bugingroup;
 }
 
-sub GroupExists {
-    my ($groupname) = (@_);
-    PushGlobalSQLState();
-    SendSQL("SELECT id FROM groups WHERE name=" . SqlQuote($groupname));
-    my $id = FetchOneColumn();
-    PopGlobalSQLState();
-    return $id;
-}
-
-sub GroupNameToId {
-    my ($groupname) = (@_);
-    PushGlobalSQLState();
-    SendSQL("SELECT id FROM groups WHERE name=" . SqlQuote($groupname));
-    my $id = FetchOneColumn();
-    PopGlobalSQLState();
-    return $id;
-}
-
 sub GroupIdToName {
     my ($groupid) = (@_);
     PushGlobalSQLState();