From 250276c89f5dfc4b6d926a2c1826d3776e7e6f35 Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Tue, 31 May 2011 15:16:15 +0200 Subject: [PATCH] [SIGNED-OFF] BUG6436 Don't allow deletion of an itemtype used in items.itype Content-Type: text/plain; charset="utf-8" Signed-off-by: Owen Leonard --- admin/itemtypes.pl | 20 +++++++++++--------- 1 files changed, 11 insertions(+), 9 deletions(-) diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index 1a33a21..3219da3 100755 --- a/admin/itemtypes.pl +++ b/admin/itemtypes.pl @@ -188,15 +188,17 @@ elsif ( $op eq 'add_validate' ) { # called by default form, used to confirm deletion of data in DB } elsif ( $op eq 'delete_confirm' ) { - # Check both categoryitem and biblioitems, see Bug 199 - my $total = 0; - for my $table ('biblioitems') { - my $sth = - $dbh->prepare( - "select count(*) as total from $table where itemtype=?"); - $sth->execute($itemtype); - $total += $sth->fetchrow_hashref->{total}; - } + # Check both items and biblioitems + my $sth = $dbh->prepare(' + SELECT COUNT(*) AS total FROM ( + SELECT itemtype AS t FROM biblioitems + UNION + SELECT itype AS t FROM items + ) AS tmp + WHERE tmp.t=? + '); + $sth->execute($itemtype); + my $total = $sth->fetchrow_hashref->{'total'}; my $sth = $dbh->prepare( -- 1.7.3