1998-09-15 21:49:26 +00:00
|
|
|
#!/usr/bonsaitools/bin/perl -w
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
1998-09-01 01:20:36 +00:00
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License
|
|
|
|
# Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
# compliance with the License. You may obtain a copy of the License at
|
|
|
|
# http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS"
|
|
|
|
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing rights and limitations
|
|
|
|
# under the License.
|
|
|
|
#
|
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
# Corporation. Portions created by Netscape are Copyright (C) 1998
|
|
|
|
# Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
use diagnostics;
|
|
|
|
use strict;
|
1998-09-01 01:20:36 +00:00
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
require "CGI.pl";
|
1998-09-01 01:20:36 +00:00
|
|
|
|
1999-10-11 17:14:32 +00:00
|
|
|
use vars %::FORM;
|
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
print "Content-type: text/html\n";
|
|
|
|
print "\n";
|
1998-09-01 01:20:36 +00:00
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
ConnectToDatabase();
|
|
|
|
|
1999-10-11 17:14:32 +00:00
|
|
|
my $offervotecacherebuild = 0;
|
1998-09-15 21:49:26 +00:00
|
|
|
|
|
|
|
sub Status {
|
|
|
|
my ($str) = (@_);
|
|
|
|
print "$str <P>\n";
|
1998-09-01 01:20:36 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
sub Alert {
|
|
|
|
my ($str) = (@_);
|
|
|
|
Status("<font color=red>$str</font>");
|
1998-09-01 01:20:36 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
sub BugLink {
|
|
|
|
my ($id) = (@_);
|
1998-11-20 19:18:37 +00:00
|
|
|
return "<a href='show_bug.cgi?id=$id'>$id</a>";
|
1998-09-01 01:20:36 +00:00
|
|
|
}
|
|
|
|
|
1999-10-11 17:14:32 +00:00
|
|
|
sub AlertBadVoteCache {
|
|
|
|
my ($id) = (@_);
|
|
|
|
Alert("Bad vote cache for bug " . BugLink($id));
|
|
|
|
$offervotecacherebuild = 1;
|
|
|
|
}
|
1998-09-01 01:20:36 +00:00
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
|
1999-03-03 22:55:36 +00:00
|
|
|
my @row;
|
1999-03-05 17:55:45 +00:00
|
|
|
my @checklist;
|
|
|
|
|
1999-10-11 17:14:32 +00:00
|
|
|
PutHeader("Bugzilla Sanity Check");
|
|
|
|
|
|
|
|
if (exists $::FORM{'rebuildvotecache'}) {
|
|
|
|
Status("OK, now rebuilding vote cache.");
|
|
|
|
SendSQL("lock tables bugs write, votes read");
|
1999-10-12 11:18:29 +00:00
|
|
|
SendSQL("update bugs set votes = 0, delta_ts=delta_ts");
|
1999-10-11 17:14:32 +00:00
|
|
|
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) {
|
1999-10-12 11:18:29 +00:00
|
|
|
SendSQL("update bugs set votes = $votes{$id}, delta_ts=delta_ts where bug_id = $id");
|
1999-10-11 17:14:32 +00:00
|
|
|
}
|
|
|
|
SendSQL("unlock tables");
|
1999-10-12 11:18:29 +00:00
|
|
|
Status("Vote cache has been rebuilt.");
|
1999-10-11 17:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print "OK, now running sanity checks.<P>\n";
|
|
|
|
|
1999-03-11 16:30:54 +00:00
|
|
|
Status("Checking groups");
|
|
|
|
SendSQL("select bit from groups where bit != pow(2, round(log(bit) / log(2)))");
|
|
|
|
while (my $bit = FetchOneColumn()) {
|
|
|
|
Alert("Illegal bit number found in group table: $bit");
|
|
|
|
}
|
|
|
|
|
|
|
|
SendSQL("select sum(bit) from groups where isbuggroup != 0");
|
|
|
|
my $buggroupset = FetchOneColumn();
|
1999-10-21 18:19:48 +00:00
|
|
|
if (!defined $buggroupset || $buggroupset eq "") {
|
1999-10-12 16:52:25 +00:00
|
|
|
$buggroupset = 0;
|
|
|
|
}
|
1999-03-11 16:30:54 +00:00
|
|
|
SendSQL("select bug_id, groupset from bugs where groupset & $buggroupset != groupset");
|
|
|
|
while (@row = FetchSQLData()) {
|
|
|
|
Alert("Bad groupset $row[1] found in bug " . BugLink($row[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-03-05 17:55:45 +00:00
|
|
|
Status("Checking version/products");
|
|
|
|
|
|
|
|
SendSQL("select distinct product, version from bugs");
|
|
|
|
while (@row = FetchSQLData()) {
|
|
|
|
my @copy = @row;
|
|
|
|
push(@checklist, \@copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $ref (@checklist) {
|
|
|
|
my ($product, $version) = (@$ref);
|
|
|
|
SendSQL("select count(*) from versions where program = '$product' and value = '$version'");
|
|
|
|
if (FetchOneColumn() != 1) {
|
|
|
|
Alert("Bug(s) found with invalid product/version: $product/$version");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-03 22:55:36 +00:00
|
|
|
|
|
|
|
Status("Checking components/products");
|
|
|
|
|
1999-03-05 17:55:45 +00:00
|
|
|
@checklist = ();
|
1999-03-03 22:55:36 +00:00
|
|
|
SendSQL("select distinct product, component from bugs");
|
|
|
|
while (@row = FetchSQLData()) {
|
|
|
|
my @copy = @row;
|
|
|
|
push(@checklist, \@copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $ref (@checklist) {
|
|
|
|
my ($product, $component) = (@$ref);
|
|
|
|
SendSQL("select count(*) from components where program = '$product' and value = '$component'");
|
|
|
|
if (FetchOneColumn() != 1) {
|
|
|
|
Alert("Bug(s) found with invalid product/component: $product/$component");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
Status("Checking profile ids...");
|
1998-09-01 01:20:36 +00:00
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
SendSQL("select userid,login_name from profiles");
|
1998-09-01 01:20:36 +00:00
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
my %profid;
|
1998-09-01 01:20:36 +00:00
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
while (@row = FetchSQLData()) {
|
|
|
|
my ($id, $email) = (@row);
|
|
|
|
if ($email =~ /^[^@, ]*@[^@, ]*\.[^@, ]*$/) {
|
|
|
|
$profid{$id} = 1;
|
1998-09-01 01:20:36 +00:00
|
|
|
} else {
|
1998-09-15 21:49:26 +00:00
|
|
|
Alert "Bad profile id $id <$email>."
|
1998-09-01 01:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
undef $profid{0};
|
1998-09-01 01:20:36 +00:00
|
|
|
|
|
|
|
|
1999-03-05 23:08:23 +00:00
|
|
|
Status("Checking reporter/assigned_to/qa_contact ids");
|
1999-10-11 17:14:32 +00:00
|
|
|
SendSQL("select bug_id,reporter,assigned_to,qa_contact,votes from bugs");
|
1998-09-01 01:20:36 +00:00
|
|
|
|
1999-10-11 17:14:32 +00:00
|
|
|
my %votes;
|
1998-09-15 21:49:26 +00:00
|
|
|
my %bugid;
|
|
|
|
|
|
|
|
while (@row = FetchSQLData()) {
|
1999-10-11 17:14:32 +00:00
|
|
|
my($id, $reporter, $assigned_to, $qa_contact, $v) = (@row);
|
1998-09-15 21:49:26 +00:00
|
|
|
$bugid{$id} = 1;
|
|
|
|
if (!defined $profid{$reporter}) {
|
|
|
|
Alert("Bad reporter $reporter in " . BugLink($id));
|
1998-09-01 01:20:36 +00:00
|
|
|
}
|
1998-09-15 21:49:26 +00:00
|
|
|
if (!defined $profid{$assigned_to}) {
|
|
|
|
Alert("Bad assigned_to $assigned_to in" . BugLink($id));
|
1998-09-01 01:20:36 +00:00
|
|
|
}
|
1999-03-05 23:08:23 +00:00
|
|
|
if ($qa_contact != 0 && !defined $profid{$qa_contact}) {
|
|
|
|
Alert("Bad qa_contact $qa_contact in" . BugLink($id));
|
|
|
|
}
|
1999-10-11 17:14:32 +00:00
|
|
|
if ($v != 0) {
|
|
|
|
$votes{$id} = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status("Checking cached vote counts");
|
|
|
|
SendSQL("select bug_id, sum(count) from votes group by bug_id");
|
|
|
|
|
|
|
|
while (@row = FetchSQLData()) {
|
|
|
|
my ($id, $v) = (@row);
|
|
|
|
if ($v <= 0) {
|
|
|
|
Alert("Bad vote sum for bug $id");
|
|
|
|
} else {
|
|
|
|
if (!defined $votes{$id} || $votes{$id} != $v) {
|
|
|
|
AlertBadVoteCache($id);
|
|
|
|
}
|
|
|
|
delete $votes{$id};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach my $id (keys %votes) {
|
|
|
|
AlertBadVoteCache($id);
|
1998-09-01 01:20:36 +00:00
|
|
|
}
|
|
|
|
|
1999-10-11 17:14:32 +00:00
|
|
|
if ($offervotecacherebuild) {
|
|
|
|
print qq{<a href="sanitycheck.cgi?rebuildvotecache=1">Click here to rebuild the vote cache</a><p>\n};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
Status("Checking CC table");
|
1998-09-01 01:20:36 +00:00
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
SendSQL("select bug_id,who from cc");
|
|
|
|
while (@row = FetchSQLData()) {
|
|
|
|
my ($id, $cc) = (@row);
|
|
|
|
if (!defined $profid{$cc}) {
|
|
|
|
Alert("Bad cc $cc in " . BugLink($id));
|
1998-09-01 01:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
Status("Checking activity table");
|
1998-09-01 01:20:36 +00:00
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
SendSQL("select bug_id,who from bugs_activity");
|
1998-09-01 01:20:36 +00:00
|
|
|
|
1998-09-15 21:49:26 +00:00
|
|
|
while (@row = FetchSQLData()) {
|
|
|
|
my ($id, $who) = (@row);
|
|
|
|
if (!defined $bugid{$id}) {
|
|
|
|
Alert("Bad bugid " . BugLink($id));
|
1998-09-01 01:20:36 +00:00
|
|
|
}
|
1998-09-15 21:49:26 +00:00
|
|
|
if (!defined $profid{$who}) {
|
|
|
|
Alert("Bad who $who in " . BugLink($id));
|
1998-09-01 01:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
1999-06-01 20:52:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
Status("Checking dependency table");
|
|
|
|
|
|
|
|
SendSQL("select blocked, dependson from dependencies");
|
|
|
|
while (@row = FetchSQLData()) {
|
|
|
|
my ($blocked, $dependson) = (@row);
|
|
|
|
if (!defined $bugid{$blocked}) {
|
|
|
|
Alert("Bad blocked " . BugLink($blocked));
|
|
|
|
}
|
|
|
|
if (!defined $bugid{$dependson}) {
|
|
|
|
Alert("Bad dependson " . BugLink($dependson));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Status("Sanity check completed.");
|