@@ -, +, @@ Koha/ItemTypes.pm --- Koha/ItemTypes.pm | 17 +++++++++++++++++ admin/itemtypes.pl | 10 +--------- 2 files changed, 18 insertions(+), 9 deletions(-) --- a/Koha/ItemTypes.pm +++ a/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'; } --- a/admin/itemtypes.pl +++ a/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 }; --