diff options
author | lpsolit%gmail.com <> | 2005-04-06 09:19:51 +0200 |
---|---|---|
committer | lpsolit%gmail.com <> | 2005-04-06 09:19:51 +0200 |
commit | 64be6114d94ef5e8bf7056e135a0d4d8c1e7b308 (patch) | |
tree | dd8ae4a27c0da72798e688a65b0fe91f265c9aa9 /editversions.cgi | |
parent | 3541f13ea528fa84bbbf5270376044266c18d763 (diff) | |
download | bugzilla-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 'editversions.cgi')
-rwxr-xr-x | editversions.cgi | 63 |
1 files changed, 15 insertions, 48 deletions
diff --git a/editversions.cgi b/editversions.cgi index 86c82beea..8d3f4dc8b 100755 --- a/editversions.cgi +++ b/editversions.cgi @@ -21,6 +21,7 @@ # Contributor(s): Holger Schurig <holgerschurig@nikocity.de> # Terry Weissman <terry@mozilla.org> # Gavin Shelley <bugzilla@chimpychompy.org> +# Frédéric Buclin <LpSolit@gmail.com> # # # Direct any questions on this source code to @@ -293,66 +294,32 @@ if ($action eq 'del') { # if ($action eq 'delete') { - - CheckVersion($product,$version); + CheckVersion($product, $version); 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', - 'versions WRITE', - 'dependencies 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. + trick_taint($version); - if (Param("allowbugdeletion")) { - - my $deleted_bug_count = 0; - - SendSQL("SELECT bug_id - FROM bugs - WHERE product_id = $product_id - AND version = " . SqlQuote($version)); - 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(); - - $deleted_bug_count++; - } - - $vars->{'deleted_bug_count'} = $deleted_bug_count; - - # Deleting the rest is easier: - - SendSQL("DELETE FROM bugs - WHERE product_id = $product_id - AND version = " . SqlQuote($version)); + my $nb_bugs = + $dbh->selectrow_array("SELECT COUNT(bug_id) FROM bugs + WHERE product_id = ? AND version = ?", + undef, ($product_id, $version)); + # The version cannot be removed if there are bugs + # associated with it. + if ($nb_bugs) { + ThrowUserError("version_has_bugs", { nb => $nb_bugs }); } - SendSQL("DELETE FROM versions - WHERE product_id = $product_id - AND value = " . SqlQuote($version)); - - $dbh->bz_unlock_tables(); + $dbh->do("DELETE FROM versions WHERE product_id = ? AND value = ?", + undef, ($product_id, $version)); unlink "$datadir/versioncache"; $vars->{'name'} = $version; $vars->{'product'} = $product; - $template->process("admin/versions/deleted.html.tmpl", - $vars) - || ThrowTemplateError($template->error()); + $template->process("admin/versions/deleted.html.tmpl", $vars) + || ThrowTemplateError($template->error()); exit; } |