Bugzilla – Attachment 59953 Details for
Bug 17944
Remove the sql code from itemtypes.pl administrative perl script
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17944 - Updates following second tester feedback
Bug-17944---Updates-following-second-tester-feedba.patch (text/plain), 4.45 KB, created by
Alex Buckley
on 2017-02-06 21:37:24 UTC
(
hide
)
Description:
Bug 17944 - Updates following second tester feedback
Filename:
MIME Type:
Creator:
Alex Buckley
Created:
2017-02-06 21:37:24 UTC
Size:
4.45 KB
patch
obsolete
>From b0417b6010b2d8247f2139934c8c5a2a2d817471 Mon Sep 17 00:00:00 2001 >From: Alex Buckley <alexbuckley@catalyst.net.nz> >Date: Sat, 28 Jan 2017 22:38:53 +0000 >Subject: [PATCH] Bug 17944 - Updates following second tester feedback > >Changed function name from get_items_and_biblioitems to is_used > >Added POD for is_used function > >Initial unit test for is_used implemented (not yet working) > >Implemented use of Koha::Items and Koha::Biblioitems instead of using Koha resultsets >--- > Koha/ItemType.pm | 15 +++++++++----- > admin/itemtypes.pl | 4 ++-- > t/db_dependent/Koha/ItemTypes.t | 43 +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 55 insertions(+), 7 deletions(-) > >diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm >index 87aa644..ac65d17 100644 >--- a/Koha/ItemType.pm >+++ b/Koha/ItemType.pm >@@ -82,15 +82,20 @@ sub translated_descriptions { > } > > >-=head3 get_items_and_biblioitems >+=head3 is_used >+my $overalltotal = $ItemType->is_used($itemtype_code) >+ >+Seperately retrieves and counts the number of items and biblioitems with an itemtype code matching the argument $itemtype_code (which is the itemtype code of the itemtype the user is trying to delete). The sum of the two numbers is added together and stored in the $overalltotal variable. >+ >+True (a number greater than 0 which is the sum of items and biblioitems) is returned to admin/itemtypes.pl if there is more than one item and/or biblioitem with a matching itemtype code. False (0) is returned if there are no items and/or biblioitems with a matching itemtype code. > > =cut > >-sub get_items_and_biblioitems { >- my $itemtype_code = $_[1]; >+sub is_used { >+ my ($self, $itemtype_code) = @_; > 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 $itemtotal = Koha::Items->search({ 'itype' => $itemtype_code})->count; >+ my $bibliototal = Koha::Biblioitems->search({ 'itemtype' => $itemtype_code})->count; > my $overalltotal = $itemtotal + $bibliototal; > return $overalltotal; > } >diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl >index f72c314..d9f6887 100755 >--- a/admin/itemtypes.pl >+++ b/admin/itemtypes.pl >@@ -139,8 +139,8 @@ if ( $op eq 'add_form' ) { > $op = 'list'; > > } elsif ( $op eq 'delete_confirm' ) { >- >- my $overalltotal = Koha::ItemType->get_items_and_biblioitems($itemtype_code); >+ my $ItemType = Koha::ItemType->new(); >+ my $overalltotal = $ItemType->is_used($itemtype_code); > if ($overalltotal) { > push @messages, { type => 'error', code => 'cannot_be_deleted', total => $overalltotal }; > $op = 'list'; >diff --git a/t/db_dependent/Koha/ItemTypes.t b/t/db_dependent/Koha/ItemTypes.t >index 9ce1ad6..8417369 100755 >--- a/t/db_dependent/Koha/ItemTypes.t >+++ b/t/db_dependent/Koha/ItemTypes.t >@@ -22,6 +22,8 @@ use Modern::Perl; > use Test::More tests => 18; > use Data::Dumper; > use Koha::Database; >+use Koha::Items; >+use Koha::Biblioitems; > > BEGIN { > use_ok('Koha::ItemType'); >@@ -56,6 +58,33 @@ Koha::ItemType->new( > } > )->store; > >+Koha::Biblio->new( >+ { >+ biblionumber => 1, >+ } >+)->store; >+ >+Koha::Biblioitem->new( >+ { >+ biblioitemnumber => 1, >+ biblionumber => 1, >+ itemtype => 'type1' >+ } >+)->store; >+ >+ >+Koha::Item->new( >+ { >+ itemnumber => 1, >+ biblionumber => 1, >+ biblioitemnumber =>1, >+ itype => 'type2', >+ notforloan => 1, >+ itemlost => 0, >+ } >+)->store; >+ >+ > my $type = Koha::ItemTypes->find('type1'); > ok( defined($type), 'first result' ); > is( $type->itemtype, 'type1', 'itemtype/code' ); >@@ -76,4 +105,18 @@ is( $type->summary, 'summary', 'summary' ); > is( $type->checkinmsg, 'checkinmsg', 'checkinmsg' ); > is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' ); > >+ >+subtest is_used => sub{ >+ plan test => 2; >+ my $itemtype_code = shift; >+ my $schema = Koha::Database->new()->schema(); >+ my $itemtotal = Koha::Items->search({ 'itype' => $itemtype_code })->count; >+ my $bibliototal = Koha::Biblioitems->search({ 'itemtype' => $itemtype_code})->count; >+ my $overalltotal = $itemtotal + $bibliototal; >+ return $overalltotal; >+} >+for my $itemtype_code ('type1', 'type 2') { >+ subtest "is_used $itemtype_code", \&is_used, $range; >+} >+ > $schema->txn_rollback; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17944
:
59391
|
59564
|
59565
|
59655
|
59656
|
59657
|
59715
|
59716
|
59717
|
59718
|
59953
|
59954
|
62499
|
62500
|
62501
|
62502
|
62503
|
62504
|
62505
|
63045
|
63152
|
63220
|
63259
|
63307
|
63308
|
63309
|
63310
|
63924
|
63925