--- /home/matty/bugzilla/sanitycheck.cgi Fri Aug 3 14:53:53 2001 +++ ./sanitycheck.cgi Sun Aug 5 02:40:13 2001 @@ -27,6 +27,31 @@ use vars %::FORM; + +########################################################################### +# General subs +########################################################################### + +sub Status { + my ($str) = (@_); + print "$str
\n"; +} + +sub Alert { + my ($str) = (@_); + Status("$str"); +} + +sub BugLink { + my ($id) = (@_); + return "$id"; +} + + +########################################################################### +# Start +########################################################################### + ConnectToDatabase(); confirm_login(); @@ -48,29 +73,40 @@ SendSQL("set SQL_BIG_TABLES=1"); -my $offervotecacherebuild = 0; +my @row; +my @checklist; -sub Status { - my ($str) = (@_); - print "$str
\n"; -} +PutHeader("Bugzilla Sanity Check"); -sub Alert { - my ($str) = (@_); - Status("$str"); -} -sub BugLink { - my ($id) = (@_); - return "$id"; -} +########################################################################### +# Fix vote cache +########################################################################### -sub AlertBadVoteCache { - my ($id) = (@_); - Alert("Bad vote cache for bug " . BugLink($id)); - $offervotecacherebuild = 1; +if (exists $::FORM{'rebuildvotecache'}) { + Status("OK, now rebuilding vote cache."); + SendSQL("lock tables bugs write, votes read"); + SendSQL("update bugs set votes = 0, delta_ts=delta_ts"); + SendSQL("select bug_id, sum(count) from votes group by bug_id"); + my %votes; + while (@row = FetchSQLData()) { + my ($id, $v) = (@row); + $votes{$id} = $v; + } + foreach my $id (keys %votes) { + SendSQL("update bugs set votes = $votes{$id}, delta_ts=delta_ts where bug_id = $id"); + } + SendSQL("unlock tables"); + Status("Vote cache has been rebuilt."); } +print "OK, now running sanity checks.
\n"; + + +########################################################################### +# Perform referential (cross) checks +########################################################################### + sub CrossCheck { my $table = shift @_; my $field = shift @_; @@ -108,33 +144,6 @@ } } - - - -my @row; -my @checklist; - -PutHeader("Bugzilla Sanity Check"); - -if (exists $::FORM{'rebuildvotecache'}) { - Status("OK, now rebuilding vote cache."); - SendSQL("lock tables bugs write, votes read"); - SendSQL("update bugs set votes = 0, delta_ts=delta_ts"); - SendSQL("select bug_id, sum(count) from votes group by bug_id"); - my %votes; - while (@row = FetchSQLData()) { - my ($id, $v) = (@row); - $votes{$id} = $v; - } - foreach my $id (keys %votes) { - SendSQL("update bugs set votes = $votes{$id}, delta_ts=delta_ts where bug_id = $id"); - } - SendSQL("unlock tables"); - Status("Vote cache has been rebuilt."); -} - -print "OK, now running sanity checks.
\n"; - CrossCheck("keyworddefs", "id", ["keywords", "keywordid"]); @@ -166,6 +175,10 @@ ["components", "initialqacontact", "value", ["0"]]); +########################################################################### +# Perform group checks +########################################################################### + Status("Checking groups"); SendSQL("select bit from groups where bit != pow(2, round(log(bit) / log(2)))"); while (my $bit = FetchOneColumn()) { @@ -183,7 +196,9 @@ } - +########################################################################### +# Perform product-specific field checks +########################################################################### Status("Checking version/products"); @@ -241,6 +256,10 @@ } +########################################################################### +# Perform login checks +########################################################################### + Status("Checking profile logins"); my $emailregexp = Param("emailregexp"); @@ -254,6 +273,18 @@ } +########################################################################### +# Perform vote/keyword cache checks +########################################################################### + +my $offervotecacherebuild = 0; + +sub AlertBadVoteCache { + my ($id) = (@_); + Alert("Bad vote cache for bug " . BugLink($id)); + $offervotecacherebuild = 1; +} + SendSQL("SELECT bug_id,votes,keywords FROM bugs " . "WHERE votes != 0 OR keywords != ''"); @@ -389,7 +420,9 @@ } - +########################################################################### +# Finish off +########################################################################### Status("Sanity check completed."); PutFooter();