From ff57d3832ec1f6aead97b20835fb36d7209cba1b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 16 Jul 2014 13:44:39 +0200 Subject: [PATCH] [PASSED QA] Bug 12583: DelItem prototype - prefer hashref To delete an item, only the itemnumber should be mandatory. The DelItem routine can retrieve the biblionumber from the itemnumber. Test plan: Verify that t/db_dependent/Items/DelItem.t passes Signed-off-by: Chris Cormack Signed-off-by: Kyle M Hall --- C4/Acquisition.pm | 7 ++++++- C4/Items.pm | 18 +++++++++++++++--- t/db_dependent/Items.t | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 1a48926..0d1745c 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1861,7 +1861,12 @@ sub DelOrder { $sth->execute( $bibnum, $ordernumber ); my @itemnumbers = GetItemnumbersFromOrder( $ordernumber ); foreach my $itemnumber (@itemnumbers){ - C4::Items::DelItem( $bibnum, $itemnumber ); + C4::Items::DelItem( + { + biblionumber => $bibnum, + itemnumber => $itemnumber + } + ); } return; } diff --git a/C4/Items.pm b/C4/Items.pm index f644c75..4aaa078 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -632,14 +632,21 @@ sub ModDateLastSeen { =head2 DelItem - DelItem( $biblionumber, $itemnumber ); + DelItem({ itemnumber => $itemnumber, [ biblionumber => $biblionumber ] } ); Exported function (core API) for deleting an item record in Koha. =cut sub DelItem { - my ( $biblionumber, $itemnumber ) = @_; + my ( $params ) = @_; + + my $itemnumber = $params->{itemnumber}; + my $biblionumber = $params->{biblionumber}; + + unless ($biblionumber) { + $biblionumber = C4::Biblio::GetBiblionumberFromItemnumber($itemnumber); + } # FIXME check the item has no current issues _koha_delete_item( $itemnumber ); @@ -2287,7 +2294,12 @@ sub DelItemCheck { } elsif ($countanalytics > 0){ $error = "linked_analytics"; } else { - DelItem($biblionumber, $itemnumber); + DelItem( + { + biblionumber => $biblionumber, + itemnumber => $itemnumber + } + ); return 1; } } diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 7afdbec..157db89 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -58,7 +58,7 @@ subtest 'General Add, Get and Del tests' => sub { cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.'); # Delete item. - DelItem($bibnum, $itemnumber); + DelItem({ biblionumber => $bibnum, itemnumber => $itemnumber }); my $getdeleted = GetItem($itemnumber); is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); -- 1.7.2.5