From 8e8093b4fbcaa75a71134d621f6d328f13390d07 Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Tue, 31 May 2011 15:16:15 +0200 Subject: [PATCH] BUG6436 Don't allow deletion of an itemtype used in items.itype Signed-off-by: Owen Leonard Signed-off-by: Chris Cormack --- admin/itemtypes.pl | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index 1a33a219c5..3219da340e 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( -- 2.39.5