From 2296f779df4debf3d7aa3fc1f2b648e2c929e061 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Mon, 23 Nov 2009 22:46:47 +0000 Subject: =?UTF-8?q?Bug=20451716:=20Deleting=20a=20product=20does=20not=20r?= =?UTF-8?q?emove=20its=20entries=20from=20the=20'Series'=20table=20-=20Pat?= =?UTF-8?q?ch=20by=20Fr=C3=83=C2=A9d=C3=83=C2=A9ric=20Buclin=20=20r=3Dgerv=20a=3DLpSolit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bugzilla/Product.pm | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/Product.pm b/Bugzilla/Product.pm index 7feaa4862..d6eeab123 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(); -- cgit v1.2.1