From fb3927cd505d3874f8cac5db58891383be2a6e7a Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Sun, 22 Jan 2017 01:52:50 +0000 Subject: [PATCH] [SIGNED-OFF] Bug 17944 - Moved the sql code from itemtypes.pl into Koha/ItemTypes.pm Signed-off-by: Owen Leonard --- Koha/ItemTypes.pm | 17 +++++++++++++++++ admin/itemtypes.pl | 10 +--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Koha/ItemTypes.pm b/Koha/ItemTypes.pm index 92fea9c..9eb26df 100644 --- a/Koha/ItemTypes.pm +++ b/Koha/ItemTypes.pm @@ -39,6 +39,23 @@ Koha::ItemTypes - Koha ItemType Object set class =cut +sub check_items_and_biblioitems { + my ($itemtype_code) = @_; + + my $dbh = C4::Context->dbh; + + # Check both items and biblioitems + my ($total) = $dbh->selectrow_array( ' + SELECT COUNT(*) AS total FROM ( + SELECT itemtype AS t FROM biblioitems + UNION ALL + SELECT itype AS t FROM items + ) AS tmp + WHERE tmp.t=? + ', {}, $itemtype_code ); + return $total; +} + sub _type { return 'Itemtype'; } diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index c8c224e..81bb391 100755 --- a/admin/itemtypes.pl +++ b/admin/itemtypes.pl @@ -139,15 +139,7 @@ if ( $op eq 'add_form' ) { $op = 'list'; } elsif ( $op eq 'delete_confirm' ) { - # Check both items and biblioitems - my ($total) = $dbh->selectrow_array( ' - SELECT COUNT(*) AS total FROM ( - SELECT itemtype AS t FROM biblioitems - UNION ALL - SELECT itype AS t FROM items - ) AS tmp - WHERE tmp.t=? - ', {}, $itemtype_code ); + my $total = Koha::ItemTypes->check_items_and_biblioitems($itemtype_code); if ($total) { push @messages, { type => 'error', code => 'cannot_be_deleted', total => $total }; -- 2.1.4