]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 451716: Deleting a product does not remove its entries from the 'Series' table...
authorlpsolit%gmail.com <>
Mon, 23 Nov 2009 22:46:47 +0000 (22:46 +0000)
committerlpsolit%gmail.com <>
Mon, 23 Nov 2009 22:46:47 +0000 (22:46 +0000)
Bugzilla/Product.pm
editproducts.cgi
template/en/default/admin/products/confirm-delete.html.tmpl

index 7feaa48623350ab16ddbb02bec99ab9d321f1e24..d6eeab12328a1340df0a1f2f7990c898a18f6b9a 100644 (file)
@@ -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();
index e1356abbc36d8f2a22fef18167c4f07678802749..1d43354665bd033f957a8ea364923f6c80b177eb 100755 (executable)
@@ -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';
index d350bdb909bf0f756462cb535eca762998abcc64..f4a04b86f5d40703b465e3cb3f68e0558b22a6db 100644 (file)
   <p>Do you really want to delete this product?</p>
 
   <form method="post" action="editproducts.cgi">
+    <input type="checkbox" id="delete_series" name="delete_series" value=1>
+    <label for="delete_series">
+      Delete all related series (you can also delete them later, by visiting
+      the <a href="chart.cgi?category=[% product.name FILTER html %]">New Charts page</a>.)
+    </label><p>
     <input type="submit" id="delete" value="Yes, delete">
     <input type="hidden" name="action" value="delete">
     <input type="hidden" name="product" value="[% product.name FILTER html %]">