From 1505a9da4070e5364139f79e531cecfb14e20faa Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Fri, 25 Aug 2006 04:27:20 +0000 Subject: Bug 170019: Sanity check for flags in right product - Patch by Frédéric Buclin r=mkanat a=myk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sanitycheck.cgi | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'sanitycheck.cgi') diff --git a/sanitycheck.cgi b/sanitycheck.cgi index 174edc9c3..b085feb9d 100755 --- a/sanitycheck.cgi +++ b/sanitycheck.cgi @@ -756,6 +756,58 @@ if (defined $cgi->param('rebuildkeywordcache')) { $dbh->bz_unlock_tables(); } +########################################################################### +# Check for flags being in incorrect products and components +########################################################################### + +Status('Checking for flags being in the wrong product/component'); + +my $invalid_flags = $dbh->selectall_arrayref( + 'SELECT DISTINCT flags.id, flags.bug_id, flags.attach_id + FROM flags + INNER JOIN bugs + ON flags.bug_id = bugs.bug_id + LEFT JOIN flaginclusions AS i + ON flags.type_id = i.type_id + AND (bugs.product_id = i.product_id OR i.product_id IS NULL) + AND (bugs.component_id = i.component_id OR i.component_id IS NULL) + WHERE i.type_id IS NULL'); + +my @invalid_flags = @$invalid_flags; + +$invalid_flags = $dbh->selectall_arrayref( + 'SELECT DISTINCT flags.id, flags.bug_id, flags.attach_id + FROM flags + INNER JOIN bugs + ON flags.bug_id = bugs.bug_id + INNER JOIN flagexclusions AS e + ON flags.type_id = e.type_id + WHERE (bugs.product_id = e.product_id OR e.product_id IS NULL) + AND (bugs.component_id = e.component_id OR e.component_id IS NULL)'); + +push(@invalid_flags, @$invalid_flags); + +if (scalar(@invalid_flags)) { + if ($cgi->param('remove_invalid_flags')) { + Status("OK, now deleting invalid flags."); + my @flag_ids = map {$_->[0]} @invalid_flags; + $dbh->bz_lock_tables('flags WRITE'); + # Silently delete these flags, with no notification to requesters/setters. + $dbh->do('DELETE FROM flags WHERE id IN (' . join(',', @flag_ids) .')'); + $dbh->bz_unlock_tables(); + Status("Invalid flags deleted."); + } + else { + foreach my $flag (@$invalid_flags) { + my ($flag_id, $bug_id, $attach_id) = @$flag; + Alert("Invalid flag $flag_id for " . + ($attach_id ? "attachment $attach_id in bug " : "bug ") . BugLink($bug_id)); + } + print qq{Click + here to delete invalid flags

\n}; + } +} + ########################################################################### # General bug checks ########################################################################### -- cgit v1.2.3-24-g4f1b