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 --- editcomponents.cgi | 76 +++++++++++++++++++----------------------------------- 1 file changed, 27 insertions(+), 49 deletions(-) (limited to 'editcomponents.cgi') diff --git a/editcomponents.cgi b/editcomponents.cgi index 9dd290db3..6f8bc99f2 100755 --- a/editcomponents.cgi +++ b/editcomponents.cgi @@ -112,7 +112,8 @@ sub CheckComponent ($$) # Preliminary checks: # -Bugzilla->login(LOGIN_REQUIRED); +my $user = Bugzilla->login(LOGIN_REQUIRED); +my $whoid = $user->id; print Bugzilla->cgi->header(); @@ -436,57 +437,36 @@ if ($action eq 'del') { # if ($action eq 'delete') { - CheckComponent($product, $component); - my $component_id = get_component_id(get_product_id($product),$component); - - # lock the tables before we start to change everything: - - $dbh->bz_lock_tables('attachments WRITE', - 'bugs WRITE', - 'bugs_activity WRITE', - 'components WRITE', - 'dependencies 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")) { - my $deleted_bug_count = 0; - - SendSQL("SELECT bug_id - FROM bugs - WHERE component_id = $component_id"); - while (MoreSQLData()) { - my $bugid = FetchOneColumn(); - - 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 $component_id = get_component_id(get_product_id($product), $component); - $deleted_bug_count++; + my $bug_ids = + $dbh->selectcol_arrayref("SELECT bug_id FROM bugs WHERE component_id = ?", + undef, $component_id); + + 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(); + } } + else { + ThrowUserError("component_has_bugs", { nb => $nb_bugs }); + } + } - $vars->{'deleted_bug_count'} = $deleted_bug_count; - - # Deleting the rest is easier: + $vars->{'deleted_bug_count'} = $nb_bugs; - SendSQL("DELETE FROM bugs - WHERE component_id=$component_id"); - } + $dbh->bz_lock_tables('components WRITE', 'flaginclusions WRITE', + 'flagexclusions WRITE'); - SendSQL("DELETE FROM flaginclusions - WHERE component_id=$component_id"); - SendSQL("DELETE FROM flagexclusions - WHERE component_id=$component_id"); - - SendSQL("DELETE FROM components - WHERE id=$component_id"); + $dbh->do("DELETE FROM flaginclusions WHERE component_id = ?", + undef, $component_id); + $dbh->do("DELETE FROM flagexclusions WHERE component_id = ?", + undef, $component_id); + $dbh->do("DELETE FROM components WHERE id = ?", undef, $component_id); $dbh->bz_unlock_tables(); @@ -494,10 +474,8 @@ if ($action eq 'delete') { $vars->{'name'} = $component; $vars->{'product'} = $product; - $template->process("admin/components/deleted.html.tmpl", - $vars) + $template->process("admin/components/deleted.html.tmpl", $vars) || ThrowTemplateError($template->error()); - exit; } -- cgit v1.2.3-24-g4f1b