Commit e9024051 authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 405970: Make checksetup.pl not rederive regex groups every time it runs…

Bug 405970: Make checksetup.pl not rederive regex groups every time it runs (this was significantly slowing down checksetup.pl on large installations when there was nothing to do) Patch by Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=mkanat
parent eed377eb
......@@ -185,36 +185,6 @@ sub update_system_groups {
$dbh->do('INSERT INTO group_group_map (grantor_id, member_id)
VALUES (?,?)', undef, $sudo_protect->id, $sudo->id);
}
# Re-evaluate all regexps, to keep them up-to-date.
my $sth = $dbh->prepare(
"SELECT profiles.userid, profiles.login_name, groups.id,
groups.userregexp, user_group_map.group_id
FROM (profiles CROSS JOIN groups)
LEFT JOIN user_group_map
ON user_group_map.user_id = profiles.userid
AND user_group_map.group_id = groups.id
AND user_group_map.grant_type = ?
WHERE userregexp != '' OR user_group_map.group_id IS NOT NULL");
my $sth_add = $dbh->prepare(
"INSERT INTO user_group_map (user_id, group_id, isbless, grant_type)
VALUES (?, ?, 0, " . GRANT_REGEXP . ")");
my $sth_del = $dbh->prepare(
"DELETE FROM user_group_map
WHERE user_id = ? AND group_id = ? AND isbless = 0
AND grant_type = " . GRANT_REGEXP);
$sth->execute(GRANT_REGEXP);
while (my ($uid, $login, $gid, $rexp, $present) = $sth->fetchrow_array()) {
if ($login =~ m/$rexp/i) {
$sth_add->execute($uid, $gid) unless $present;
} else {
$sth_del->execute($uid, $gid) if $present;
}
}
}
sub create_default_classification {
......
......@@ -415,12 +415,13 @@ sub update_table_definitions {
_fix_attachments_submitter_id_idx();
_copy_attachments_thedata_to_attach_data();
_fix_broken_all_closed_series();
# 2005-08-14 bugreport@peshkin.net -- Bug 304583
# Get rid of leftover DERIVED group permissions
use constant GRANT_DERIVED => 1;
$dbh->do("DELETE FROM user_group_map WHERE grant_type = " . GRANT_DERIVED);
_rederive_regex_groups();
# PUBLIC is a reserved word in Oracle.
$dbh->bz_rename_column('series', 'public', 'is_public');
......@@ -2614,6 +2615,54 @@ EOT
} # if (@$broken_nonopen_series)
}
# This needs to happen at two times: when we upgrade from 2.16 (thus creating
# user_group_map), and when we kill derived gruops in the DB.
sub _rederive_regex_groups {
my $dbh = Bugzilla->dbh;
my $regex_groups_exist = $dbh->selectrow_array(
"SELECT 1 FROM groups WHERE userregexp = '' " . $dbh->sql_limit(1));
return if !$regex_groups_exist;
my $regex_derivations = $dbh->selectrow_array(
'SELECT 1 FROM user_group_map WHERE grant_type = ' . GRANT_REGEXP
. ' ' . $dbh->sql_limit(1));
return if $regex_derivations;
print "Deriving regex group memberships...\n";
# Re-evaluate all regexps, to keep them up-to-date.
my $sth = $dbh->prepare(
"SELECT profiles.userid, profiles.login_name, groups.id,
groups.userregexp, user_group_map.group_id
FROM (profiles CROSS JOIN groups)
LEFT JOIN user_group_map
ON user_group_map.user_id = profiles.userid
AND user_group_map.group_id = groups.id
AND user_group_map.grant_type = ?
WHERE userregexp != '' OR user_group_map.group_id IS NOT NULL");
my $sth_add = $dbh->prepare(
"INSERT INTO user_group_map (user_id, group_id, isbless, grant_type)
VALUES (?, ?, 0, " . GRANT_REGEXP . ")");
my $sth_del = $dbh->prepare(
"DELETE FROM user_group_map
WHERE user_id = ? AND group_id = ? AND isbless = 0
AND grant_type = " . GRANT_REGEXP);
$sth->execute(GRANT_REGEXP);
while (my ($uid, $login, $gid, $rexp, $present) =
$sth->fetchrow_array())
{
if ($login =~ m/$rexp/i) {
$sth_add->execute($uid, $gid) unless $present;
} else {
$sth_del->execute($uid, $gid) if $present;
}
}
}
sub _clean_control_characters_from_short_desc {
my $dbh = Bugzilla->dbh;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment