diff options
author | matty%chariot.net.au <> | 2002-10-05 21:14:47 +0000 |
---|---|---|
committer | matty%chariot.net.au <> | 2002-10-05 21:14:47 +0000 |
commit | f9a1a427d40e906bb7c8a06864fc22b31b4361ff (patch) | |
tree | 0466733fc2a617c2e690a142aa8ea556d18eb7b0 /sanitycheck.cgi | |
parent | 1d45e9b3107746c7562e66b95b418d16fc42f34f (diff) | |
download | bugs-f9a1a427d40e906bb7c8a06864fc22b31b4361ff.tar bugs-f9a1a427d40e906bb7c8a06864fc22b31b4361ff.tar.gz bugs-f9a1a427d40e906bb7c8a06864fc22b31b4361ff.tar.bz2 bugs-f9a1a427d40e906bb7c8a06864fc22b31b4361ff.tar.xz bugs-f9a1a427d40e906bb7c8a06864fc22b31b4361ff.zip |
Bug #93667: Rewrite double cross checking.
Diffstat (limited to 'sanitycheck.cgi')
-rwxr-xr-x | sanitycheck.cgi | 115 |
1 files changed, 47 insertions, 68 deletions
diff --git a/sanitycheck.cgi b/sanitycheck.cgi index 34f93b690..caeb25138 100755 --- a/sanitycheck.cgi +++ b/sanitycheck.cgi @@ -287,80 +287,59 @@ CrossCheck("products", "id", DateCheck("groups", "last_changed"); DateCheck("profiles", "refreshed_when"); - ########################################################################### -# Perform product specific field checks +# Perform double field referential (cross) checks ########################################################################### - -Status("Checking version/products"); - -SendSQL("select distinct product_id, version from bugs"); -while (@row = FetchSQLData()) { - my @copy = @row; - push(@checklist, \@copy); -} - -foreach my $ref (@checklist) { - my ($product_id, $version) = (@$ref); - SendSQL("select count(*) from versions where product_id = $product_id and value = " . SqlQuote($version)); - if (FetchOneColumn() != 1) { - Alert("Bug(s) found with invalid product ID/version: $product_id/$version"); - } -} - -# Adding check for Target Milestones / products - matthew@zeroknowledge.com -Status("Checking milestone/products"); - -@checklist = (); -SendSQL("select distinct product_id, target_milestone from bugs"); -while (@row = FetchSQLData()) { - my @copy = @row; - push(@checklist, \@copy); -} - -foreach my $ref (@checklist) { - my ($product_id, $milestone) = (@$ref); - SendSQL("SELECT count(*) FROM milestones WHERE product_id = $product_id AND value = " . SqlQuote($milestone)); - if(FetchOneColumn() != 1) { - Alert("Bug(s) found with invalid product ID/milestone: $product_id/$milestone"); - } -} - - -Status("Checking default milestone/products"); - -@checklist = (); -SendSQL("select id, defaultmilestone from products"); -while (@row = FetchSQLData()) { - my @copy = @row; - push(@checklist, \@copy); -} - -foreach my $ref (@checklist) { - my ($product_id, $milestone) = (@$ref); - SendSQL("SELECT count(*) FROM milestones WHERE product_id = $product_id AND value = " . SqlQuote($milestone)); - if(FetchOneColumn() != 1) { - Alert("Product(s) found with invalid default milestone: $product_id/$milestone"); + +sub DoubleCrossCheck { + my $table = shift @_; + my $field1 = shift @_; + my $field2 = shift @_; + + Status("Checking references to $table.$field1 / $table.$field2"); + + while (@_) { + my $ref = shift @_; + my ($refertable, $referfield1, $referfield2, $keyname) = @$ref; + + Status("... from $refertable.$referfield1 / $refertable.$referfield2"); + + SendSQL("SELECT DISTINCT $refertable.$referfield1, $refertable.$referfield2" . ($keyname ? ", $refertable.$keyname" : '') . " " . + "FROM $refertable LEFT JOIN $table " . + " ON $refertable.$referfield1 = $table.$field1 " . + " AND $refertable.$referfield2 = $table.$field2 " . + "WHERE $table.$field1 IS NULL " . + " AND $table.$field2 IS NULL " . + " AND $refertable.$referfield1 IS NOT NULL " . + " AND $refertable.$referfield2 IS NOT NULL"); + + while (MoreSQLData()) { + my ($value1, $value2, $key) = FetchSQLData(); + + my $alert = "Bad values $value1, $value2 found in " . + "$refertable.$referfield1 / $refertable.$referfield2"; + if ($keyname) { + if ($keyname eq 'bug_id') { + $alert .= ' (bug ' . BugLink($key) . ')'; + } + else { + $alert .= " ($keyname == '$key')"; + } + } + Alert($alert); + } } } +DoubleCrossCheck("components", "product_id", "id", + ["bugs", "product_id", "component_id", "bug_id"]); -Status("Checking components/products"); - -@checklist = (); -SendSQL("select distinct product_id, component_id from bugs"); -while (@row = FetchSQLData()) { - my @copy = @row; - push(@checklist, \@copy); -} - -foreach my $ref (@checklist) { - my ($product_id, $component_id) = (@$ref); - SendSQL("select count(*) from components where product_id = $product_id and id = $component_id"); - if (FetchOneColumn() != 1) { - Alert(qq{Bug(s) found with invalid product/component ID: $product_id/$component_id}); - } -} +DoubleCrossCheck("versions", "product_id", "value", + ["bugs", "product_id", "version", "bug_id"]); + +DoubleCrossCheck("milestones", "product_id", "value", + ["bugs", "product_id", "target_milestone", "bug_id"], + ["products", "id", "defaultmilestone", "name"]); ########################################################################### # Perform login checks |