From: lpsolit%gmail.com <> Date: Mon, 23 Nov 2009 22:46:47 +0000 (+0000) Subject: Bug 451716: Deleting a product does not remove its entries from the 'Series' table... X-Git-Tag: bugzilla-3.5.3~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2296f779df4debf3d7aa3fc1f2b648e2c929e061;p=thirdparty%2Fbugzilla.git Bug 451716: Deleting a product does not remove its entries from the 'Series' table - Patch by Frédéric Buclin r=gerv a=LpSolit --- diff --git a/Bugzilla/Product.pm b/Bugzilla/Product.pm index 7feaa48623..d6eeab1232 100644 --- a/Bugzilla/Product.pm +++ b/Bugzilla/Product.pm @@ -376,7 +376,7 @@ sub update { } sub remove_from_db { - my $self = shift; + my ($self, $params) = @_; my $user = Bugzilla->user; my $dbh = Bugzilla->dbh; @@ -399,8 +399,31 @@ sub remove_from_db { } } - # XXX - This line can go away as soon as bug 427455 is fixed. - $dbh->do("DELETE FROM group_control_map WHERE product_id = ?", undef, $self->id); + if ($params->{delete_series}) { + my $series_ids = + $dbh->selectcol_arrayref('SELECT series_id + FROM series + INNER JOIN series_categories + ON series_categories.id = series.category + WHERE series_categories.name = ?', + undef, $self->name); + + $dbh->do('DELETE FROM series WHERE ' . $dbh->sql_in('series_id', $series_ids)); + + # If no subcategory uses this product name, completely purge it. + my $in_use = + $dbh->selectrow_array('SELECT 1 + FROM series + INNER JOIN series_categories + ON series_categories.id = series.subcategory + WHERE series_categories.name = ? ' . + $dbh->sql_limit(1), + undef, $self->name); + if (!$in_use) { + $dbh->do('DELETE FROM series_categories WHERE name = ?', undef, $self->name); + } + } + $dbh->do("DELETE FROM products WHERE id = ?", undef, $self->id); $dbh->bz_commit_transaction(); diff --git a/editproducts.cgi b/editproducts.cgi index e1356abbc3..1d43354665 100755 --- a/editproducts.cgi +++ b/editproducts.cgi @@ -233,7 +233,7 @@ if ($action eq 'delete') { my $product = $user->check_can_admin_product($product_name); check_token_data($token, 'delete_product'); - $product->remove_from_db; + $product->remove_from_db({ delete_series => scalar $cgi->param('delete_series')}); delete_token($token); $vars->{'message'} = 'product_deleted'; diff --git a/template/en/default/admin/products/confirm-delete.html.tmpl b/template/en/default/admin/products/confirm-delete.html.tmpl index d350bdb909..f4a04b86f5 100644 --- a/template/en/default/admin/products/confirm-delete.html.tmpl +++ b/template/en/default/admin/products/confirm-delete.html.tmpl @@ -248,6 +248,11 @@

Do you really want to delete this product?

+ +