From 81f55739b4374727d71effd04570569828201066 Mon Sep 17 00:00:00 2001 From: "matty%chariot.net.au" Date: Sat, 5 Oct 2002 14:25:13 +0000 Subject: [PATCH] Bug #93667: Move some code around, add some section heading comments. --- webtools/bugzilla/sanitycheck.cgi | 119 ++++++++++++++++-------------- 1 file changed, 65 insertions(+), 54 deletions(-) diff --git a/webtools/bugzilla/sanitycheck.cgi b/webtools/bugzilla/sanitycheck.cgi index caeb2513879f..bd931c03c113 100755 --- a/webtools/bugzilla/sanitycheck.cgi +++ b/webtools/bugzilla/sanitycheck.cgi @@ -71,57 +71,6 @@ sub AlertBadVoteCache { $offervotecacherebuild = 1; } -sub CrossCheck { - my $table = shift @_; - my $field = shift @_; - - Status("Checking references to $table.$field"); - - while (@_) { - my $ref = shift @_; - my ($refertable, $referfield, $keyname, $exceptions) = @$ref; - - $exceptions ||= []; - my %exceptions = map { $_ => 1 } @$exceptions; - - Status("... from $refertable.$referfield"); - - SendSQL("SELECT DISTINCT $refertable.$referfield" . ($keyname ? ", $refertable.$keyname" : '') . " " . - "FROM $refertable LEFT JOIN $table " . - " ON $refertable.$referfield = $table.$field " . - "WHERE $table.$field IS NULL " . - " AND $refertable.$referfield IS NOT NULL"); - - while (MoreSQLData()) { - my ($value, $key) = FetchSQLData(); - if (!$exceptions{$value}) { - my $alert = "Bad value $value found in $refertable.$referfield"; - if ($keyname) { - if ($keyname eq 'bug_id') { - $alert .= ' (bug ' . BugLink($key) . ')'; - } - else { - $alert .= " ($keyname == '$key')"; - } - } - Alert($alert); - } - } - } -} - -sub DateCheck { - my $table = shift @_; - my $field = shift @_; - Status("Checking dates in $table.$field"); - SendSQL("SELECT COUNT( $field ) FROM $table WHERE $field > NOW()"); - my $c = FetchOneColumn(); - if ($c) { - Alert("Found $c dates in future"); - } -} - - my @badbugs; @@ -151,6 +100,10 @@ if (exists $::FORM{'rebuildvotecache'}) { Status("Vote cache has been rebuilt."); } +########################################################################### +# Fix group derivations +########################################################################### + if (exists $::FORM{'rederivegroups'}) { Status("OK, All users' inherited permissions will be rechecked when " . "they next access Bugzilla."); @@ -204,6 +157,10 @@ if (exists $::FORM{'cleangroupsnow'}) { print "OK, now running sanity checks.

\n"; +########################################################################### +# Check enumeration values +########################################################################### + # This one goes first, because if this is wrong, then the below tests # will probably fail too @@ -226,6 +183,45 @@ foreach my $field (("bug_severity", "bug_status", "op_sys", # Perform referential (cross) checks ########################################################################### +sub CrossCheck { + my $table = shift @_; + my $field = shift @_; + + Status("Checking references to $table.$field"); + + while (@_) { + my $ref = shift @_; + my ($refertable, $referfield, $keyname, $exceptions) = @$ref; + + $exceptions ||= []; + my %exceptions = map { $_ => 1 } @$exceptions; + + Status("... from $refertable.$referfield"); + + SendSQL("SELECT DISTINCT $refertable.$referfield" . ($keyname ? ", $refertable.$keyname" : '') . " " . + "FROM $refertable LEFT JOIN $table " . + " ON $refertable.$referfield = $table.$field " . + "WHERE $table.$field IS NULL " . + " AND $refertable.$referfield IS NOT NULL"); + + while (MoreSQLData()) { + my ($value, $key) = FetchSQLData(); + if (!$exceptions{$value}) { + my $alert = "Bad value $value found in $refertable.$referfield"; + if ($keyname) { + if ($keyname eq 'bug_id') { + $alert .= ' (bug ' . BugLink($key) . ')'; + } + else { + $alert .= " ($keyname == '$key')"; + } + } + Alert($alert); + } + } + } +} + CrossCheck("keyworddefs", "id", ["keywords", "keywordid"]); @@ -284,9 +280,6 @@ CrossCheck("products", "id", ["flaginclusions", "product_id", "type_id"], ["flagexclusions", "product_id", "type_id"]); -DateCheck("groups", "last_changed"); -DateCheck("profiles", "refreshed_when"); - ########################################################################### # Perform double field referential (cross) checks ########################################################################### @@ -566,6 +559,24 @@ BugCheck("bugs, products WHERE " . "votestoconfirm <= votes", "Bugs that have enough votes to be confirmed but haven't been"); +########################################################################### +# Date checks +########################################################################### + +sub DateCheck { + my $table = shift @_; + my $field = shift @_; + Status("Checking dates in $table.$field"); + SendSQL("SELECT COUNT( $field ) FROM $table WHERE $field > NOW()"); + my $c = FetchOneColumn(); + if ($c) { + Alert("Found $c dates in future"); + } +} + +DateCheck("groups", "last_changed"); +DateCheck("profiles", "refreshed_when"); + ########################################################################### # Unsent mail ###########################################################################