Commit f9a1a427 authored by matty%chariot.net.au's avatar matty%chariot.net.au

Bug #93667: Rewrite double cross checking.

parent 1d45e9b3
...@@ -287,80 +287,59 @@ CrossCheck("products", "id", ...@@ -287,80 +287,59 @@ CrossCheck("products", "id",
DateCheck("groups", "last_changed"); DateCheck("groups", "last_changed");
DateCheck("profiles", "refreshed_when"); DateCheck("profiles", "refreshed_when");
########################################################################### ###########################################################################
# Perform product specific field checks # Perform double field referential (cross) checks
########################################################################### ###########################################################################
Status("Checking version/products"); sub DoubleCrossCheck {
my $table = shift @_;
SendSQL("select distinct product_id, version from bugs"); my $field1 = shift @_;
while (@row = FetchSQLData()) { my $field2 = shift @_;
my @copy = @row;
push(@checklist, \@copy); Status("Checking references to $table.$field1 / $table.$field2");
}
while (@_) {
foreach my $ref (@checklist) { my $ref = shift @_;
my ($product_id, $version) = (@$ref); my ($refertable, $referfield1, $referfield2, $keyname) = @$ref;
SendSQL("select count(*) from versions where product_id = $product_id and value = " . SqlQuote($version));
if (FetchOneColumn() != 1) { Status("... from $refertable.$referfield1 / $refertable.$referfield2");
Alert("Bug(s) found with invalid product ID/version: $product_id/$version");
} SendSQL("SELECT DISTINCT $refertable.$referfield1, $refertable.$referfield2" . ($keyname ? ", $refertable.$keyname" : '') . " " .
} "FROM $refertable LEFT JOIN $table " .
" ON $refertable.$referfield1 = $table.$field1 " .
# Adding check for Target Milestones / products - matthew@zeroknowledge.com " AND $refertable.$referfield2 = $table.$field2 " .
Status("Checking milestone/products"); "WHERE $table.$field1 IS NULL " .
" AND $table.$field2 IS NULL " .
@checklist = (); " AND $refertable.$referfield1 IS NOT NULL " .
SendSQL("select distinct product_id, target_milestone from bugs"); " AND $refertable.$referfield2 IS NOT NULL");
while (@row = FetchSQLData()) {
my @copy = @row; while (MoreSQLData()) {
push(@checklist, \@copy); my ($value1, $value2, $key) = FetchSQLData();
}
my $alert = "Bad values $value1, $value2 found in " .
foreach my $ref (@checklist) { "$refertable.$referfield1 / $refertable.$referfield2";
my ($product_id, $milestone) = (@$ref); if ($keyname) {
SendSQL("SELECT count(*) FROM milestones WHERE product_id = $product_id AND value = " . SqlQuote($milestone)); if ($keyname eq 'bug_id') {
if(FetchOneColumn() != 1) { $alert .= ' (bug ' . BugLink($key) . ')';
Alert("Bug(s) found with invalid product ID/milestone: $product_id/$milestone"); }
} else {
} $alert .= " ($keyname == '$key')";
}
}
Status("Checking default milestone/products"); Alert($alert);
}
@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");
} }
} }
DoubleCrossCheck("components", "product_id", "id",
["bugs", "product_id", "component_id", "bug_id"]);
Status("Checking components/products"); DoubleCrossCheck("versions", "product_id", "value",
["bugs", "product_id", "version", "bug_id"]);
@checklist = ();
SendSQL("select distinct product_id, component_id from bugs"); DoubleCrossCheck("milestones", "product_id", "value",
while (@row = FetchSQLData()) { ["bugs", "product_id", "target_milestone", "bug_id"],
my @copy = @row; ["products", "id", "defaultmilestone", "name"]);
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});
}
}
########################################################################### ###########################################################################
# Perform login checks # Perform login checks
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment