diff options
author | Frédéric Buclin <LpSolit@gmail.com> | 2011-09-12 18:40:14 +0200 |
---|---|---|
committer | Frédéric Buclin <LpSolit@gmail.com> | 2011-09-12 18:40:14 +0200 |
commit | 63c780370a5fe56ae0aba39fb5924322985c8474 (patch) | |
tree | e2e6f21416b9cfdc70ec0248d264df536c2ce325 | |
parent | 381d530928f57932ab3341e2d06d69b6a647dfd6 (diff) | |
download | bugzilla-63c780370a5fe56ae0aba39fb5924322985c8474.tar.gz bugzilla-63c780370a5fe56ae0aba39fb5924322985c8474.tar.xz |
Bug 686133: Bugzilla crashes when deleting a bug
r=timello a=LpSolit
-rw-r--r-- | Bugzilla/Bug.pm | 61 |
1 files changed, 3 insertions, 58 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 23e07979f..2b526588f 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -1083,71 +1083,16 @@ sub _sync_fulltext { WHERE bug_id = ?', undef, $all, $nopriv_string, $self->id); } - -# 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 }); - } + ThrowCodeError("bug_error", { bug => $self }) if $self->{'error'}; my $bug_id = $self->{'bug_id'}; - - # tables having 'bugs.bug_id' as a foreign key: - # - attachments - # - bug_group_map - # - bugs - # - bugs_activity - # - bugs_fulltext - # - cc - # - dependencies - # - duplicates - # - flags - # - keywords - # - longdescs - - # Also, the attach_data table uses attachments.attach_id as a foreign - # key, and so indirectly depends on a bug deletion too. - - $dbh->bz_start_transaction(); - - $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); - - # The attach_data table doesn't depend on bugs.bug_id directly. - my $attach_ids = - $dbh->selectcol_arrayref("SELECT attach_id FROM attachments - WHERE bug_id = ?", undef, $bug_id); - - if (scalar(@$attach_ids)) { - $dbh->do("DELETE FROM attach_data WHERE " - . $dbh->sql_in('id', $attach_ids)); - } - - # 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->do("DELETE FROM longdescs WHERE bug_id = ?", undef, $bug_id); - - $dbh->bz_commit_transaction(); - - # The bugs_fulltext table doesn't support transactions. + $self->SUPER::remove_from_db(); + # The bugs_fulltext table doesn't support foreign keys. $dbh->do("DELETE FROM bugs_fulltext WHERE bug_id = ?", undef, $bug_id); - - # Now this bug no longer exists - $self->DESTROY; - return $self; } ##################################################################### |