]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 405970: Make checksetup.pl not rederive regex groups every time it runs (this...
authormkanat%bugzilla.org <>
Mon, 3 Aug 2009 05:14:39 +0000 (05:14 +0000)
committermkanat%bugzilla.org <>
Mon, 3 Aug 2009 05:14:39 +0000 (05:14 +0000)
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=mkanat

Bugzilla/Install.pm
Bugzilla/Install/DB.pm

index c469aa857c2792c459143673c5997ad2c5260607..a32063ca72aa9a1e974fdb9caf6eb71529455885 100644 (file)
@@ -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 {
index 53f800b82f29b1969920e0acb81e23bbcebe7186..09b110894119bb4d67b992faa68c708dbd2ce015 100644 (file)
@@ -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;