aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2006-06-08 04:35:53 +0000
committerlpsolit%gmail.com <>2006-06-08 04:35:53 +0000
commita609c6c3f0ac219b997dbaf4d1aaa6c7778c5939 (patch)
tree45e105fe9b2984c4169978872e94ac0703df6f13 /sanitycheck.cgi
parentPatch for bug 340154: readd #chart anchor in query.cgi; patch by Vlad Dascalu... (diff)
downloadbugzilla-a609c6c3f0ac219b997dbaf4d1aaa6c7778c5939.tar.gz
bugzilla-a609c6c3f0ac219b997dbaf4d1aaa6c7778c5939.tar.bz2
bugzilla-a609c6c3f0ac219b997dbaf4d1aaa6c7778c5939.zip
Bug 339667: Attachment data not deleted when deleting a component or a product - Patch by Frédéric Buclin <LpSolit@gmail.com> r=wicked a=justdave
Diffstat (limited to 'sanitycheck.cgi')
-rwxr-xr-xsanitycheck.cgi37
1 files changed, 35 insertions, 2 deletions
diff --git a/sanitycheck.cgi b/sanitycheck.cgi
index 15861b9d8..b887deeff 100755
--- a/sanitycheck.cgi
+++ b/sanitycheck.cgi
@@ -249,7 +249,7 @@ if (defined $cgi->param('rescanallBugMail')) {
# Remove all references to deleted bugs
###########################################################################
-if (defined $cgi->param('remove_invalid_references')) {
+if (defined $cgi->param('remove_invalid_bug_references')) {
Status("OK, now removing all references to deleted bugs.");
$dbh->bz_lock_tables('attachments WRITE', 'bug_group_map WRITE',
@@ -280,6 +280,30 @@ if (defined $cgi->param('remove_invalid_references')) {
Status("All references to deleted bugs have been removed.");
}
+###########################################################################
+# Remove all references to deleted attachments
+###########################################################################
+
+if (defined $cgi->param('remove_invalid_attach_references')) {
+ Status("OK, now removing all references to deleted attachments.");
+
+ $dbh->bz_lock_tables('attachments WRITE', 'attach_data WRITE');
+
+ my $attach_ids =
+ $dbh->selectcol_arrayref('SELECT attach_data.id
+ FROM attach_data
+ LEFT JOIN attachments
+ ON attachments.attach_id = attach_data.id
+ WHERE attachments.attach_id IS NULL');
+
+ if (scalar(@$attach_ids)) {
+ $dbh->do('DELETE FROM attach_data WHERE id IN (' .
+ join(',', @$attach_ids) . ')');
+ }
+
+ $dbh->bz_unlock_tables();
+ Status("All references to deleted attachments have been removed.");
+}
print "OK, now running sanity checks.<p>\n";
@@ -348,7 +372,13 @@ sub CrossCheck {
}
# References to non existent bugs can be safely removed, bug 288461
if ($table eq 'bugs' && $has_bad_references) {
- print qq{<a href="sanitycheck.cgi?remove_invalid_references=1">Remove invalid references to non existent bugs.</a><p>\n};
+ print qq{<a href="sanitycheck.cgi?remove_invalid_bug_references=1">
+ Remove invalid references to non existent bugs.</a><p>\n};
+ }
+ # References to non existent attachments can be safely removed.
+ if ($table eq 'attachments' && $has_bad_references) {
+ print qq{<a href="sanitycheck.cgi?remove_invalid_attach_references=1">
+ Remove invalid references to non existent attachments.</a><p>\n};
}
}
}
@@ -453,6 +483,9 @@ CrossCheck('whine_events', 'id',
['whine_queries', 'eventid'],
['whine_schedules', 'eventid']);
+CrossCheck('attachments', 'attach_id',
+ ['attach_data', 'id']);
+
###########################################################################
# Perform double field referential (cross) checks
###########################################################################