[Koha-patches] [PATCH] [SIGNED-OFF] BUG6436 Don't allow deletion of an itemtype used in items.itype

Owen Leonard oleonard at myacpl.org
Tue May 31 22:14:34 CEST 2011


From: Fridolyn SOMERS <fridolyn.somers at progilone.fr>


Signed-off-by: Owen Leonard <oleonard at myacpl.org>
---
 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



More information about the Koha-patches mailing list