]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 170019: Sanity check for flags in right product - Patch by Frédéric Buclin <LpSol...
authorlpsolit%gmail.com <>
Fri, 25 Aug 2006 04:27:20 +0000 (04:27 +0000)
committerlpsolit%gmail.com <>
Fri, 25 Aug 2006 04:27:20 +0000 (04:27 +0000)
sanitycheck.cgi

index 174edc9c39e5f755f47a50d77b8104c71788294c..b085feb9d8bfaffee7420c7dac72129e014045d5 100755 (executable)
@@ -756,6 +756,58 @@ if (defined $cgi->param('rebuildkeywordcache')) {
     $dbh->bz_unlock_tables();
 }
 
+###########################################################################
+# Check for flags being in incorrect products and components
+###########################################################################
+
+Status('Checking for flags being in the wrong product/component');
+
+my $invalid_flags = $dbh->selectall_arrayref(
+       'SELECT DISTINCT flags.id, flags.bug_id, flags.attach_id
+          FROM flags
+    INNER JOIN bugs
+            ON flags.bug_id = bugs.bug_id
+     LEFT JOIN flaginclusions AS i
+            ON flags.type_id = i.type_id
+           AND (bugs.product_id = i.product_id OR i.product_id IS NULL)
+           AND (bugs.component_id = i.component_id OR i.component_id IS NULL)
+         WHERE i.type_id IS NULL');
+
+my @invalid_flags = @$invalid_flags;
+
+$invalid_flags = $dbh->selectall_arrayref(
+       'SELECT DISTINCT flags.id, flags.bug_id, flags.attach_id
+          FROM flags
+    INNER JOIN bugs
+            ON flags.bug_id = bugs.bug_id
+    INNER JOIN flagexclusions AS e
+            ON flags.type_id = e.type_id
+         WHERE (bugs.product_id = e.product_id OR e.product_id IS NULL)
+           AND (bugs.component_id = e.component_id OR e.component_id IS NULL)');
+
+push(@invalid_flags, @$invalid_flags);
+
+if (scalar(@invalid_flags)) {
+    if ($cgi->param('remove_invalid_flags')) {
+        Status("OK, now deleting invalid flags.");
+        my @flag_ids = map {$_->[0]} @invalid_flags;
+        $dbh->bz_lock_tables('flags WRITE');
+        # Silently delete these flags, with no notification to requesters/setters.
+        $dbh->do('DELETE FROM flags WHERE id IN (' . join(',', @flag_ids) .')');
+        $dbh->bz_unlock_tables();
+        Status("Invalid flags deleted.");
+    }
+    else {
+        foreach my $flag (@$invalid_flags) {
+            my ($flag_id, $bug_id, $attach_id) = @$flag;
+            Alert("Invalid flag $flag_id for " .
+                  ($attach_id ? "attachment $attach_id in bug " : "bug ") . BugLink($bug_id));
+        }
+        print qq{<a href="sanitycheck.cgi?remove_invalid_flags=1">Click
+                 here to delete invalid flags</a><p>\n};
+    }
+}
+
 ###########################################################################
 # General bug checks
 ###########################################################################