summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Bugzilla/Group.pm28
-rwxr-xr-xeditgroups.cgi2
-rwxr-xr-xeditproducts.cgi5
-rw-r--r--globals.pl18
4 files changed, 31 insertions, 22 deletions
diff --git a/Bugzilla/Group.pm b/Bugzilla/Group.pm
index 32c4696db..b561f0040 100644
--- a/Bugzilla/Group.pm
+++ b/Bugzilla/Group.pm
@@ -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
diff --git a/editgroups.cgi b/editgroups.cgi
index c366c6d79..026d85b93 100755
--- a/editgroups.cgi
+++ b/editgroups.cgi
@@ -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
diff --git a/editproducts.cgi b/editproducts.cgi
index 1101f3182..25bad900d 100755
--- a/editproducts.cgi
+++ b/editproducts.cgi
@@ -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)
diff --git a/globals.pl b/globals.pl
index 2c7861c6b..b9b6e02d5 100644
--- a/globals.pl
+++ b/globals.pl
@@ -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();