зеркало из https://github.com/mozilla/gecko-dev.git
Bug 328435: Move GroupNameToId into Bugzilla/Group.pm and eliminate GroupExists
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=wicked, a=justdave
This commit is contained in:
Родитель
3a4d8347a4
Коммит
e702596d80
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
Загрузка…
Ссылка в новой задаче