@@ -, +, @@ database then a message telling you the number of items of that itemtype there are will be displayed. written in this file. in this file. There is however DBIx code, for example $schema->resultset('Item')->search({ 'itype' => $itemtype_code} ); which is searching for items with the itype value matching $itemtype_code value. resulting message DBIx code is working as intended --- Koha/ItemTypes.pm | 17 ----------------- admin/itemtypes.pl | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 21 deletions(-) --- a/Koha/ItemTypes.pm +++ a/Koha/ItemTypes.pm @@ -62,23 +62,6 @@ sub search_with_localization { =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 @@ -137,12 +137,20 @@ if ( $op eq 'add_form' ) { $searchfield = ''; $op = 'list'; -} elsif ( $op eq 'delete_confirm' ) { - my $total = Koha::ItemTypes->check_items_and_biblioitems($itemtype_code); + } elsif ( $op eq 'delete_confirm' ) { - if ($total) { - push @messages, { type => 'error', code => 'cannot_be_deleted', total => $total }; + my $context = C4::Context->new; + my $schema = Koha::Database->new()->schema(); + my $itemtotal = $schema->resultset('Item')->search({ 'itype' => $itemtype_code} ); + my $bibliototal = $schema->resultset('Biblioitem')->search({ 'itemtype' => $itemtype_code} ); + + $itemtotal->count; + $bibliototal->count; + my $overalltotal = $itemtotal + $bibliototal; + + if ($overalltotal) { + push @messages, { type => 'error', code => 'cannot_be_deleted', total => $overalltotal }; $op = 'list'; } else { my $itemtype = Koha::ItemTypes->find($itemtype_code); @@ -150,6 +158,7 @@ if ( $op eq 'add_form' ) { } } elsif ( $op eq 'delete_confirmed' ) { + my $itemtype = Koha::ItemTypes->find($itemtype_code); my $deleted = eval { $itemtype->delete }; if ( $@ or not $deleted ) { --