From 64be6114d94ef5e8bf7056e135a0d4d8c1e7b308 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Wed, 6 Apr 2005 07:19:51 +0000 Subject: Bug 86328: Deleting bugs doesn't delete dependent records properly - Patch by Frederic Buclin r=wurblzap a=justdave --- editproducts.cgi | 96 ++++++++++++++++++++++---------------------------------- 1 file changed, 37 insertions(+), 59 deletions(-) (limited to 'editproducts.cgi') diff --git a/editproducts.cgi b/editproducts.cgi index 2267de922..4713a45ae 100755 --- a/editproducts.cgi +++ b/editproducts.cgi @@ -23,6 +23,7 @@ # Dawn Endico # Joe Robins # Gavin Shelley +# Frédéric Buclin # # Direct any questions on this source code to # @@ -259,7 +260,8 @@ sub PutTrailer (@) # Preliminary checks: # -Bugzilla->login(LOGIN_REQUIRED); +my $user = Bugzilla->login(LOGIN_REQUIRED); +my $whoid = $user->id; print Bugzilla->cgi->header(); @@ -771,79 +773,55 @@ one."; # if ($action eq 'delete') { - PutHeader("Deleting product"); CheckProduct($product); my $product_id = get_product_id($product); - # lock the tables before we start to change everything: - - $dbh->bz_lock_tables('attachments WRITE', - 'bugs WRITE', - 'bugs_activity WRITE', - 'components WRITE', - 'dependencies WRITE', - 'versions WRITE', - 'products WRITE', - 'groups WRITE', - 'group_control_map WRITE', - 'profiles WRITE', - 'milestones WRITE', - 'flaginclusions WRITE', - 'flagexclusions WRITE'); - - # According to MySQL doc I cannot do a DELETE x.* FROM x JOIN Y, - # so I have to iterate over bugs and delete all the indivial entries - # in bugs_activies and attachments. - - if (Param("allowbugdeletion")) { - SendSQL("SELECT bug_id - FROM bugs - WHERE product_id=$product_id"); - while (MoreSQLData()) { - my $bugid = FetchOneColumn(); + my $bug_ids = + $dbh->selectcol_arrayref("SELECT bug_id FROM bugs WHERE product_id = ?", + undef, $product_id); - PushGlobalSQLState(); - SendSQL("DELETE FROM attachments WHERE bug_id=$bugid"); - SendSQL("DELETE FROM bugs_activity WHERE bug_id=$bugid"); - SendSQL("DELETE FROM dependencies WHERE blocked=$bugid"); - PopGlobalSQLState(); + my $nb_bugs = scalar(@$bug_ids); + if ($nb_bugs) { + if (Param("allowbugdeletion")) { + foreach my $bug_id (@$bug_ids) { + my $bug = new Bugzilla::Bug($bug_id, $whoid); + $bug->remove_from_db(); + } } - print "Attachments, bug activity and dependencies deleted.
\n"; - + else { + ThrowUserError("product_has_bugs", { nb => $nb_bugs }); + } + } - # Deleting the rest is easier: + PutHeader("Deleting product"); + print "All references to deleted bugs removed.

\n" if $nb_bugs; - SendSQL("DELETE FROM bugs - WHERE product_id=$product_id"); - print "Bugs deleted.
\n"; - } + $dbh->bz_lock_tables('products WRITE', 'components WRITE', + 'versions WRITE', 'milestones WRITE', + 'group_control_map WRITE', + 'flaginclusions WRITE', 'flagexclusions WRITE'); - SendSQL("DELETE FROM components - WHERE product_id=$product_id"); + $dbh->do("DELETE FROM components WHERE product_id = ?", undef, $product_id); print "Components deleted.
\n"; - SendSQL("DELETE FROM versions - WHERE product_id=$product_id"); - print "Versions deleted.

\n"; + $dbh->do("DELETE FROM versions WHERE product_id = ?", undef, $product_id); + print "Versions deleted.
\n"; - # deleting associated target milestones - matthew@zeroknowledge.com - SendSQL("DELETE FROM milestones - WHERE product_id=$product_id"); - print "Milestones deleted.
\n"; + $dbh->do("DELETE FROM milestones WHERE product_id = ?", undef, $product_id); + print "Milestones deleted.

\n"; - SendSQL("DELETE FROM group_control_map - WHERE product_id=$product_id"); + $dbh->do("DELETE FROM group_control_map WHERE product_id = ?", + undef, $product_id); print "Group controls deleted.
\n"; - SendSQL("DELETE FROM flaginclusions - WHERE product_id=$product_id"); - SendSQL("DELETE FROM flagexclusions - WHERE product_id=$product_id"); - print "Flag inclusions and exclusions deleted.
\n"; + $dbh->do("DELETE FROM flaginclusions WHERE product_id = ?", + undef, $product_id); + $dbh->do("DELETE FROM flagexclusions WHERE product_id = ?", + undef, $product_id); + print "Flag inclusions and exclusions deleted.

\n"; - SendSQL("DELETE FROM products - WHERE id=$product_id"); - print "Product '$product' deleted.
\n"; + $dbh->do("DELETE FROM products WHERE id = ?", undef, $product_id); + print "Product '$product' deleted.

\n"; $dbh->bz_unlock_tables(); -- cgit v1.2.3-24-g4f1b