summaryrefslogtreecommitdiffstats
path: root/editcomponents.cgi
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 /editcomponents.cgi
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 'editcomponents.cgi')
-rwxr-xr-xeditcomponents.cgi76
1 files changed, 27 insertions, 49 deletions
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;
}