From f1e5b2aa558a8b9475f0fec798d47f06cbec0697 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Wed, 13 Apr 2005 00:24:33 +0000 Subject: [PATCH] =?utf8?q?Bug=20288461:=20sanitycheck.cgi=20should=20permi?= =?utf8?q?t=20to=20clean=20all=20invalid=20references=20to=20deleted=20bug?= =?utf8?q?s=20-=20Patch=20by=20Fr=C3=A9d=C3=A9ric=20Buclin=20=20r=3Dglob=20a=3Djustdave?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- sanitycheck.cgi | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/sanitycheck.cgi b/sanitycheck.cgi index 89b657e907..e8f4988fb3 100755 --- a/sanitycheck.cgi +++ b/sanitycheck.cgi @@ -175,6 +175,10 @@ if (defined $cgi->param('cleangroupsnow')) { "- reduced from $before records to $after records"); } +########################################################################### +# Send unsent mail +########################################################################### + if (defined $cgi->param('rescanallBugMail')) { require Bugzilla::BugMail; @@ -202,6 +206,42 @@ if (defined $cgi->param('rescanallBugMail')) { exit; } +########################################################################### +# Remove all references to deleted bugs +########################################################################### + +if (defined $cgi->param('remove_invalid_references')) { + Status("OK, now removing all references to deleted bugs."); + + $dbh->bz_lock_tables('attachments WRITE', 'bug_group_map WRITE', + 'bugs_activity WRITE', 'cc WRITE', + 'dependencies WRITE', 'duplicates WRITE', + 'flags WRITE', 'keywords WRITE', + 'longdescs WRITE', 'votes WRITE', 'bugs READ'); + + foreach my $pair ('attachments/', 'bug_group_map/', 'bugs_activity/', 'cc/', + 'dependencies/blocked', 'dependencies/dependson', + 'duplicates/dupe', 'duplicates/dupe_of', + 'flags/', 'keywords/', 'longdescs/', 'votes/') { + + my ($table, $field) = split('/', $pair); + $field ||= "bug_id"; + + my $bug_ids = + $dbh->selectcol_arrayref("SELECT $table.$field FROM $table + LEFT JOIN bugs ON $table.$field = bugs.bug_id + WHERE bugs.bug_id IS NULL"); + + if (scalar(@$bug_ids)) { + $dbh->do("DELETE FROM $table WHERE $field IN (" . join(',', @$bug_ids) . ")"); + } + } + + $dbh->bz_unlock_tables(); + Status("All references to deleted bugs have been removed."); +} + + print "OK, now running sanity checks.

\n"; ########################################################################### @@ -247,6 +287,7 @@ sub CrossCheck { "WHERE $table.$field IS NULL " . " AND $refertable.$referfield IS NOT NULL"); + my $has_bad_references = 0; while (MoreSQLData()) { my ($value, $key) = FetchSQLData(); if (!$exceptions{$value}) { @@ -260,8 +301,13 @@ sub CrossCheck { } } Alert($alert); + $has_bad_references = 1; } } + # References to non existent bugs can be safely removed, bug 288461 + if ($table eq 'bugs' && $has_bad_references) { + print qq{Remove invalid references to non existent bugs.

\n}; + } } } -- 2.47.3