]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug #93667: General bug check refactoring.
authormatty%chariot.net.au <>
Sat, 5 Oct 2002 20:23:44 +0000 (20:23 +0000)
committermatty%chariot.net.au <>
Sat, 5 Oct 2002 20:23:44 +0000 (20:23 +0000)
sanitycheck.cgi

index 073fd7f197c98e767b7db8abc6add4bc5b5a0899..0d8538fff48c01931e052316ce2967d07d876ee8 100755 (executable)
@@ -521,152 +521,72 @@ if (exists $::FORM{'rebuildkeywordcache'}) {
 }
 
 ###########################################################################
-# Perform duplicates table checks
+# General bug checks
 ###########################################################################
 
-Status("Checking duplicates table");
-
-SendSQL("SELECT bugs.bug_id " .
-        "FROM bugs, duplicates " .
-        "WHERE bugs.resolution != 'DUPLICATE' " .
-        "  AND bugs.bug_id = duplicates.dupe " .
-        "ORDER BY bugs.bug_id");
-
-@badbugs = ();
-
-while (@row = FetchSQLData()) {
-    my ($id) = (@row);
-    push (@badbugs, $id);
-}
-
-if (@badbugs) {
-    Alert("Bug(s) found on duplicates table that are not marked duplicate: " .
-          join(', ', @badbugs));
+sub BugCheck ($$) {
+    my ($middlesql, $errortext) = @_;
+    
+    SendSQL("SELECT DISTINCT bugs.bug_id " .
+            "FROM $middlesql " .
+            "ORDER BY bugs.bug_id");
+    
+    my @badbugs = ();
+    
+    while (@row = FetchSQLData()) {
+        my ($id) = (@row);
+        push (@badbugs, $id);
+    }
+    
+    @badbugs = map(BugLink($_), @badbugs);
+    
+    if (@badbugs) {
+        Alert("$errortext: " . join(', ', @badbugs));
+    }
 }
 
-SendSQL("SELECT bugs.bug_id " .
-        "FROM bugs LEFT JOIN duplicates ON bugs.bug_id = duplicates.dupe " .
-        "WHERE bugs.resolution = 'DUPLICATE' AND duplicates.dupe IS NULL " .
-        "ORDER BY bugs.bug_id");
-
-@badbugs = ();
-
-while (@row = FetchSQLData()) {
-    my ($id) = (@row);
-    push (@badbugs, $id);
-}
+Status("Checking resolution/duplicates");
 
-if (@badbugs) {
-    Alert("Bug(s) found marked resolved duplicate and not on duplicates " .
-          "table: " . join(', ', @badbugs));
-}
+BugCheck("bugs, duplicates WHERE " .
+         "bugs.resolution != 'DUPLICATE' AND " .
+         "bugs.bug_id = duplicates.dupe",
+         "Bug(s) found on duplicates table that are not marked duplicate");
 
-###########################################################################
-# Perform status/resolution checks
-###########################################################################
+BugCheck("bugs LEFT JOIN duplicates ON bugs.bug_id = duplicates.dupe WHERE " .
+         "bugs.resolution = 'DUPLICATE' AND " .
+         "duplicates.dupe IS NULL",
+         "Bug(s) found marked resolved duplicate and not on duplicates table");
 
 Status("Checking statuses/resolutions");
 
 my @open_states = map(SqlQuote($_), OpenStates());
 my $open_states = join(', ', @open_states);
 
-@badbugs = ();
-
-SendSQL("SELECT   bug_id FROM bugs " .
-        "WHERE    bug_status IN ($open_states) " .
-        "AND      resolution != '' " .
-        "ORDER BY bug_id");
-
-while (@row = FetchSQLData()) {
-    my ($id) = (@row);
-    push(@badbugs, $id);
-}
-
-if (@badbugs > 0) {
-    Alert("Bugs with open status and a resolution: " .
-          join (", ", @badbugs));
-}
-
-@badbugs = ();
-
-SendSQL("SELECT   bug_id FROM bugs " .
-        "WHERE    bug_status NOT IN ($open_states) " .
-        "AND      resolution = '' " .
-        "ORDER BY bug_id");
-
-while (@row = FetchSQLData()) {
-    my ($id) = (@row);
-    push(@badbugs, $id);
-}
-
-if (@badbugs > 0) {
-    Alert("Bugs with non-open status and no resolution: " .
-          join (", ", @badbugs));
-}
-
-###########################################################################
-# Perform status/everconfirmed checks
-###########################################################################
+BugCheck("bugs WHERE bug_status IN ($open_states) AND resolution != ''",
+         "Bugs with open status and a resolution");
+BugCheck("bugs WHERE bug_status NOT IN ($open_states) AND resolution = ''",
+         "Bugs with non-open status and no resolution");
 
 Status("Checking statuses/everconfirmed");
 
-@badbugs = ();
-
-SendSQL("SELECT   bug_id FROM bugs " .
-        "WHERE    bug_status = " . SqlQuote($::unconfirmedstate) . ' ' .
-        "AND      everconfirmed = 1 " .
-        "ORDER BY bug_id");
-
-while (@row = FetchSQLData()) {
-    my ($id) = (@row);
-    push(@badbugs, $id);
-}
-
-if (@badbugs > 0) {
-    Alert("Bugs that are UNCONFIRMED but have everconfirmed set: " .
-          join (", ", @badbugs));
-}
-
-@badbugs = ();
+my $sqlunconfirmed = SqlQuote($::unconfirmedstate);
 
-SendSQL("SELECT   bug_id FROM bugs " .
-        "WHERE    bug_status IN ('NEW', 'ASSIGNED', 'REOPENED') " .
-        "AND      everconfirmed = 0 " .
-        "ORDER BY bug_id");
-
-while (@row = FetchSQLData()) {
-    my ($id) = (@row);
-    push(@badbugs, $id);
-}
-
-if (@badbugs > 0) {
-    Alert("Bugs with confirmed status but don't have everconfirmed set: " .
-          join (", ", @badbugs));
-}
-
-###########################################################################
-# Perform vote/everconfirmed checks
-###########################################################################
+BugCheck("bugs WHERE bug_status = $sqlunconfirmed AND everconfirmed = 1",
+         "Bugs that are UNCONFIRMED but have everconfirmed set");
+# The below list of resolutions is hardcoded because we don't know if future
+# resolutions will be confirmed, unconfirmed or maybeconfirmed.  I suspect
+# they will be maybeconfirmed, eg ASLEEP and REMIND.  This hardcoding should
+# disappear when we have customised statuses.
+BugCheck("bugs WHERE bug_status IN ('NEW', 'ASSIGNED', 'REOPENED') AND everconfirmed = 0",
+         "Bugs with confirmed status but don't have everconfirmed set"); 
 
 Status("Checking votes/everconfirmed");
 
-@badbugs = ();
-
-SendSQL("SELECT   bug_id FROM bugs, products " .
-        "WHERE    bugs.product_id = products.id " .
-        "AND      bug_status = " . SqlQuote($::unconfirmedstate) . ' ' .
-        "AND      votestoconfirm <= votes " .
-        "ORDER BY bug_id");
-
-while (@row = FetchSQLData()) {
-    my ($id) = (@row);
-    push(@badbugs, $id);
-}
-
-if (@badbugs > 0) {
-    Alert("Bugs that have enough votes to be confirmed but haven't been: " .
-          join (", ", @badbugs));
-}
+BugCheck("bugs, products WHERE " .
+         "bugs.product = products.product AND " .
+         "everconfirmed = 0 AND " .
+         "votestoconfirm <= votes",
+         "Bugs that have enough votes to be confirmed but haven't been");
 
 ###########################################################################
 # Unsent mail