From abd45dfcec0864ad60de2df4c7bd39a336436490 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 1 Feb 2017 17:01:37 +1300 Subject: [PATCH] Bug 17944 - Moved the DBIx code into the ItemType.pm file --- Koha/ItemType.pm | 14 ++++++++++++++ admin/itemtypes.pl | 11 +++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index 48df808..87aa644 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -81,6 +81,20 @@ sub translated_descriptions { } @translated_descriptions ]; } + +=head3 get_items_and_biblioitems + +=cut + +sub get_items_and_biblioitems { + my $itemtype_code = $_[1]; + my $schema = Koha::Database->new()->schema(); + my $itemtotal = $schema->resultset('Item')->search({ 'itype' => $itemtype_code})->count; + my $bibliototal = $schema->resultset('Biblioitem')->search({ 'itemtype' => $itemtype_code})->count; + my $overalltotal = $itemtotal + $bibliototal; + return $overalltotal; +} + =head3 type =cut diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index e926418..373a16c 100755 --- a/admin/itemtypes.pl +++ b/admin/itemtypes.pl @@ -32,7 +32,7 @@ use C4::Context; use C4::Auth; use C4::Output; -use Koha::ItemTypes; +use Koha::ItemType; use Koha::Localizations; my $input = new CGI; @@ -140,12 +140,7 @@ if ( $op eq 'add_form' ) { } elsif ( $op eq 'delete_confirm' ) { - my $schema = Koha::Database->new()->schema(); - my $itemtotal = $schema->resultset('Item')->search({ 'itype' => $itemtype_code})->count; - my $bibliototal = $schema->resultset('Biblioitem')->search({ 'itemtype' => $itemtype_code})->count; - - my $overalltotal = $itemtotal + $bibliototal; - + my $overalltotal = Koha::ItemType->get_items_and_biblioitems($itemtype_code); if ($overalltotal) { push @messages, { type => 'error', code => 'cannot_be_deleted', total => $overalltotal }; $op = 'list'; @@ -156,7 +151,7 @@ if ( $op eq 'add_form' ) { } elsif ( $op eq 'delete_confirmed' ) { - my $itemtype = Koha::ItemTypes->find($itemtype_code); + my $itemtype = Koha::ItemType->get_items_and_biblioitems($itemtype_code); my $deleted = eval { $itemtype->delete }; if ( $@ or not $deleted ) { push @messages, { type => 'error', code => 'error_on_delete' }; -- 2.1.4