summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Bug.pm
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2005-04-06 09:19:51 +0200
committerlpsolit%gmail.com <>2005-04-06 09:19:51 +0200
commit64be6114d94ef5e8bf7056e135a0d4d8c1e7b308 (patch)
treedd8ae4a27c0da72798e688a65b0fe91f265c9aa9 /Bugzilla/Bug.pm
parent3541f13ea528fa84bbbf5270376044266c18d763 (diff)
downloadbugzilla-64be6114d94ef5e8bf7056e135a0d4d8c1e7b308.tar.gz
bugzilla-64be6114d94ef5e8bf7056e135a0d4d8c1e7b308.tar.xz
Bug 86328: Deleting bugs doesn't delete dependent records properly - Patch by Frederic Buclin <LpSolit@gmail.com> r=wurblzap a=justdave
Diffstat (limited to 'Bugzilla/Bug.pm')
-rwxr-xr-xBugzilla/Bug.pm55
1 files changed, 55 insertions, 0 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 87bf96e25..5017196b3 100755
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -23,6 +23,7 @@
# Bradley Baetz <bbaetz@acm.org>
# Dave Miller <justdave@bugzilla.org>
# Max Kanat-Alexander <mkanat@kerio.com>
+# Frédéric Buclin <LpSolit@gmail.com>
package Bugzilla::Bug;
@@ -217,6 +218,60 @@ sub initBug {
return $self;
}
+# This is the correct way to delete bugs from the DB.
+# No bug should be deleted from anywhere else except from here.
+#
+sub remove_from_db {
+ my ($self) = @_;
+ my $dbh = Bugzilla->dbh;
+
+ if ($self->{'error'}) {
+ ThrowCodeError("bug_error", { bug => $self });
+ }
+
+ my $bug_id = $self->{'bug_id'};
+
+ # tables having 'bugs.bug_id' as a foreign key:
+ # - attachments
+ # - bug_group_map
+ # - bugs
+ # - bugs_activity
+ # - cc
+ # - dependencies
+ # - duplicates
+ # - flags
+ # - keywords
+ # - longdescs
+ # - votes
+
+ $dbh->bz_lock_tables('attachments WRITE', 'bug_group_map WRITE',
+ 'bugs WRITE', 'bugs_activity WRITE', 'cc WRITE',
+ 'dependencies WRITE', 'duplicates WRITE',
+ 'flags WRITE', 'keywords WRITE',
+ 'longdescs WRITE', 'votes WRITE');
+
+ $dbh->do("DELETE FROM bug_group_map WHERE bug_id = ?", undef, $bug_id);
+ $dbh->do("DELETE FROM bugs_activity WHERE bug_id = ?", undef, $bug_id);
+ $dbh->do("DELETE FROM cc WHERE bug_id = ?", undef, $bug_id);
+ $dbh->do("DELETE FROM dependencies WHERE blocked = ? OR dependson = ?",
+ undef, ($bug_id, $bug_id));
+ $dbh->do("DELETE FROM duplicates WHERE dupe = ? OR dupe_of = ?",
+ undef, ($bug_id, $bug_id));
+ $dbh->do("DELETE FROM flags WHERE bug_id = ?", undef, $bug_id);
+ $dbh->do("DELETE FROM keywords WHERE bug_id = ?", undef, $bug_id);
+ $dbh->do("DELETE FROM longdescs WHERE bug_id = ?", undef, $bug_id);
+ $dbh->do("DELETE FROM votes WHERE bug_id = ?", undef, $bug_id);
+ # Several of the previous tables also depend on attach_id.
+ $dbh->do("DELETE FROM attachments WHERE bug_id = ?", undef, $bug_id);
+ $dbh->do("DELETE FROM bugs WHERE bug_id = ?", undef, $bug_id);
+
+ $dbh->bz_unlock_tables();
+
+ # Now this bug no longer exists
+ $self->DESTROY;
+ return $self;
+}
+
#####################################################################
# Accessors
#####################################################################