From f527966ffc1203068194815c0943846a24ac8ca2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 6 Aug 2018 19:50:41 -0300 Subject: [PATCH] Bug 21206: Replace C4::Items::GetItem Note: This is here for information purpose, feel free to test it if you wan to play with it. TODO: C4::Reserves::_get_itype is not longer in use No more GetItem must be returned by: git grep GetItem|grep -v GetItemsAvailableToFillHoldRequestsForBib|grep -v GetItemsForInventory|grep -v GetItemsInfo|grep -v GetItemsLocationInfo|grep -v GetItemsInCollection|grep -v GetItemCourseReservesInfo|grep -v GetItemnumbersFromOrder|grep -v GetItemSearchField|grep -v GetItemTypesCategorized|grep -v GetItemNumbersFromImportBatch|cut -d':' -f1|sort|uniq Signed-off-by: Josef Moravec --- C4/Biblio.pm | 15 +- C4/Circulation.pm | 293 +++++++++++---------- C4/CourseReserves.pm | 6 +- C4/HoldsQueue.pm | 7 +- C4/ILSDI/Services.pm | 43 +-- C4/Items.pm | 41 +-- C4/Message.pm | 2 +- C4/Reserves.pm | 39 ++- acqui/orderreceive.pl | 9 +- catalogue/getitem-ajax.pl | 40 +-- catalogue/updateitem.pl | 2 +- cataloguing/additem.pl | 23 +- installer/data/mysql/backfill_statistics.pl | 9 +- labels/label-edit-batch.pl | 3 +- misc/recreateIssueStatistics.pl | 22 +- opac/opac-renew.pl | 7 +- opac/opac-shelves.pl | 6 +- opac/sco/sco-main.pl | 9 +- reserve/placerequest.pl | 8 +- svc/checkin | 14 +- t/db_dependent/Acquisition/CancelReceipt.t | 9 +- t/db_dependent/Circulation.t | 6 +- t/db_dependent/Circulation/IsItemIssued.t | 9 +- t/db_dependent/Circulation/Returns.t | 11 +- t/db_dependent/Circulation/issue.t | 13 +- .../Holds/DisallowHoldIfItemsAvailable.t | 15 +- t/db_dependent/Items.t | 68 ++--- .../Items/AutomaticItemModificationByAge.t | 51 ++-- t/db_dependent/Items/DelItem.t | 10 +- t/db_dependent/Items/MoveItemFromBiblio.t | 13 +- t/db_dependent/Items_DelItemCheck.t | 5 +- t/db_dependent/Reserves.t | 3 +- tools/batchMod.pl | 8 +- tools/inventory.pl | 6 +- tools/viewlog.pl | 10 +- virtualshelves/shelves.pl | 7 +- 36 files changed, 437 insertions(+), 405 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 808ed8d067..dc0a409e99 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2194,10 +2194,9 @@ sub PrepHostMarcField { my ($hostbiblionumber,$hostitemnumber, $marcflavour) = @_; $marcflavour ||="MARC21"; - require C4::Items; my $hostrecord = GetMarcBiblio({ biblionumber => $hostbiblionumber }); - my $item = C4::Items::GetItem($hostitemnumber); - + my $item = Koha::Items->find($hostitemnumber); + my $hostmarcfield; if ( $marcflavour eq "MARC21" || $marcflavour eq "NORMARC" ) { @@ -2220,7 +2219,7 @@ sub PrepHostMarcField { #other fields my $ed = $hostrecord->subfield('250','a'); - my $barcode = $item->{'barcode'}; + my $barcode = $item->barcode; my $title = $hostrecord->subfield('245','a'); # record control number, 001 with 003 and prefix @@ -2823,8 +2822,12 @@ sub EmbedItemsInMarcBiblio { require C4::Items; while ( my ($itemnumber) = $sth->fetchrow_array ) { next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers; - my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef; - push @items, { itemnumber => $itemnumber, item => $i }; + my $item; + if ( $opachiddenitems ) { + $item = Koha::Items->find($itemnumber); + $item = $item ? $item->unblessed : undef; + } + push @items, { itemnumber => $itemnumber, item => $item }; } my @items2pass = map { $_->{item} } @items; my @hiddenitems = diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 0999a970fd..6013890ed1 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -669,17 +669,18 @@ sub CanBookBeIssued { my $onsite_checkout = $params->{onsite_checkout} || 0; my $override_high_holds = $params->{override_high_holds} || 0; - my $item = GetItem(undef, $barcode ); + my $item = Koha::Items->find({barcode => $barcode }); # MANDATORY CHECKS - unless item exists, nothing else matters unless ( $item ) { $issuingimpossible{UNKNOWN_BARCODE} = 1; } return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible; - my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } ); - my $biblio = Koha::Biblios->find( $item->{biblionumber} ); + my $item_unblessed = $item->unblessed; # Transition... + my $issue = $item->checkout; + my $biblio = $item->biblio; my $biblioitem = $biblio->biblioitem; - my $effective_itemtype = $item->{itype}; # GetItem deals with that + my $effective_itemtype = $item->effective_itemtype; my $dbh = C4::Context->dbh; my $patron_unblessed = $patron->unblessed; @@ -693,7 +694,7 @@ sub CanBookBeIssued { unless ( $duedate ) { my $issuedate = $now->clone(); - my $branch = _GetCircControlBranch($item, $patron_unblessed); + my $branch = _GetCircControlBranch($item_unblessed, $patron_unblessed); $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed ); # Offline circ calls AddIssue directly, doesn't run through here @@ -712,17 +713,17 @@ sub CanBookBeIssued { # # BORROWER STATUS # - if ( $patron->category->category_type eq 'X' && ( $item->{barcode} )) { + if ( $patron->category->category_type eq 'X' && ( $item->barcode )) { # stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1 . &UpdateStats({ branch => C4::Context->userenv->{'branch'}, type => 'localuse', - itemnumber => $item->{'itemnumber'}, + itemnumber => $item->itemnumber, itemtype => $effective_itemtype, borrowernumber => $patron->borrowernumber, - ccode => $item->{'ccode'}} + ccode => $item->ccode} ); - ModDateLastSeen( $item->{'itemnumber'} ); + ModDateLastSeen( $item->itemnumber ); # FIXME Move to Koha::Item return( { STATS => 1 }, {}); } @@ -833,7 +834,7 @@ sub CanBookBeIssued { } else { my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed( $patron->borrowernumber, - $item->{'itemnumber'}, + $item->itemnumber, ); if ( $CanBookBeRenewed == 0 ) { # no more renewals allowed if ( $renewerror eq 'onsite_checkout' ) { @@ -854,7 +855,7 @@ sub CanBookBeIssued { my $patron = Koha::Patrons->find( $issue->borrowernumber ); - my ( $can_be_returned, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} ); + my ( $can_be_returned, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} ); unless ( $can_be_returned ) { $issuingimpossible{RETURN_IMPOSSIBLE} = 1; @@ -875,7 +876,7 @@ sub CanBookBeIssued { and $issue and $issue->onsite_checkout and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 ); - my $toomany = TooMany( $patron_unblessed, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } ); + my $toomany = TooMany( $patron_unblessed, $item->biblionumber, $item_unblessed, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } ); # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) { if ( $toomany->{max_allowed} == 0 ) { @@ -898,19 +899,19 @@ sub CanBookBeIssued { $patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed my $wants_check = $patron->wants_check_for_previous_checkout; $needsconfirmation{PREVISSUE} = 1 - if ($wants_check and $patron->do_check_for_previous_checkout($item)); + if ($wants_check and $patron->do_check_for_previous_checkout($item_unblessed)); # # ITEM CHECKING # - if ( $item->{'notforloan'} ) + if ( $item->notforloan ) { if(!C4::Context->preference("AllowNotForLoanOverride")){ $issuingimpossible{NOT_FOR_LOAN} = 1; - $issuingimpossible{item_notforloan} = $item->{'notforloan'}; + $issuingimpossible{item_notforloan} = $item->notforloan; }else{ $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1; - $needsconfirmation{item_notforloan} = $item->{'notforloan'}; + $needsconfirmation{item_notforloan} = $item->notforloan; } } else { @@ -943,17 +944,17 @@ sub CanBookBeIssued { } } } - if ( $item->{'withdrawn'} && $item->{'withdrawn'} > 0 ) + if ( $item->withdrawn && $item->withdrawn > 0 ) { $issuingimpossible{WTHDRAWN} = 1; } - if ( $item->{'restricted'} - && $item->{'restricted'} == 1 ) + if ( $item->restricted + && $item->restricted == 1 ) { $issuingimpossible{RESTRICTED} = 1; } - if ( $item->{'itemlost'} && C4::Context->preference("IssueLostItem") ne 'nothing' ) { - my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->{itemlost} }); + if ( $item->itemlost && C4::Context->preference("IssueLostItem") ne 'nothing' ) { + my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->itemlost }); my $code = $av->count ? $av->next->lib : ''; $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' ); $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' ); @@ -961,9 +962,10 @@ sub CanBookBeIssued { if ( C4::Context->preference("IndependentBranches") ) { my $userenv = C4::Context->userenv; unless ( C4::Context->IsSuperLibrarian() ) { - if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ){ + my $HomeOrHoldingBranch = C4::Context->preference("HomeOrHoldingBranch"); + if ( $item->$HomeOrHoldingBranch ne $userenv->{branch} ){ $issuingimpossible{ITEMNOTSAMEBRANCH} = 1; - $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")}; + $issuingimpossible{'itemhomebranch'} = $item->$HomeOrHoldingBranch; } $needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode if ( $patron->branchcode ne $userenv->{branch} ); @@ -975,7 +977,7 @@ sub CanBookBeIssued { my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation"); if ( $rentalConfirmation ){ - my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $patron->borrowernumber ); + my ($rentalCharge) = GetIssuingCharges( $item->itemnumber, $patron->borrowernumber ); if ( $rentalCharge > 0 ){ $needsconfirmation{RENTALCHARGE} = $rentalCharge; } @@ -983,7 +985,7 @@ sub CanBookBeIssued { unless ( $ignore_reserves ) { # See if the item is on reserve. - my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->{'itemnumber'} ); + my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->itemnumber ); if ($restype) { my $resbor = $res->{'borrowernumber'}; if ( $resbor ne $patron->borrowernumber ) { @@ -1028,7 +1030,7 @@ sub CanBookBeIssued { ## check for high holds decreasing loan period if ( C4::Context->preference('decreaseLoanHighHolds') ) { - my $check = checkHighHolds( $item, $patron_unblessed ); + my $check = checkHighHolds( $item_unblessed, $patron_unblessed ); if ( $check->{exceeded} ) { if ($override_high_holds) { @@ -1057,7 +1059,7 @@ sub CanBookBeIssued { ) { # Check if borrower has already issued an item from the same biblio # Only if it's not a subscription - my $biblionumber = $item->{biblionumber}; + my $biblionumber = $item->biblionumber; require C4::Serials; my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber); unless ($is_a_subscription) { @@ -1090,7 +1092,7 @@ Check whether the item can be returned to the provided branch =over 4 -=item C<$item> is a hash of item information as returned from GetItem +=item C<$item> is a hash of item information as returned Koha::Items->find->unblessed (Temporary, should be a Koha::Item instead) =item C<$branch> is the branchcode where the return is taking place @@ -1288,21 +1290,21 @@ sub AddIssue { # Stop here if the patron or barcode doesn't exist if ( $borrower && $barcode && $barcodecheck ) { # find which item we issue - my $item = GetItem( '', $barcode ) + my $item = Koha::Items->find({ barcode => $barcode }) or return; # if we don't get an Item, abort. - my $item_object = Koha::Items->find( { barcode => $barcode } ); + my $item_unblessed = $item->unblessed; - my $branch = _GetCircControlBranch( $item, $borrower ); + my $branch = _GetCircControlBranch( $item_unblessed, $borrower ); # get actual issuing if there is one - my $actualissue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } ); + my $actualissue = $item->checkout; # check if we just renew the issue. if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'} and not $switch_onsite_checkout ) { $datedue = AddRenewal( $borrower->{'borrowernumber'}, - $item->{'itemnumber'}, + $item->itemnumber, $branch, $datedue, $issuedate, # here interpreted as the renewal date @@ -1313,15 +1315,15 @@ sub AddIssue { if ( $actualissue and not $switch_onsite_checkout ) { # This book is currently on loan, but not to the person # who wants to borrow it now. mark it returned before issuing to the new borrower - my ( $allowed, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} ); + my ( $allowed, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} ); return unless $allowed; - AddReturn( $item->{'barcode'}, C4::Context->userenv->{'branch'} ); + AddReturn( $item->barcode, C4::Context->userenv->{'branch'} ); } - C4::Reserves::MoveReserve( $item->{'itemnumber'}, $borrower->{'borrowernumber'}, $cancelreserve ); + C4::Reserves::MoveReserve( $item->itemnumber, $borrower->{'borrowernumber'}, $cancelreserve ); # Starting process for transfer job (checking transfert and validate it if we have one) - my ($datesent) = GetTransfers( $item->{'itemnumber'} ); + my ($datesent) = GetTransfers( $item->itemnumber ); if ($datesent) { # updating line of branchtranfert to finish it, and changing the to branch value, implement a comment for visibility of this case (maybe for stats ....) my $sth = $dbh->prepare( @@ -1332,14 +1334,14 @@ sub AddIssue { WHERE itemnumber= ? AND datearrived IS NULL" ); $sth->execute( C4::Context->userenv->{'branch'}, - $item->{'itemnumber'} ); + $item->itemnumber ); } # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule. unless ($auto_renew) { my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( { categorycode => $borrower->{categorycode}, - itemtype => $item->{itype}, + itemtype => $item->effective_itemtype, branchcode => $branch } ); @@ -1349,7 +1351,7 @@ sub AddIssue { # Record in the database the fact that the book was issued. unless ($datedue) { - my $itype = $item_object->effective_itemtype; + my $itype = $item->effective_itemtype; $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower ); } @@ -1358,7 +1360,7 @@ sub AddIssue { $issue = Koha::Database->new()->schema()->resultset('Issue')->update_or_create( { borrowernumber => $borrower->{'borrowernumber'}, - itemnumber => $item->{'itemnumber'}, + itemnumber => $item->itemnumber, issuedate => $issuedate->strftime('%Y-%m-%d %H:%M:%S'), date_due => $datedue->strftime('%Y-%m-%d %H:%M:%S'), branchcode => C4::Context->userenv->{'branch'}, @@ -1369,49 +1371,48 @@ sub AddIssue { if ( C4::Context->preference('ReturnToShelvingCart') ) { # ReturnToShelvingCart is on, anything issued should be taken off the cart. - CartToShelf( $item->{'itemnumber'} ); + CartToShelf( $item->itemnumber ); } - $item->{'issues'}++; + if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) { - UpdateTotalIssues( $item->{'biblionumber'}, 1 ); + UpdateTotalIssues( $item->biblionumber, 1 ); } ## If item was lost, it has now been found, reverse any list item charges if necessary. - if ( $item->{'itemlost'} ) { + if ( $item->itemlost ) { if ( Koha::RefundLostItemFeeRules->should_refund( { current_branch => C4::Context->userenv->{branch}, - item_home_branch => $item->{homebranch}, - item_holding_branch => $item->{holdingbranch} + item_home_branch => $item->homebranch, + item_holding_branch => $item->holdingbranch, } ) ) { - _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef, - $item->{'barcode'} ); + _FixAccountForLostAndReturned( $item->itemnumber, undef, + $item->barcode ); } } ModItem( { - issues => $item->{'issues'}, + issues => $item->issues + 1, holdingbranch => C4::Context->userenv->{'branch'}, itemlost => 0, onloan => $datedue->ymd(), datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(), }, - $item->{'biblionumber'}, - $item->{'itemnumber'}, + $item->biblionumber, + $item->itemnumber, { log_action => 0 } ); - ModDateLastSeen( $item->{'itemnumber'} ); + ModDateLastSeen( $item->itemnumber ); # If it costs to borrow this book, charge it to the patron's account. - my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} ); + my ( $charge, $itemtype ) = GetIssuingCharges( $item->itemnumber, $borrower->{'borrowernumber'} ); if ( $charge > 0 ) { AddIssuingCharge( $issue, $charge ); - $item->{'charge'} = $charge; } # Record the fact that this book was issued. @@ -1421,11 +1422,11 @@ sub AddIssue { type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ), amount => $charge, other => ( $sipmode ? "SIP-$sipmode" : '' ), - itemnumber => $item->{'itemnumber'}, - itemtype => $item->{'itype'}, - location => $item->{location}, + itemnumber => $item->itemnumber, + itemtype => $item->effective_itemtype, + location => $item->location, borrowernumber => $borrower->{'borrowernumber'}, - ccode => $item->{'ccode'} + ccode => $item->ccode, } ); @@ -1434,7 +1435,7 @@ sub AddIssue { my %conditions = ( branchcode => $branch, categorycode => $borrower->{categorycode}, - item_type => $item->{itype}, + item_type => $item->effective_itemtype, notification => 'CHECKOUT', ); if ( $circulation_alert->is_enabled_for( \%conditions ) ) { @@ -1450,7 +1451,7 @@ sub AddIssue { logaction( "CIRCULATION", "ISSUE", $borrower->{'borrowernumber'}, - $item->{'itemnumber'} + $item->itemnumber, ) if C4::Context->preference("IssueLog"); } } @@ -1803,13 +1804,13 @@ sub AddReturn { my $stat_type = 'return'; # get information on item - my $item = GetItem( undef, $barcode ); + my $item = Koha::Items->find({ barcode => $barcode }); unless ($item) { return ( 0, { BadBarcode => $barcode } ); # no barcode means no item or borrower. bail out. } - my $itemnumber = $item->{ itemnumber }; - my $itemtype = $item->{itype}; # GetItem called effective_itemtype + my $itemnumber = $item->itemnumber; + my $itemtype = $item->effective_itemtype; my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ); if ( $issue ) { @@ -1829,21 +1830,22 @@ sub AddReturn { } } - if ( $item->{'location'} eq 'PROC' ) { + my $item_unblessed = $item->unblessed; + if ( $item->location eq 'PROC' ) { if ( C4::Context->preference("InProcessingToShelvingCart") ) { - $item->{'location'} = 'CART'; + $item_unblessed->{location} = 'CART'; } else { - $item->{location} = $item->{permanent_location}; + $item_unblessed->{location} = $item->permanent_location; } - ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'}, { log_action => 0 } ); + ModItem( $item_unblessed, $item->biblionumber, $item->itemnumber, { log_action => 0 } ); } # full item data, but no borrowernumber or checkout info (no issue) - my $hbr = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch"; + my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch"; # get the proper branch to which to return the item - my $returnbranch = $item->{$hbr} || $branch ; + my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch; # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch) my $borrowernumber = $patron ? $patron->borrowernumber : undef; # we don't know if we had a borrower or not @@ -1859,8 +1861,8 @@ sub AddReturn { } else { foreach my $key ( keys %$rules ) { - if ( $item->{notforloan} eq $key ) { - $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} }; + if ( $item->notforloan eq $key ) { + $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} }; ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, { log_action => 0 } ); last; } @@ -1869,7 +1871,7 @@ sub AddReturn { } # check if the return is allowed at this branch - my ($returnallowed, $message) = CanBookBeReturned($item, $branch); + my ($returnallowed, $message) = CanBookBeReturned($item_unblessed, $branch); unless ($returnallowed){ $messages->{'Wrongbranch'} = { Wrongbranch => $branch, @@ -1879,12 +1881,12 @@ sub AddReturn { return ( $doreturn, $messages, $issue, $patron_unblessed); } - if ( $item->{'withdrawn'} ) { # book has been cancelled + if ( $item->withdrawn ) { # book has been cancelled $messages->{'withdrawn'} = 1; $doreturn = 0 if C4::Context->preference("BlockReturnOfWithdrawnItems"); } - if ( $item->{itemlost} and C4::Context->preference("BlockReturnOfLostItems") ) { + if ( $item->itemlost and C4::Context->preference("BlockReturnOfLostItems") ) { $doreturn = 0; } @@ -1901,7 +1903,7 @@ sub AddReturn { # don't allow dropbox mode to create an invalid entry in issues (issuedate > today) # FIXME: check issuedate > returndate, factoring in holidays - $circControlBranch = _GetCircControlBranch($item,$patron_unblessed); + $circControlBranch = _GetCircControlBranch($item_unblessed, $patron_unblessed); $is_overdue = $issue->is_overdue( $dropboxdate ); } else { $is_overdue = $issue->is_overdue; @@ -1909,12 +1911,12 @@ sub AddReturn { if ($patron) { eval { - MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, + MarkIssueReturned( $borrowernumber, $item->itemnumber, $circControlBranch, $return_date, $patron->privacy ); }; unless ( $@ ) { if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) { - _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed, return_date => $return_date } ); + _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed, return_date => $return_date } ); } } else { carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue->unblessed ); @@ -1927,58 +1929,58 @@ sub AddReturn { } - ModItem( { onloan => undef }, $item->{biblionumber}, $item->{itemnumber}, { log_action => 0 } ); + ModItem( { onloan => undef }, $item->biblionumber, $item->itemnumber, { log_action => 0 } ); } # the holdingbranch is updated if the document is returned to another location. # this is always done regardless of whether the item was on loan or not - my $item_holding_branch = $item->{ holdingbranch }; - if ($item->{'holdingbranch'} ne $branch) { - UpdateHoldingbranch($branch, $item->{'itemnumber'}); - $item->{'holdingbranch'} = $branch; # update item data holdingbranch too + my $item_holding_branch = $item->holdingbranch; + if ($item->holdingbranch ne $branch) { + UpdateHoldingbranch($branch, $item->itemnumber); + $item_unblessed->{'holdingbranch'} = $branch; # update item data holdingbranch too # FIXME I guess this is for the _debar_user_on_return call later } my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0; - ModDateLastSeen( $item->{itemnumber}, $leave_item_lost ); + ModDateLastSeen( $item->itemnumber, $leave_item_lost ); # check if we have a transfer for this document - my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->{'itemnumber'} ); + my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->itemnumber ); # if we have a transfer to do, we update the line of transfers with the datearrived - my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->{'itemnumber'} ); + my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->itemnumber ); if ($datesent) { if ( $tobranch eq $branch ) { my $sth = C4::Context->dbh->prepare( "UPDATE branchtransfers SET datearrived = now() WHERE itemnumber= ? AND datearrived IS NULL" ); - $sth->execute( $item->{'itemnumber'} ); + $sth->execute( $item->itemnumber ); # if we have a reservation with valid transfer, we can set it's status to 'W' - ShelfToCart( $item->{'itemnumber'} ) if ( C4::Context->preference("ReturnToShelvingCart") ); - C4::Reserves::ModReserveStatus($item->{'itemnumber'}, 'W'); + ShelfToCart( $item->itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") ); + C4::Reserves::ModReserveStatus($item->itemnumber, 'W'); } else { $messages->{'WrongTransfer'} = $tobranch; - $messages->{'WrongTransferItem'} = $item->{'itemnumber'}; + $messages->{'WrongTransferItem'} = $item->itemnumber; } $validTransfert = 1; } else { - ShelfToCart( $item->{'itemnumber'} ) if ( C4::Context->preference("ReturnToShelvingCart") ); + ShelfToCart( $item->itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") ); } # fix up the accounts..... - if ( $item->{'itemlost'} ) { + if ( $item->itemlost ) { $messages->{'WasLost'} = 1; unless ( C4::Context->preference("BlockReturnOfLostItems") ) { if ( Koha::RefundLostItemFeeRules->should_refund( { current_branch => C4::Context->userenv->{branch}, - item_home_branch => $item->{homebranch}, + item_home_branch => $item->homebranch, item_holding_branch => $item_holding_branch } ) ) { - _FixAccountForLostAndReturned( $item->{'itemnumber'}, + _FixAccountForLostAndReturned( $item->itemnumber, $borrowernumber, $barcode ); $messages->{'LostItemFeeRefunded'} = 1; } @@ -1987,14 +1989,14 @@ sub AddReturn { # fix up the overdues in accounts... if ($borrowernumber) { - my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox); - defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!"; # zero is OK, check defined + my $fix = _FixOverduesOnReturn($borrowernumber, $item->itemnumber, $exemptfine, $dropbox); + defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->itemnumber...) failed!"; # zero is OK, check defined if ( $issue and $issue->is_overdue ) { # fix fine days $today = dt_from_string($return_date) if $return_date; $today = $dropboxdate if $dropbox; - my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item, dt_from_string($issue->date_due), $today ); + my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item_unblessed, dt_from_string($issue->date_due), $today ); if ($reminder){ $messages->{'PrevDebarred'} = $debardate; } else { @@ -2019,7 +2021,7 @@ sub AddReturn { # if we don't have a reserve with the status W, we launch the Checkreserves routine my ($resfound, $resrec); my $lookahead= C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds - ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->{'itemnumber'}, undef, $lookahead ) unless ( $item->{'withdrawn'} ); + ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->itemnumber, undef, $lookahead ) unless ( $item->withdrawn ); if ($resfound) { $resrec->{'ResFound'} = $resfound; $messages->{'ResFound'} = $resrec; @@ -2032,7 +2034,7 @@ sub AddReturn { itemnumber => $itemnumber, itemtype => $itemtype, borrowernumber => $borrowernumber, - ccode => $item->{ ccode } + ccode => $item->ccode, }); # Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then. @@ -2041,19 +2043,19 @@ sub AddReturn { my %conditions = ( branchcode => $branch, categorycode => $patron->categorycode, - item_type => $item->{itype}, + item_type => $itemtype, notification => 'CHECKIN', ); if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) { SendCirculationAlert({ type => 'CHECKIN', - item => $item, + item => $item_unblessed, borrower => $patron->unblessed, branch => $branch, }); } - logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'}) + logaction("CIRCULATION", "RETURN", $borrowernumber, $item->itemnumber) if C4::Context->preference("ReturnLog"); } @@ -2069,13 +2071,14 @@ sub AddReturn { # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer if (!$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){ + my $BranchTransferLimitsType = C4::Context->preference("BranchTransferLimitsType"); if (C4::Context->preference("AutomaticItemReturn" ) or (C4::Context->preference("UseBranchTransferLimits") and - ! IsBranchTransferAllowed($branch, $returnbranch, $item->{C4::Context->preference("BranchTransferLimitsType")} ) + ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType ) )) { - $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->{'itemnumber'},$branch, $returnbranch; - $debug and warn "item: " . Dumper($item); - ModItemTransfer($item->{'itemnumber'}, $branch, $returnbranch); + $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->itemnumber,$branch, $returnbranch; + $debug and warn "item: " . Dumper($item_unblessed); + ModItemTransfer($item->itemnumber, $branch, $returnbranch); $messages->{'WasTransfered'} = 1; } else { $messages->{'NeedsTransfer'} = $returnbranch; @@ -2612,7 +2615,7 @@ sub CanBookBeRenewed { my $dbh = C4::Context->dbh; my $renews = 1; - my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); + my $item = Koha::Items->find($itemnumber) or return ( 0, 'no_item' ); my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' ); return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout; return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item }); @@ -2670,7 +2673,7 @@ sub CanBookBeRenewed { my @reservable; my %borrowers; ITEM: foreach my $i (@itemnumbers) { - my $item = GetItem($i); + my $item = Koha::Items->find($i)->unblessed; next if IsItemOnHoldAndFound($i); for my $b (@borrowernumbers) { my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed; @@ -2691,10 +2694,10 @@ sub CanBookBeRenewed { return ( 1, undef ) if $override_limit; - my $branchcode = _GetCircControlBranch( $item, $patron->unblessed ); + my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( { categorycode => $patron->categorycode, - itemtype => $item->{itype}, + itemtype => $item->effective_itemtype, branchcode => $branchcode } ); @@ -2818,15 +2821,13 @@ sub AddRenewal { my $datedue = shift; my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd(); - my $item = GetItem($itemnumber) or return; - my $item_object = Koha::Items->find( $itemnumber ); # Should replace $item - my $biblio = $item_object->biblio; + my $item = Koha::Items->find($itemnumber) or return; + my $biblio = $item->biblio; + my $issue = $item->checkout; + my $item_unblessed = $item->unblessed; my $dbh = C4::Context->dbh; - # Find the issues record for this book - my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ); - return unless $issue; $borrowernumber ||= $issue->borrowernumber; @@ -2840,7 +2841,7 @@ sub AddRenewal { my $patron_unblessed = $patron->unblessed; if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) { - _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } ); + _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } ); } _FixOverduesOnReturn( $borrowernumber, $itemnumber ); @@ -2849,11 +2850,11 @@ sub AddRenewal { # based on the value of the RenewalPeriodBase syspref. unless ($datedue) { - my $itemtype = $item_object->effective_itemtype; + my $itemtype = $item->effective_itemtype; $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? dt_from_string( $issue->date_due, 'sql' ) : DateTime->now( time_zone => C4::Context->tz()); - $datedue = CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal'); + $datedue = CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item_unblessed, $patron_unblessed), $patron_unblessed, 'is a renewal'); } # Update the issues record to have the new due date, and a new count @@ -2867,8 +2868,8 @@ sub AddRenewal { $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); # Update the renewal count on the item, and tell zebra to reindex - $renews = $item->{renewals} + 1; - ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, { log_action => 0 } ); + $renews = $item->renewals + 1; + ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->biblionumber, $itemnumber, { log_action => 0 } ); # Charge a new rental fee, if applicable? my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); @@ -2883,7 +2884,7 @@ sub AddRenewal { VALUES (now(),?,?,?,?,?,?,?,?)" ); $sth->execute( $borrowernumber, $accountno, $charge, $manager_id, - "Renewal of Rental Item " . $biblio->title . " $item->{'barcode'}", + "Renewal of Rental Item " . $biblio->title . " " . $item->barcode, 'Rent', $charge, $itemnumber ); } @@ -2893,14 +2894,14 @@ sub AddRenewal { my %conditions = ( branchcode => $branch, categorycode => $patron->categorycode, - item_type => $item->{itype}, + item_type => $item->effective_itemtype, notification => 'CHECKOUT', ); if ( $circulation_alert->is_enabled_for( \%conditions ) ) { SendCirculationAlert( { type => 'RENEWAL', - item => $item, + item => $item_unblessed, borrower => $patron->unblessed, branch => $branch, } @@ -2928,10 +2929,10 @@ sub AddRenewal { type => 'renew', amount => $charge, itemnumber => $itemnumber, - itemtype => $item->{itype}, - location => $item->{location}, + itemtype => $item->effective_itemtype, + location => $item->location, borrowernumber => $borrowernumber, - ccode => $item->{'ccode'} + ccode => $item->ccode, } ); @@ -2949,7 +2950,7 @@ sub GetRenewCount { my $renewsleft = 0; my $patron = Koha::Patrons->find( $bornum ); - my $item = GetItem($itemno); + my $item = Koha::Items->find($itemno); return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed @@ -2966,11 +2967,11 @@ sub GetRenewCount { my $data = $sth->fetchrow_hashref; $renewcount = $data->{'renewals'} if $data->{'renewals'}; # $item and $borrower should be calculated - my $branchcode = _GetCircControlBranch($item, $patron->unblessed); + my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( { categorycode => $patron->categorycode, - itemtype => $item->{itype}, + itemtype => $item->effective_itemtype, branchcode => $branchcode } ); @@ -3005,17 +3006,17 @@ sub GetSoonestRenewDate { my $dbh = C4::Context->dbh; - my $item = GetItem($itemnumber) or return; - my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return; + my $item = Koha::Items->find($itemnumber) or return; + my $itemissue = $item->checkout or return; $borrowernumber ||= $itemissue->borrowernumber; my $patron = Koha::Patrons->find( $borrowernumber ) or return; - my $branchcode = _GetCircControlBranch( $item, $patron->unblessed ); + my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( { categorycode => $patron->categorycode, - itemtype => $item->{itype}, + itemtype => $item->effective_itemtype, branchcode => $branchcode } ); @@ -3064,17 +3065,17 @@ sub GetLatestAutoRenewDate { my $dbh = C4::Context->dbh; - my $item = GetItem($itemnumber) or return; - my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return; + my $item = Koha::Items->find($itemnumber) or return; + my $itemissue = $item->checkout or return; $borrowernumber ||= $itemissue->borrowernumber; my $patron = Koha::Patrons->find( $borrowernumber ) or return; - my $branchcode = _GetCircControlBranch( $item, $patron->unblessed ); + my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( { categorycode => $patron->categorycode, - itemtype => $item->{itype}, + itemtype => $item->effective_itemtype, branchcode => $branchcode } ); @@ -3651,8 +3652,8 @@ sub ReturnLostItem{ MarkIssueReturned( $borrowernumber, $itemnum ); my $patron = Koha::Patrons->find( $borrowernumber ); - my $item = C4::Items::GetItem( $itemnum ); - my $old_note = ($item->{'paidfor'} && ($item->{'paidfor'} ne q{})) ? $item->{'paidfor'}.' / ' : q{}; + my $item = Koha::Items->find($itemnum); + my $old_note = ($item->paidfor && ($item->paidfor ne q{})) ? $item->paidfor.' / ' : q{}; my @datearr = localtime(time); my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3]; my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber; @@ -3839,8 +3840,12 @@ sub ProcessOfflinePayment { sub TransferSlip { my ($branch, $itemnumber, $barcode, $to_branch) = @_; - my $item = GetItem( $itemnumber, $barcode ) - or return; + my $item = + $itemnumber + ? Koha::Items->find($itemnumber) + : Koha::Items->find( { barcode => $barcode } ); + + $item or return; return C4::Letters::GetPreparedLetter ( module => 'circulation', @@ -3848,8 +3853,8 @@ sub TransferSlip { branchcode => $branch, tables => { 'branches' => $to_branch, - 'biblio' => $item->{biblionumber}, - 'items' => $item, + 'biblio' => $item->biblionumber, + 'items' => $item->unblessed, }, ); } diff --git a/C4/CourseReserves.pm b/C4/CourseReserves.pm index 997f725995..428d7e9d33 100644 --- a/C4/CourseReserves.pm +++ b/C4/CourseReserves.pm @@ -20,7 +20,7 @@ use Modern::Perl; use List::MoreUtils qw(any); use C4::Context; -use C4::Items qw(GetItem ModItem); +use C4::Items qw(ModItem); use C4::Circulation qw(GetOpenIssue); use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG @FIELDS); @@ -606,14 +606,14 @@ sub _SwapAllFields { warn "C4::CourseReserves::_SwapFields( $ci_id )" if $DEBUG; my $course_item = GetCourseItem( ci_id => $ci_id ); - my $item = GetItem( $course_item->{'itemnumber'} ); + my $item = Koha::Items->find($course_item->{'itemnumber'}); my %course_item_fields; my %item_fields; foreach (@FIELDS) { if ( defined( $course_item->{$_} ) ) { $course_item_fields{$_} = $course_item->{$_}; - $item_fields{$_} = $item->{$_} || q{}; + $item_fields{$_} = $item->$_ || q{}; } } diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index ce525ba64b..1015763dd8 100755 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -29,6 +29,7 @@ use C4::Circulation; use C4::Members; use C4::Biblio; use Koha::DateUtils; +use Koha::Items; use Koha::Patrons; use List::Util qw(shuffle); @@ -674,9 +675,9 @@ sub CreatePicklistFromItemMap { my $reservenotes = $mapped_item->{reservenotes}; my $item_level = $mapped_item->{item_level}; - my $item = GetItem($itemnumber); - my $barcode = $item->{barcode}; - my $itemcallnumber = $item->{itemcallnumber}; + my $item = Koha::Items->find($itemnumber); + my $barcode = $item->barcode; + my $itemcallnumber = $item->itemcallnumber; my $patron = Koha::Patrons->find( $borrowernumber ); my $cardnumber = $patron->cardnumber; diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index 689973ea3e..2ad2a72168 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -535,17 +535,17 @@ sub GetServices { my $borrower = $patron->unblessed; # Get the item, or return an error code if not found my $itemnumber = $cgi->param('item_id'); - my $item = GetItem( $itemnumber ); - return { code => 'RecordNotFound' } unless $$item{itemnumber}; + my $item = Koha::Items->find($itemnumber); + return { code => 'RecordNotFound' } unless $item; my @availablefor; # Reserve level management - my $biblionumber = $item->{'biblionumber'}; + my $biblionumber = $item->biblionumber; my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber ); if ($canbookbereserved->{status} eq 'OK') { push @availablefor, 'title level hold'; - my $canitembereserved = IsAvailableForItemLevelRequest($item, $borrower); + my $canitembereserved = IsAvailableForItemLevelRequest($item->unblessed, $borrower); if ($canitembereserved) { push @availablefor, 'item level hold'; } @@ -568,7 +568,7 @@ sub GetServices { } # Issuing management - my $barcode = $item->{'barcode'} || ''; + my $barcode = $item->barcode || ''; $barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') ); if ($barcode) { my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $barcode ); @@ -607,14 +607,17 @@ sub RenewLoan { # Get the item, or return an error code my $itemnumber = $cgi->param('item_id'); - my $item = GetItem( $itemnumber ); - return { code => 'RecordNotFound' } unless $$item{itemnumber}; + my $item = Koha::Items->find($itemnumber); + return { code => 'RecordNotFound' } unless $item; # Add renewal if possible my @renewal = CanBookBeRenewed( $borrowernumber, $itemnumber ); if ( $renewal[0] ) { AddRenewal( $borrowernumber, $itemnumber ); } - my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return; # FIXME should be handled + return unless $item; # FIXME should be handled + + my $issue = $item->checkout; + return $issue; # FIXME should be handled # Hashref building my $out; @@ -732,11 +735,11 @@ sub HoldItem { # Get the item or return an error code my $itemnumber = $cgi->param('item_id'); - my $item = GetItem( $itemnumber ); - return { code => 'RecordNotFound' } unless $$item{itemnumber}; + my $item = Koha::Items->find($itemnumber); + return { code => 'RecordNotFound' } unless $item; # If the biblio does not match the item, return an error code - return { code => 'RecordNotFound' } if $$item{biblionumber} ne $biblio->biblionumber; + return { code => 'RecordNotFound' } if $item->biblionumber ne $biblio->biblionumber; # Check for item disponibility my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber ); @@ -811,25 +814,25 @@ Returns, for an itemnumber, an array containing availability information. sub _availability { my ($itemnumber) = @_; - my $item = GetItem( $itemnumber, undef, undef ); + my $item = Koha::Items->find($itemnumber); - if ( not $item->{'itemnumber'} ) { + unless ( $item ) { return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef ); } - my $biblionumber = $item->{'biblioitemnumber'}; - my $library = Koha::Libraries->find( $item->{holdingbranch} ); + my $biblionumber = $item->biblioitemnumber; + my $library = Koha::Libraries->find( $item->holdingbranch ); my $location = $library ? $library->branchname : ''; - if ( $item->{'notforloan'} ) { + if ( $item->notforloan ) { return ( $biblionumber, 'not available', 'Not for loan', $location ); - } elsif ( $item->{'onloan'} ) { + } elsif ( $item->onloan ) { return ( $biblionumber, 'not available', 'Checked out', $location ); - } elsif ( $item->{'itemlost'} ) { + } elsif ( $item->itemlost ) { return ( $biblionumber, 'not available', 'Item lost', $location ); - } elsif ( $item->{'withdrawn'} ) { + } elsif ( $item->withdrawn ) { return ( $biblionumber, 'not available', 'Item withdrawn', $location ); - } elsif ( $item->{'damaged'} ) { + } elsif ( $item->damaged ) { return ( $biblionumber, 'not available', 'Item damaged', $location ); } else { return ( $biblionumber, 'available', undef, $location ); diff --git a/C4/Items.pm b/C4/Items.pm index 3b006c686e..ff74fc3ece 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -177,10 +177,9 @@ sub CartToShelf { croak "FAILED CartToShelf() - no itemnumber supplied"; } - my $item = GetItem($itemnumber); - if ( $item->{location} eq 'CART' ) { - $item->{location} = $item->{permanent_location}; - ModItem($item, undef, $itemnumber); + my $item = Koha::Items->find($itemnumber); + if ( $item->location eq 'CART' ) { + ModItem({ location => $item->permanent_location}, undef, $itemnumber); } } @@ -200,9 +199,7 @@ sub ShelfToCart { croak "FAILED ShelfToCart() - no itemnumber supplied"; } - my $item = GetItem($itemnumber); - $item->{'location'} = 'CART'; - ModItem($item, undef, $itemnumber); + ModItem({ location => 'CART'}, undef, $itemnumber); } =head2 AddItemFromMarc @@ -556,12 +553,12 @@ sub ModItem { my @fields = qw( itemlost withdrawn damaged ); - # Only call GetItem if we need to set an "on" date field + # Only retrieve the item if we need to set an "on" date field if ( $item->{itemlost} || $item->{withdrawn} || $item->{damaged} ) { - my $pre_mod_item = GetItem( $item->{'itemnumber'} ); + my $pre_mod_item = Koha::Items->find( $item->{'itemnumber'} ); for my $field (@fields) { if ( defined( $item->{$field} ) - and not $pre_mod_item->{$field} + and not $pre_mod_item->$field and $item->{$field} ) { $item->{ $field . '_on' } = @@ -1331,13 +1328,12 @@ sub GetMarcItem { # while the other treats the MARC representation as authoritative # under certain circumstances. - my $itemrecord = GetItem($itemnumber); + my $item = Koha::Items->find($itemnumber) or return; # Tack on 'items.' prefix to column names so that C4::Biblio::TransformKohaToMarc will work. # Also, don't emit a subfield if the underlying field is blank. - - return Item2Marc($itemrecord,$biblionumber); + return Item2Marc($item->unblessed, $biblionumber); } sub Item2Marc { @@ -1776,31 +1772,21 @@ sub ItemSafeToDelete { my $countanalytics = GetAnalyticsCount($itemnumber); - # check that there is no issue on this item before deletion. - my $sth = $dbh->prepare( - q{ - SELECT COUNT(*) FROM issues - WHERE itemnumber = ? - } - ); - $sth->execute($itemnumber); - my ($onloan) = $sth->fetchrow; - - my $item = GetItem($itemnumber); + my $item = Koha::Items->find($itemnumber) or return; - if ($onloan) { + if ($item->checkout) { $status = "book_on_loan"; } elsif ( defined C4::Context->userenv and !C4::Context->IsSuperLibrarian() and C4::Context->preference("IndependentBranches") - and ( C4::Context->userenv->{branch} ne $item->{'homebranch'} ) ) + and ( C4::Context->userenv->{branch} ne $item->homebranch ) ) { $status = "not_same_branch"; } else { # check it doesn't have a waiting reserve - $sth = $dbh->prepare( + my $sth = $dbh->prepare( q{ SELECT COUNT(*) FROM reserves WHERE (found = 'W' OR found = 'T') @@ -2685,7 +2671,6 @@ sub ToggleNewStatus { while ( my $values = $sth->fetchrow_hashref ) { my $biblionumber = $values->{biblionumber}; my $itemnumber = $values->{itemnumber}; - my $item = C4::Items::GetItem( $itemnumber ); for my $substitution ( @$substitutions ) { next unless $substitution->{field}; C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber ) diff --git a/C4/Message.pm b/C4/Message.pm index 3783ce85b9..e4dafdb215 100644 --- a/C4/Message.pm +++ b/C4/Message.pm @@ -37,7 +37,7 @@ How to add a new message to the queue: use C4::Message; use C4::Items; my $borrower = { borrowernumber => 1 }; - my $item = C4::Items::GetItem(1); + my $item = Koha::Items->find($itemnumber)->unblessed; my $letter = C4::Letters::GetPreparedLetter ( module => 'circulation', letter_code => 'CHECKOUT', diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 78e8f6a360..4c3e3b0c80 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -318,14 +318,14 @@ sub CanItemBeReserved { # we retrieve borrowers and items informations # # item->{itype} will come for biblioitems if necessery - my $item = C4::Items::GetItem($itemnumber); - my $biblio = Koha::Biblios->find( $item->{biblionumber} ); + my $item = Koha::Items->find($itemnumber); + my $biblio = $item->biblio; my $patron = Koha::Patrons->find( $borrowernumber ); my $borrower = $patron->unblessed; # If an item is damaged and we don't allow holds on damaged items, we can stop right here return { status =>'damaged' } - if ( $item->{damaged} + if ( $item->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems') ); # Check for the age restriction @@ -353,7 +353,7 @@ sub CanItemBeReserved { if ( $controlbranch eq "ItemHomeLibrary" ) { $branchfield = "items.homebranch"; - $branchcode = $item->{homebranch}; + $branchcode = $item->homebranch; } elsif ( $controlbranch eq "PatronLibrary" ) { $branchfield = "borrowers.branchcode"; @@ -361,7 +361,7 @@ sub CanItemBeReserved { } # we retrieve rights - if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->{'itype'}, $branchcode ) ) { + if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->effective_itemtype, $branchcode ) ) { $ruleitemtype = $rights->{itemtype}; $allowedreserves = $rights->{reservesallowed}; $holds_per_record = $rights->{holds_per_record}; @@ -371,7 +371,6 @@ sub CanItemBeReserved { $ruleitemtype = '*'; } - $item = Koha::Items->find( $itemnumber ); my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber, @@ -447,7 +446,7 @@ sub CanItemBeReserved { my $circ_control_branch = C4::Circulation::_GetCircControlBranch( $item->unblessed(), $borrower ); my $branchitemrule = - C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype ); + C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype ); # FIXME Should not be item->effective_itemtype? if ( $branchitemrule->{holdallowed} == 0 ) { return { status => 'notReservable' }; @@ -464,8 +463,7 @@ sub CanItemBeReserved { if ( C4::Context->preference('IndependentBranches') and !C4::Context->preference('canreservefromotherbranches') ) { - my $itembranch = $item->homebranch; - if ( $itembranch ne $borrower->{branchcode} ) { + if ( $item->homebranch ne $borrower->{branchcode} ) { return { status => 'cannotReserveFromOtherBranches' }; } } @@ -522,8 +520,8 @@ sub GetOtherReserves { my $nextreservinfo; my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber); if ($checkreserves) { - my $iteminfo = GetItem($itemnumber); - if ( $iteminfo->{'holdingbranch'} ne $checkreserves->{'branchcode'} ) { + my $item = Koha::Items->find($itemnumber); + if ( $item->holdingbranch ne $checkreserves->{'branchcode'} ) { $messages->{'transfert'} = $checkreserves->{'branchcode'}; #minus priorities of others reservs ModReserveMinusPriority( @@ -534,7 +532,7 @@ sub GetOtherReserves { #launch the subroutine dotransfer C4::Items::ModItemTransfer( $itemnumber, - $iteminfo->{'holdingbranch'}, + $item->holdingbranch, $checkreserves->{'branchcode'} ), ; @@ -759,15 +757,15 @@ sub CheckReserves { } } else { my $patron; - my $iteminfo; + my $item; my $local_hold_match; if ($LocalHoldsPriority) { $patron = Koha::Patrons->find( $res->{borrowernumber} ); - $iteminfo = C4::Items::GetItem($itemnumber); + $item = Koha::Items->find($itemnumber); my $local_holds_priority_item_branchcode = - $iteminfo->{$LocalHoldsPriorityItemControl}; + $item->$LocalHoldsPriorityItemControl; my $local_holds_priority_patron_branchcode = ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' ) ? $res->{branchcode} @@ -781,14 +779,15 @@ sub CheckReserves { # See if this item is more important than what we've got so far if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) { - $iteminfo ||= C4::Items::GetItem($itemnumber); - next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo ); + $item ||= Koha::Items->find($itemnumber); + next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype; $patron ||= Koha::Patrons->find( $res->{borrowernumber} ); - my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed ); - my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'}); + my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed ); + my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype); next if ($branchitemrule->{'holdallowed'} == 0); next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode)); - next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) ); + my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy}; + next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) ); $priority = $res->{'priority'}; $highest = $res; last if $local_hold_match; diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index e57e2a6966..a9d3201246 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -130,10 +130,10 @@ if ($AcqCreateItem eq 'receiving') { ); } elsif ($AcqCreateItem eq 'ordering') { my $fw = ($acq_fw) ? 'ACQ' : ''; - my @itemnumbers = $order_object->items->get_column('itemnumber'); + my $items = $order_object->items; my @items; - foreach (@itemnumbers) { - my $item = GetItem($_); # FIXME We do not need this call, we already have the Koha::Items + while ( my $i = $items->next ) { + my $item = $i->unblessed; my $descriptions; $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} }); $item->{notforloan} = $descriptions->{lib} // ''; @@ -150,8 +150,9 @@ if ($AcqCreateItem eq 'receiving') { $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} }); $item->{materials} = $descriptions->{lib} // ''; - my $itemtype = Koha::ItemTypes->find( $item->{itype} ); + my $itemtype = Koha::ItemTypes->find($i->effective_itemtype); if (defined $itemtype) { + # We should not do that here, but call ->itemtype->description when needed instead $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description? } push @items, $item; diff --git a/catalogue/getitem-ajax.pl b/catalogue/getitem-ajax.pl index 10df69ef75..87fc547aab 100755 --- a/catalogue/getitem-ajax.pl +++ b/catalogue/getitem-ajax.pl @@ -29,6 +29,7 @@ use C4::Output; use Koha::Libraries; use Koha::AuthorisedValues; +use Koha::Items; use Koha::ItemTypes; my $cgi = new CGI; @@ -43,39 +44,42 @@ unless ($status eq "ok") { my $item = {}; my $itemnumber = $cgi->param('itemnumber'); +my $item_unblessed = {}; if($itemnumber) { my $acq_fw = GetMarcStructure(1, 'ACQ'); my $fw = ($acq_fw) ? 'ACQ' : ''; - $item = GetItem($itemnumber); + $item = Koha::Items->find($itemnumber); + $item_unblessed = $item->unblessed; # FIXME Not needed, call home_branch and holding_branch in the templates instead - if($item->{homebranch}) { - $item->{homebranchname} = Koha::Libraries->find($item->{homebranch})->branchname; + if($item->homebranch) { # This test should not be needed, homebranch and holdingbranch are mandatory + $item_unblessed->{homebranchname} = $item->home_branch->branchname; } - if($item->{holdingbranch}) { - $item->{holdingbranchname} = Koha::Libraries->find($item->{holdingbranch})->branchname; + if($item->holdingbranch) { + $item_unblessed->{holdingbranchname} = $item->holding_branch->branchname; } my $descriptions; - $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} }); - $item->{notforloan} = $descriptions->{lib} // ''; + $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->notforloan }); + $item_unblessed->{notforloan} = $descriptions->{lib} // ''; - $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->{restricted} }); - $item->{restricted} = $descriptions->{lib} // ''; + $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->restricted }); + $item_unblessed->{restricted} = $descriptions->{lib} // ''; - $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->{location} }); - $item->{location} = $descriptions->{lib} // ''; + $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->location }); + $item_unblessed->{location} = $descriptions->{lib} // ''; - $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->{collection} }); - $item->{collection} = $descriptions->{lib} // ''; + $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->collection }); + $item_unblessed->{collection} = $descriptions->{lib} // ''; - $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} }); - $item->{materials} = $descriptions->{lib} // ''; + $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->materials }); + $item_unblessed->{materials} = $descriptions->{lib} // ''; - my $itemtype = Koha::ItemTypes->find( $item->{itype} ); - $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description? + my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); + # We should not do that here, but call ->itemtype->description when needed instea + $item_unblessed->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description? } -my $json_text = to_json( $item, { utf8 => 1 } ); +my $json_text = to_json( $item_unblessed, { utf8 => 1 } ); output_with_http_headers $cgi, undef, $json_text, 'json'; diff --git a/catalogue/updateitem.pl b/catalogue/updateitem.pl index f06dfedfb1..7924b2b85e 100755 --- a/catalogue/updateitem.pl +++ b/catalogue/updateitem.pl @@ -44,7 +44,7 @@ my $confirm=$cgi->param('confirm'); my $dbh = C4::Context->dbh; # get the rest of this item's information -my $item_data_hashref = GetItem($itemnumber, undef); +my $item_data_hashref = Koha::Items->find($itemnumber)->unblessed; # make sure item statuses are set to 0 if empty or NULL for ($damaged,$itemlost,$withdrawn) { diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 02d45ddef4..db5ffd3b61 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -74,15 +74,20 @@ sub get_item_from_barcode { sub set_item_default_location { my $itemnumber = shift; - my $item = GetItem( $itemnumber ); + my $item = Koha::Items->find($itemnumber); if ( C4::Context->preference('NewItemsDefaultLocation') ) { - $item->{'permanent_location'} = $item->{'location'}; - $item->{'location'} = C4::Context->preference('NewItemsDefaultLocation'); - ModItem( $item, undef, $itemnumber); + ModItem( + { + permanent_location => $item->location, + location => C4::Context->preference('NewItemsDefaultLocation') + }, + undef, + $itemnumber + ); } else { - $item->{'permanent_location'} = $item->{'location'} if !defined($item->{'permanent_location'}); - ModItem( $item, undef, $itemnumber); + ModItem( { permanent_location => $item->location }, undef, $itemnumber ) + unless defined $item->permanent_location; } } @@ -695,12 +700,12 @@ if ($op eq "additem") { if ($exist_itemnumber && $exist_itemnumber != $itemnumber) { push @errors,"barcode_not_unique"; } else { - my $item = GetItem( $itemnumber ); + my $item = Koha::Items->find($itemnumber ); my $newitem = ModItemFromMarc($itemtosave, $biblionumber, $itemnumber); $itemnumber = q{}; - my $olditemlost = $item->{itemlost}; + my $olditemlost = $item->itemlost; my $newitemlost = $newitem->{itemlost}; - LostItem( $item->{itemnumber}, 'additem' ) + LostItem( $item->itemnumber, 'additem' ) if $newitemlost && $newitemlost ge '1' && !$olditemlost; } $nextop="additem"; diff --git a/installer/data/mysql/backfill_statistics.pl b/installer/data/mysql/backfill_statistics.pl index d03b46177d..0264c2c890 100755 --- a/installer/data/mysql/backfill_statistics.pl +++ b/installer/data/mysql/backfill_statistics.pl @@ -79,13 +79,14 @@ my $query = "UPDATE statistics SET itemtype = ? WHERE itemnumber = ?"; my $update = $dbh->prepare($query); # $debug and print "Update Query: $query\n"; foreach (@itemnumbers) { - my $item = GetItem($_); - unless ($item) { + my $item = Koha::Items->find($_); + unless ($item) { print STDERR "\tNo item found for itemnumber $_\n"; next; } - $update->execute($item->{itype},$_) or warn "Error in UPDATE execution"; - printf "\titemnumber %5d : %7s (%s rows)\n", $_, $item->{itype}, $update->rows; + my $itemtype = $item->effective_itemtype; + $update->execute($itemtype,$_) or warn "Error in UPDATE execution"; + printf "\titemnumber %5d : %7s (%s rows)\n", $_, $itemtype, $update->rows; } my $old_issues = $dbh->prepare("SELECT * FROM old_issues WHERE timestamp = ? AND itemnumber = ?"); diff --git a/labels/label-edit-batch.pl b/labels/label-edit-batch.pl index 0121ad2b07..83c74e9c25 100755 --- a/labels/label-edit-batch.pl +++ b/labels/label-edit-batch.pl @@ -25,7 +25,6 @@ use CGI qw ( -utf8 ); use C4::Auth qw(get_template_and_user); use C4::Output qw(output_html_with_http_headers); -use C4::Items qw(GetItem); use C4::Creators; use C4::Labels; @@ -89,7 +88,7 @@ elsif ($op eq 'add') { my @numbers_list = split /\n/, $number_list; # Entries are effectively passed in as a separated list foreach my $number (@numbers_list) { $number =~ s/\r$//; # strip any naughty return chars - if( $number_type eq "itemnumber" && GetItem($number) ) { + if( $number_type eq "itemnumber" && Koha::Items->find($number) ) { push @item_numbers, $number; } elsif ($number_type eq "barcode" ) { # we must test in case an invalid barcode is passed in; we effectively disgard them atm diff --git a/misc/recreateIssueStatistics.pl b/misc/recreateIssueStatistics.pl index a4382f191b..6ba83e1e53 100755 --- a/misc/recreateIssueStatistics.pl +++ b/misc/recreateIssueStatistics.pl @@ -26,6 +26,7 @@ use C4::Context; use C4::Items; use Data::Dumper; use Getopt::Long; +use Koha::Items; my $dbh = C4::Context->dbh; @@ -73,7 +74,8 @@ if ($issues == 1) { my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"; $substh = $dbh->prepare($insert); - my $item = GetItem($hashref->{'itemnumber'}); + my $item = Koha::Items->find($hashref->{'itemnumber'}); + my $itemtype = $item->effective_itemtype; $substh->execute( $hashref->{'issuedate'}, @@ -82,10 +84,10 @@ if ($issues == 1) { 'issue', '', $hashref->{'itemnumber'}, - $item->{'itype'}, + $itemtype, $hashref->{'borrowernumber'} ); - print "date: $hashref->{'issuedate'} branchcode: $hashref->{'branchcode'} type: issue itemnumber: $hashref->{'itemnumber'} itype: $item->{'itype'} borrowernumber: $hashref->{'borrowernumber'}\n"; + print "date: $hashref->{'issuedate'} branchcode: $hashref->{'branchcode'} type: issue itemnumber: $hashref->{'itemnumber'} itype: $itemtype borrowernumber: $hashref->{'borrowernumber'}\n"; $count_issues++; } @@ -106,7 +108,8 @@ if ($issues == 1) { my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"; $substh = $dbh->prepare($insert); - my $item = GetItem($hashref->{'itemnumber'}); + my $item = Koha::Items->find($hashref->{'itemnumber'}); + my $itemtype = $item->effective_itemtype; $substh->execute( $hashref->{'lastreneweddate'}, @@ -115,10 +118,10 @@ if ($issues == 1) { 'renew', '', $hashref->{'itemnumber'}, - $item->{'itype'}, + $itemtype, $hashref->{'borrowernumber'} ); - print "date: $hashref->{'lastreneweddate'} branchcode: $hashref->{'branchcode'} type: renew itemnumber: $hashref->{'itemnumber'} itype: $item->{'itype'} borrowernumber: $hashref->{'borrowernumber'}\n"; + print "date: $hashref->{'lastreneweddate'} branchcode: $hashref->{'branchcode'} type: renew itemnumber: $hashref->{'itemnumber'} itype: $itemtype borrowernumber: $hashref->{'borrowernumber'}\n"; $count_renewals++; } @@ -145,7 +148,8 @@ if ($returns == 1) { my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"; $substh = $dbh->prepare($insert); - my $item = GetItem($hashref->{'itemnumber'}); + my $item = Koha::Items->find($hashref->{'itemnumber'}); + my $itemtype = $item->effective_itemtype; $substh->execute( $hashref->{'returndate'}, @@ -154,10 +158,10 @@ if ($returns == 1) { 'return', '', $hashref->{'itemnumber'}, - $item->{'itype'}, + $itemtype, $hashref->{'borrowernumber'} ); - print "date: $hashref->{'returndate'} branchcode: $hashref->{'branchcode'} type: return itemnumber: $hashref->{'itemnumber'} itype: $item->{'itype'} borrowernumber: $hashref->{'borrowernumber'}\n"; + print "date: $hashref->{'returndate'} branchcode: $hashref->{'branchcode'} type: return itemnumber: $hashref->{'itemnumber'} itype: $itemtype borrowernumber: $hashref->{'borrowernumber'}\n"; $count_returns++; } diff --git a/opac/opac-renew.pl b/opac/opac-renew.pl index 73606b0649..85570d54ad 100755 --- a/opac/opac-renew.pl +++ b/opac/opac-renew.pl @@ -29,6 +29,7 @@ use C4::Auth; use C4::Context; use C4::Items; use C4::Members; +use Koha::Items; use Koha::Patrons; use Date::Calc qw( Today Date_to_Days ); my $query = new CGI; @@ -65,14 +66,14 @@ else { my $renewalbranch = C4::Context->preference('OpacRenewalBranch'); my $branchcode; if ( $renewalbranch eq 'itemhomebranch' ) { - my $item = GetItem($itemnumber); - $branchcode = $item->{'homebranch'}; + my $item = Koha::Items->find($itemnumber); + $branchcode = $item->homebranch; } elsif ( $renewalbranch eq 'patronhomebranch' ) { $branchcode = Koha::Patrons->find( $borrowernumber )->branchcode; } elsif ( $renewalbranch eq 'checkoutbranch' ) { - my $issue = GetOpenIssue($itemnumber); + my $issue = GetOpenIssue($itemnumber); # FIXME Should not be $item->checkout? $branchcode = $issue->{'branchcode'}; } elsif ( $renewalbranch eq 'NULL' ) { diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 8da67e905f..ab1a835c08 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -176,10 +176,10 @@ if ( $op eq 'add_form' ) { $shelf = Koha::Virtualshelves->find($shelfnumber); if ($shelf) { if( my $barcode = $query->param('barcode') ) { - my $item = GetItem( 0, $barcode); - if (defined $item && $item->{itemnumber}) { + my $item = Koha::Items->find({ barcode => $barcode }); + if ( $item ) { if ( $shelf->can_biblios_be_added( $loggedinuser ) ) { - my $added = eval { $shelf->add_biblio( $item->{biblionumber}, $loggedinuser ); }; + my $added = eval { $shelf->add_biblio( $item->biblionumber, $loggedinuser ); }; if ($@) { push @messages, { type => 'error', code => ref($@), msg => $@ }; } elsif ( $added ) { diff --git a/opac/sco/sco-main.pl b/opac/sco/sco-main.pl index 9fcf7293b5..bb65d1bebe 100755 --- a/opac/sco/sco-main.pl +++ b/opac/sco/sco-main.pl @@ -45,6 +45,7 @@ use C4::Biblio; use C4::Items; use Koha::DateUtils qw( dt_from_string ); use Koha::Acquisition::Currencies; +use Koha::Items; use Koha::Patrons; use Koha::Patron::Images; use Koha::Patron::Messages; @@ -104,7 +105,7 @@ my ($op, $patronid, $patronlogin, $patronpw, $barcode, $confirmed) = ( my $issuenoconfirm = 1; #don't need to confirm on issue. my $issuer = Koha::Patrons->find( $issuerid )->unblessed; -my $item = GetItem(undef,$barcode); +my $item = Koha::Items->find({ barcode => $barcode }); if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) { my $dbh = C4::Context->dbh; my $resval; @@ -157,7 +158,7 @@ elsif ( $patron and $op eq "checkout" ) { $template->param( impossible => $issue_error, "circ_error_$issue_error" => 1, - title => $item->{title}, + title => $item->biblio->title, # FIXME Need to be backport! GetItem did not return the biblio's title hide_main => 1, ); if ($issue_error eq 'DEBT') { @@ -174,7 +175,7 @@ elsif ( $patron and $op eq "checkout" ) { } elsif ( $needconfirm->{RENEW_ISSUE} ) { if ($confirmed) { #warn "renewing"; - AddRenewal( $borrower->{borrowernumber}, $item->{itemnumber} ); + AddRenewal( $borrower->{borrowernumber}, $item->itemnumber ); } else { #warn "renew confirmation"; $template->param( @@ -235,7 +236,7 @@ elsif ( $patron and $op eq "checkout" ) { $confirm_required = 1; #warn "issue confirmation"; $template->param( - confirm => "Issuing title: " . $item->{title}, + confirm => "Issuing title: " . $item->biblio->title, barcode => $barcode, hide_main => 1, inputfocus => 'confirm', diff --git a/reserve/placerequest.pl b/reserve/placerequest.pl index 351041b5df..c614200a67 100755 --- a/reserve/placerequest.pl +++ b/reserve/placerequest.pl @@ -31,6 +31,8 @@ use C4::Reserves; use C4::Circulation; use C4::Members; use C4::Auth qw/checkauth/; + +use Koha::Items; use Koha::Patrons; my $input = CGI->new(); @@ -87,9 +89,9 @@ if ( $type eq 'str8' && $borrower ) { } if ( defined $checkitem && $checkitem ne '' ) { - my $item = GetItem($checkitem); - if ( $item->{'biblionumber'} ne $biblionumber ) { - $biblionumber = $item->{'biblionumber'}; + my $item = Koha::Items->find($checkitem); + if ( $item->biblionumber ne $biblionumber ) { + $biblionumber = $item->biblionumber; } } diff --git a/svc/checkin b/svc/checkin index 9b72abaa79..e0dc21c7db 100755 --- a/svc/checkin +++ b/svc/checkin @@ -24,7 +24,7 @@ use CGI; use JSON qw(to_json); use C4::Circulation; -use C4::Items qw(GetItem ModItem); +use C4::Items qw(ModItem); use C4::Context; use C4::Auth qw(check_cookie_auth); use Koha::Checkouts; @@ -64,17 +64,15 @@ $data->{borrowernumber} = $borrowernumber; $data->{branchcode} = $branchcode; if ( C4::Context->preference("InProcessingToShelvingCart") ) { - my $item = GetItem($itemnumber); - if ( $item->{'location'} eq 'PROC' ) { - $item->{'location'} = 'CART'; - ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} ); + my $item = Koha::Items->find($itemnumber); + if ( $item->location eq 'PROC' ) { + ModItem( { location => 'CART' }, $item->biblionumber, $item->itemnumber ); } } if ( C4::Context->preference("ReturnToShelvingCart") ) { - my $item = GetItem($itemnumber); - $item->{'location'} = 'CART'; - ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} ); + my $item = Koha::Items->find($itemnumber); + ModItem( { location => 'CART' }, $item->biblionumber, $item->itemnumber ); } my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber }); diff --git a/t/db_dependent/Acquisition/CancelReceipt.t b/t/db_dependent/Acquisition/CancelReceipt.t index a900885de6..f659e9ef3a 100644 --- a/t/db_dependent/Acquisition/CancelReceipt.t +++ b/t/db_dependent/Acquisition/CancelReceipt.t @@ -31,6 +31,7 @@ use Koha::Database; use Koha::DateUtils; use Koha::Acquisition::Booksellers; use Koha::Acquisition::Orders; +use Koha::Items; use MARC::Record; my $schema = Koha::Database->new()->schema(); @@ -162,10 +163,10 @@ is( "Create items on ordering: items are not deleted after cancelling a receipt" ); -my $item1 = C4::Items::GetItem( $itemnumber1 ); -is( $item1->{notforloan}, 9, "The notforloan value has been updated with '9'" ); +my $item1 = Koha::Items->find( $itemnumber1 ); +is( $item1->notforloan, 9, "The notforloan value has been updated with '9'" ); -my $item2 = C4::Items::GetItem( $itemnumber2 ); -is( $item2->{notforloan}, 0, "The notforloan value has been updated with '9'" ); +my $item2 = Koha::Items->find( $itemnumber2 ); +is( $item2->notforloan, 0, "The notforloan value has been updated with '9'" ); $schema->storage->txn_rollback(); diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 93f62571c6..e663e83fd7 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -35,6 +35,7 @@ use C4::Overdues qw(UpdateFine CalcFine); use Koha::DateUtils; use Koha::Database; use Koha::IssuingRules; +use Koha::Items; use Koha::Checkouts; use Koha::Patrons; use Koha::Subscriptions; @@ -484,7 +485,8 @@ C4::Context->dbh->do("DELETE FROM accountlines"); my $passeddatedue1 = AddIssue($renewing_borrower, $barcode7, $five_weeks_ago); is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due); - my ( $fine ) = CalcFine( GetItem(undef, $barcode7), $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now ); + my $item = Koha::Items->find({barcode => $barcode7}); + my ( $fine ) = CalcFine( $item->unblessed, $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now ); C4::Overdues::UpdateFine( { issue_id => $passeddatedue1->id(), @@ -857,7 +859,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); $line = Koha::Account::Lines->find($line->id); is( $line->accounttype, 'F', 'Account type correctly changed from FU to F' ); - my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber); + $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber); ok( !$item->onloan(), "Lost item marked as returned has false onloan value" ); my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber }); is( $checkout, undef, 'LostItem called with forced return has checked in the item' ); diff --git a/t/db_dependent/Circulation/IsItemIssued.t b/t/db_dependent/Circulation/IsItemIssued.t index ab26f0c3cb..7e4cf2334e 100644 --- a/t/db_dependent/Circulation/IsItemIssued.t +++ b/t/db_dependent/Circulation/IsItemIssued.t @@ -25,6 +25,7 @@ use C4::Items; use C4::Biblio; use Koha::Database; use Koha::DateUtils; +use Koha::Items; use Koha::Patrons; use t::lib::TestBuilder; @@ -68,12 +69,12 @@ my ( undef, undef, $itemnumber ) = AddItem( $biblionumber ); -my $item = GetItem( $itemnumber ); +my $item = Koha::Items->find( $itemnumber ); -is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" ); +is ( IsItemIssued( $item->itemnumber ), 0, "item is not on loan at first" ); AddIssue($borrower, 'i_dont_exist'); -is ( IsItemIssued( $item->{itemnumber} ), 1, "item is now on loan" ); +is ( IsItemIssued( $item->itemnumber ), 1, "item is now on loan" ); is( DelItemCheck( $biblionumber, $itemnumber), @@ -82,7 +83,7 @@ is( ); AddReturn('i_dont_exist', $library->{branchcode}); -is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" ); +is ( IsItemIssued( $item->itemnumber ), 0, "item has been returned" ); is( DelItemCheck( $biblionumber, $itemnumber), diff --git a/t/db_dependent/Circulation/Returns.t b/t/db_dependent/Circulation/Returns.t index bd21347694..bfedd31f01 100644 --- a/t/db_dependent/Circulation/Returns.t +++ b/t/db_dependent/Circulation/Returns.t @@ -87,17 +87,16 @@ subtest "InProcessingToShelvingCart tests" => sub { t::lib::Mocks::mock_preference( "InProcessingToShelvingCart", 1 ); AddReturn( $barcode, $branch ); - $item = GetItem( $itemnumber ); - is( $item->{location}, 'CART', + $item = Koha::Items->find( $itemnumber ); + is( $item->location, 'CART', "InProcessingToShelvingCart functions as intended" ); - $item->{location} = $location; - ModItem( $item, undef, $itemnumber ); + ModItem( {location => $location}, undef, $itemnumber ); t::lib::Mocks::mock_preference( "InProcessingToShelvingCart", 0 ); AddReturn( $barcode, $branch ); - $item = GetItem( $itemnumber ); - is( $item->{location}, $permanent_location, + $item = Koha::Items->find( $itemnumber ); + is( $item->location, $permanent_location, "InProcessingToShelvingCart functions as intended" ); }; diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t index f613f081f1..77416ead58 100644 --- a/t/db_dependent/Circulation/issue.t +++ b/t/db_dependent/Circulation/issue.t @@ -32,6 +32,7 @@ use Koha::Checkouts; use Koha::Database; use Koha::DateUtils; use Koha::Holds; +use Koha::Items; use Koha::Library; use Koha::Patrons; @@ -358,17 +359,17 @@ my $itemnumber; t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} ); AddReturn( 'barcode_3', $branchcode_1 ); -my $item = GetItem( $itemnumber ); -ok( $item->{notforloan} eq 1, 'UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' ); +my $item = Koha::Items->find( $itemnumber ); +ok( $item->notforloan eq 1, 'UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' ); t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', '1: 9' ); AddReturn( 'barcode_3', $branchcode_1 ); -$item = GetItem( $itemnumber ); -ok( $item->{notforloan} eq 9, q{UpdateNotForLoanStatusOnCheckin updates notforloan value from 1 to 9 with setting "1: 9"} ); +$item = Koha::Items->find( $itemnumber ); +ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin updates notforloan value from 1 to 9 with setting "1: 9"} ); AddReturn( 'barcode_3', $branchcode_1 ); -$item = GetItem( $itemnumber ); -ok( $item->{notforloan} eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} ); +$item = Koha::Items->find( $itemnumber ); +ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} ); # Bug 14640 - Cancel the hold on checking out if asked my $reserve_id = AddReserve($branchcode_1, $borrower_id1, $biblionumber, diff --git a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t b/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t index 645616c7cf..fc316a8d1d 100755 --- a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t +++ b/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t @@ -6,6 +6,7 @@ use C4::Context; use C4::Circulation; use C4::Items; use Koha::IssuingRule; +use Koha::Items; use Test::More tests => 6; @@ -79,7 +80,7 @@ my $itemnumber1 = $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber") or BAIL_OUT("Cannot find newly created item"); -my $item1 = GetItem( $itemnumber1 ); +my $item1 = Koha::Items->find( $itemnumber1 )->unblessed; $dbh->do(" INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype) @@ -90,7 +91,7 @@ my $itemnumber2 = $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber ORDER BY itemnumber DESC") or BAIL_OUT("Cannot find newly created item"); -my $item2 = GetItem( $itemnumber2 ); +my $item2 = Koha::Items->find( $itemnumber2 )->unblessed; $dbh->do("DELETE FROM issuingrules"); my $rule = Koha::IssuingRule->new( @@ -134,8 +135,9 @@ AddReturn( $item1->{barcode} ); subtest 'Item is available at a different library' => sub { plan tests => 4; - Koha::Items->find( $item1->{itemnumber} )->set({homebranch => $library_B, holdingbranch => $library_B })->store; - $item1 = GetItem( $itemnumber1 ); + $item1 = Koha::Items->find( $item1->{itemnumber} ); + $item1->set({homebranch => $library_B, holdingbranch => $library_B })->store; + $item1 = $item1->unblessed; #Scenario is: #One shelf holds is 'If all unavailable'/2 #Item 1 homebranch library B is available @@ -174,8 +176,9 @@ AddReturn( $item1->{barcode} ); subtest 'Item is available at the same library' => sub { plan tests => 4; - Koha::Items->find( $item1->{itemnumber} )->set({homebranch => $library_A, holdingbranch => $library_A })->store; - $item1 = GetItem( $itemnumber1 ); + $item1 = Koha::Items->find( $item1->{itemnumber} ); + $item1->set({homebranch => $library_A, holdingbranch => $library_A })->store; + $item1 = $item1->unblessed; #Scenario is: #One shelf holds is 'If all unavailable'/2 #Item 1 homebranch library A is available diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index bc7aaa9feb..ff069f32e0 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -64,11 +64,11 @@ subtest 'General Add, Get and Del tests' => sub { cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); # Get item. - my $getitem = GetItem($itemnumber); - cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber."); - cmp_ok($getitem->{'biblioitemnumber'}, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber."); - is( $getitem->{location}, $location, "The location should not have been modified" ); - is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to the location value" ); + my $getitem = Koha::Items->find($itemnumber); + cmp_ok($getitem->itemnumber, '==', $itemnumber, "Retrieved item has correct itemnumber."); + cmp_ok($getitem->biblioitemnumber, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber."); + is( $getitem->location, $location, "The location should not have been modified" ); + is( $getitem->permanent_location, $location, "The permanent_location should have been set to the location value" ); # Do not modify anything, and do not explode! @@ -78,35 +78,35 @@ subtest 'General Add, Get and Del tests' => sub { # Modify item; setting barcode. ModItem({ barcode => '987654321' }, $bibnum, $itemnumber); - my $moditem = GetItem($itemnumber); - cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.'); + my $moditem = Koha::Items->find($itemnumber); + cmp_ok($moditem->barcode, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->barcode . '.'); # Delete item. DelItem({ biblionumber => $bibnum, itemnumber => $itemnumber }); - my $getdeleted = GetItem($itemnumber); - is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); + my $getdeleted = Koha::Items->find($itemnumber); + is($getdeleted, undef, "Item deleted as expected."); ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $bibnum); - $getitem = GetItem($itemnumber); - is( $getitem->{location}, $location, "The location should not have been modified" ); - is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" ); + $getitem = Koha::Items->find($itemnumber); + is( $getitem->location, $location, "The location should not have been modified" ); + is( $getitem->permanent_location, 'my permanent location', "The permanent_location should not have modified" ); ModItem({ location => $location }, $bibnum, $itemnumber); - $getitem = GetItem($itemnumber); - is( $getitem->{location}, $location, "The location should have been set to correct location" ); - is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to location" ); + $getitem = Koha::Items->find($itemnumber); + is( $getitem->location, $location, "The location should have been set to correct location" ); + is( $getitem->permanent_location, $location, "The permanent_location should have been set to location" ); ModItem({ location => 'CART' }, $bibnum, $itemnumber); - $getitem = GetItem($itemnumber); - is( $getitem->{location}, 'CART', "The location should have been set to CART" ); - is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" ); + $getitem = Koha::Items->find($itemnumber); + is( $getitem->location, 'CART', "The location should have been set to CART" ); + is( $getitem->permanent_location, $location, "The permanent_location should not have been set to CART" ); t::lib::Mocks::mock_preference('item-level_itypes', '1'); - $getitem = GetItem($itemnumber); - is( $getitem->{itype}, $itemtype->{itemtype}, "Itemtype set correctly when using item-level_itypes" ); + $getitem = Koha::Items->find($itemnumber); + is( $getitem->effective_itemtype, $itemtype->{itemtype}, "Itemtype set correctly when using item-level_itypes" ); t::lib::Mocks::mock_preference('item-level_itypes', '0'); - $getitem = GetItem($itemnumber); - is( $getitem->{itype}, undef, "Itemtype set correctly when not using item-level_itypes" ); + $getitem = Koha::Items->find($itemnumber); + is( $getitem->effective_itemtype, undef, "Itemtype set correctly when not using item-level_itypes" ); $schema->storage->txn_rollback; }; @@ -194,8 +194,8 @@ subtest 'GetHiddenItemnumbers tests' => sub { my @itemnumbers = ($item1_itemnumber,$item2_itemnumber); my @hidden; my @items; - push @items, GetItem( $item1_itemnumber ); - push @items, GetItem( $item2_itemnumber ); + push @items, Koha::Items->find( $item1_itemnumber )->unblessed; + push @items, Koha::Items->find( $item2_itemnumber )->unblessed; # Empty OpacHiddenItems t::lib::Mocks::mock_preference('OpacHiddenItems',''); @@ -501,8 +501,8 @@ subtest 'SearchItems test' => sub { ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber); # Make sure the link is used - my $item3 = GetItem($item3_itemnumber); - ok($item3->{itemnotes} eq 'foobar', 'itemnotes eq "foobar"'); + my $item3 = Koha::Items->find($item3_itemnumber); + ok($item3->itemnotes eq 'foobar', 'itemnotes eq "foobar"'); # Do the same search again. # This time it will search in items.itemnotes @@ -718,21 +718,21 @@ subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblionumber); # Make sure everything has been set up - my $item = GetItem($item_itemnumber); - is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' ); + my $item = Koha::Items->find($item_itemnumber); + is( $item->barcode, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' ); # Delete the barcode field and save the record $item_record->delete_fields( $barcode_field ); $item_record->append_fields( $itemtype_field ); # itemtype is mandatory ModItemFromMarc($item_record, $biblionumber, $item_itemnumber); - $item = GetItem($item_itemnumber); - is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' ); + $item = Koha::Items->find($item_itemnumber); + is( $item->barcode, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' ); # Re-add the barcode field and save the record $item_record->append_fields( $barcode_field ); ModItemFromMarc($item_record, $biblionumber, $item_itemnumber); - $item = GetItem($item_itemnumber); - is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' ); + $item = Koha::Items->find($item_itemnumber); + is( $item->barcode, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' ); # Remove the mapping for barcode Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'p' })->delete; @@ -752,8 +752,8 @@ subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { $item_record->append_fields( $another_barcode_field ); # The DB value should not have been updated ModItemFromMarc($item_record, $biblionumber, $item_itemnumber); - $item = GetItem($item_itemnumber); - is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' ); + $item = Koha::Items->find($item_itemnumber); + is ( $item->barcode, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' ); $cache->clear_from_cache("default_value_for_mod_marc-"); $cache->clear_from_cache( "MarcSubfieldStructure-" ); diff --git a/t/db_dependent/Items/AutomaticItemModificationByAge.t b/t/db_dependent/Items/AutomaticItemModificationByAge.t index 17172be5d2..fad82fc67c 100644 --- a/t/db_dependent/Items/AutomaticItemModificationByAge.t +++ b/t/db_dependent/Items/AutomaticItemModificationByAge.t @@ -11,6 +11,7 @@ use C4::Items; use C4::Biblio; use C4::Context; use Koha::DateUtils; +use Koha::Items; use t::lib::TestBuilder; my $schema = Koha::Database->new->schema; @@ -61,8 +62,8 @@ my ($item_bibnum, $item_bibitemnum, $itemnumber) = C4::Items::AddItem( $biblionumber ); -my $item = C4::Items::GetItem( $itemnumber ); -is ( $item->{new_status}, 'new_value', q|AddItem insert the 'new_status' field| ); +my $item = Koha::Items->find( $itemnumber ); +is ( $item->new_status, 'new_value', q|AddItem insert the 'new_status' field| ); my ( $tagfield, undef ) = GetMarcFromKohaField('items.itemnumber', $frameworkcode); my $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); @@ -89,8 +90,8 @@ my @rules = ( C4::Items::ToggleNewStatus( { rules => \@rules } ); -my $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is updated|); +my $modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'updated_value', q|ToggleNewStatus: The new_status value is updated|); $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is updated| ); @@ -115,18 +116,16 @@ is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNew C4::Items::ToggleNewStatus( { rules => \@rules } ); -$modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is not updated|); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'updated_value', q|ToggleNewStatus: The new_status value is not updated|); $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is not updated| ); # Play with age -$item = C4::Items::GetItem( $itemnumber ); my $dt_today = dt_from_string; my $days5ago = $dt_today->add_duration( DateTime::Duration->new( days => -5 ) ); C4::Items::ModItem( { dateaccessioned => $days5ago }, $biblionumber, $itemnumber ); -$item = C4::Items::GetItem( $itemnumber ); @rules = ( { @@ -146,26 +145,26 @@ $item = C4::Items::GetItem( $itemnumber ); }, ); C4::Items::ToggleNewStatus( { rules => \@rules } ); -$modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: Age = 10 : The new_status value is not updated|); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'updated_value', q|ToggleNewStatus: Age = 10 : The new_status value is not updated|); $rules[0]->{age} = 5; $rules[0]->{substitutions}[0]{value} = 'new_updated_value5'; C4::Items::ToggleNewStatus( { rules => \@rules } ); -$modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new_status}, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new_status value is updated|); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new_status value is updated|); $rules[0]->{age} = ''; $rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string'; C4::Items::ToggleNewStatus( { rules => \@rules } ); -$modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new_status}, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new_status value is updated|); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new_status value is updated|); $rules[0]->{age} = undef; $rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef'; C4::Items::ToggleNewStatus( { rules => \@rules } ); -$modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new_status}, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new_status value is updated|); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new_status value is updated|); # Field deletion @rules = ( @@ -188,8 +187,8 @@ is( $modified_item->{new_status}, 'new_updated_value_undef', q|ToggleNewStatus: C4::Items::ToggleNewStatus( { rules => \@rules } ); -$modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new_status}, '', q|ToggleNewStatus: The new_status value is empty|); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, '', q|ToggleNewStatus: The new_status value is empty|); $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: The new_status field is removed from the item marc| ); @@ -218,8 +217,8 @@ is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: Th C4::Items::ToggleNewStatus( { rules => \@rules } ); -$modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new_status value is updated|); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new_status value is updated|); @rules = ( { @@ -245,8 +244,8 @@ is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions mul C4::Items::ToggleNewStatus( { rules => \@rules } ); -$modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions multiple: at least 1 condition does not match, the new_status value is not updated|); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'new_value', q|ToggleNewStatus: conditions multiple: at least 1 condition does not match, the new_status value is not updated|); @rules = ( { @@ -272,8 +271,8 @@ is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions mul C4::Items::ToggleNewStatus( { rules => \@rules } ); -$modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new_status}, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new_status value is updated|); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new_status value is updated|); @rules = ( { @@ -295,8 +294,8 @@ is( $modified_item->{new_status}, 'new_updated_value', q|ToggleNewStatus: condit C4::Items::ToggleNewStatus( { rules => \@rules } ); -$modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new_status}, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|); # Clear cache $cache = Koha::Caches->get_instance(); diff --git a/t/db_dependent/Items/DelItem.t b/t/db_dependent/Items/DelItem.t index 03f1f5840e..94262204c5 100644 --- a/t/db_dependent/Items/DelItem.t +++ b/t/db_dependent/Items/DelItem.t @@ -4,6 +4,8 @@ use MARC::Record; use C4::Items; use C4::Biblio; +use Koha::Items; + use t::lib::TestBuilder; use Test::More tests => 6; @@ -24,15 +26,15 @@ my ( $item_bibnum, $item_bibitemnum, $itemnumber ); my $deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } ); is( $deleted, 1, "DelItem should return 1 if the item has been deleted" ); -my $deleted_item = GetItem($itemnumber); -is( $deleted_item->{itemnumber}, undef, "DelItem with biblionumber parameter - the item should be deleted." ); +my $deleted_item = Koha::Items->find($itemnumber); +is( $deleted_item, undef, "DelItem with biblionumber parameter - the item should be deleted." ); ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblionumber ); $deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } ); is( $deleted, 1, "DelItem should return 1 if the item has been deleted" ); -$deleted_item = GetItem($itemnumber); -is( $deleted_item->{itemnumber}, undef, "DelItem without biblionumber parameter - the item should be deleted." ); +$deleted_item = Koha::Items->find($itemnumber); +is( $deleted_item, undef, "DelItem without biblionumber parameter - the item should be deleted." ); $deleted = DelItem( { itemnumber => $itemnumber + 1} ); is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" ); diff --git a/t/db_dependent/Items/MoveItemFromBiblio.t b/t/db_dependent/Items/MoveItemFromBiblio.t index 21855d91da..fec7e51442 100644 --- a/t/db_dependent/Items/MoveItemFromBiblio.t +++ b/t/db_dependent/Items/MoveItemFromBiblio.t @@ -22,6 +22,7 @@ use C4::Items; use C4::Reserves; use Koha::Database; use Koha::Holds; +use Koha::Items; use t::lib::TestBuilder; use Data::Dumper qw|Dumper|; @@ -79,12 +80,12 @@ $to_biblionumber_after_moved = C4::Items::MoveItemFromBiblio( $item2->{itemnumbe is( $to_biblionumber_after_moved, undef, 'MoveItemFromBiblio should return undef if the move has failed. If called twice, the item is not attached to the first biblio anymore' ); -my $get_item1 = C4::Items::GetItem( $item1->{itemnumber} ); -is( $get_item1->{biblionumber}, $from_biblio->{biblionumber}, 'The item1 should not have been moved' ); -my $get_item2 = C4::Items::GetItem( $item2->{itemnumber} ); -is( $get_item2->{biblionumber}, $to_biblio->{biblionumber}, 'The item2 should have been moved' ); -my $get_item3 = C4::Items::GetItem( $item3->{itemnumber} ); -is( $get_item3->{biblionumber}, $to_biblio->{biblionumber}, 'The item3 should not have been moved' ); +my $get_item1 = Koha::Items->find( $item1->{itemnumber} ); +is( $get_item1->biblionumber, $from_biblio->{biblionumber}, 'The item1 should not have been moved' ); +my $get_item2 = Koha::Items->find( $item2->{itemnumber} ); +is( $get_item2->biblionumber, $to_biblio->{biblionumber}, 'The item2 should have been moved' ); +my $get_item3 = Koha::Items->find( $item3->{itemnumber} ); +is( $get_item3->biblionumber, $to_biblio->{biblionumber}, 'The item3 should not have been moved' ); my $get_bib_level_hold = Koha::Holds->find( $bib_level_hold_not_to_move->{reserve_id} ); my $get_item_level_hold_1 = Koha::Holds->find( $item_level_hold_not_to_move->{reserve_id} ); diff --git a/t/db_dependent/Items_DelItemCheck.t b/t/db_dependent/Items_DelItemCheck.t index 57514d0491..ce06dfe629 100644 --- a/t/db_dependent/Items_DelItemCheck.t +++ b/t/db_dependent/Items_DelItemCheck.t @@ -19,6 +19,7 @@ use Modern::Perl; use C4::Circulation; use Koha::Database; +use Koha::Items; use t::lib::TestBuilder; use t::lib::Mocks; @@ -159,9 +160,9 @@ is( DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} ); -my $test_item = GetItem( $item->{itemnumber} ); +my $test_item = Koha::Items->find( $item->{itemnumber} ); -is( $test_item->{itemnumber}, undef, +is( $test_item, undef, "DelItemCheck should delete item if ItemSafeToDelete returns true" ); diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 9fe293df34..a830351050 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -35,6 +35,7 @@ use C4::Reserves; use Koha::Caches; use Koha::DateUtils; use Koha::Holds; +use Koha::Items; use Koha::Libraries; use Koha::Notice::Templates; use Koha::Patrons; @@ -539,7 +540,7 @@ is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber)->{status} , ####### EO Bug 13113 <<< #### -$item = GetItem($itemnumber); +$item = Koha::Items->find($itemnumber)->unblessed; ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" ); diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 59d824bad7..140b1dc355 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -176,7 +176,9 @@ if ($op eq "action") { foreach my $itemnumber(@itemnumbers){ $job->progress($i) if $runinbackground; - my $itemdata = GetItem($itemnumber); + my $itemdata = Koha::Items->find($itemnumber); + next unless $itemdata; # Should have been tested earlier, but just in case... + $itemdata = $itemdata->unblessed; if ( $del ){ my $return = DelItemCheck( $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'}); if ($return == 1) { @@ -531,7 +533,9 @@ sub BuildItemsData{ my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", ""); my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", ""); foreach my $itemnumber (@itemnumbers){ - my $itemdata=GetItem($itemnumber); + my $itemdata = Koha::Items->find($itemnumber); + next unless $itemdata; # Should have been tested earlier, but just in case... + $itemdata = $itemdata->unblessed; my $itemmarc=Item2Marc($itemdata); my %this_row; foreach my $field (grep {$_->tag() eq $itemtagfield} $itemmarc->fields()) { diff --git a/tools/inventory.pl b/tools/inventory.pl index b5c94d6d94..94ec8c3877 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -39,6 +39,7 @@ use Koha::Biblios; use Koha::DateUtils; use Koha::AuthorisedValues; use Koha::BiblioFrameworks; +use Koha::Items; use List::MoreUtils qw( none ); my $minlocation=$input->param('minlocation') || ''; @@ -187,8 +188,9 @@ if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) { push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; } else { - my $item = GetItem( '', $barcode ); - if ( defined $item && $item->{'itemnumber'} ) { + my $item = Koha::Items->find({barcode => $barcode}); + if ( $item ) { + $item = $item->unblessed; # Modify date last seen for scanned items, remove lost status ModItem( { itemlost => 0, datelastseen => $date }, undef, $item->{'itemnumber'} ); $moddatecount++; diff --git a/tools/viewlog.pl b/tools/viewlog.pl index 2f8bc30e3e..f93725fc3f 100755 --- a/tools/viewlog.pl +++ b/tools/viewlog.pl @@ -31,6 +31,8 @@ use C4::Items; use C4::Serials; use C4::Debug; use C4::Search; # enabled_staff_search_views + +use Koha::Items; use Koha::Patrons; use vars qw($debug $cgi_debug); @@ -120,11 +122,11 @@ if ($do_it) { # get item information so we can create a working link my $itemnumber = $result->{'object'}; $itemnumber = $result->{'info'} if ( $result->{module} eq "CIRCULATION" ); - my $item = GetItem($itemnumber); + my $item = Koha::Items->find($itemnumber); if ($item) { - $result->{'biblionumber'} = $item->{'biblionumber'}; - $result->{'biblioitemnumber'} = $item->{'biblionumber'}; - $result->{'barcode'} = $item->{'barcode'}; + $result->{'biblionumber'} = $item->biblionumber; + $result->{'biblioitemnumber'} = $item->biblionumber; + $result->{'barcode'} = $item->barcode; } } diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index bd1c0d4654..495f4429b3 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -29,6 +29,7 @@ use C4::XSLT; use Koha::Biblios; use Koha::Biblioitems; +use Koha::Items; use Koha::ItemTypes; use Koha::CsvProfiles; use Koha::Patrons; @@ -151,9 +152,9 @@ if ( $op eq 'add_form' ) { foreach my $barcode (@barcodes){ $barcode =~ s/\r$//; # strip any naughty return chars next if $barcode eq ''; - my $item = GetItem( 0, $barcode); - if (defined $item && $item->{itemnumber}) { - my $added = eval { $shelf->add_biblio( $item->{biblionumber}, $loggedinuser ); }; + my $item = Koha::Items->find({barcode => $barcode}); + if ( $item ) { + my $added = eval { $shelf->add_biblio( $item->biblionumber, $loggedinuser ); }; if ($@) { push @messages, { item_barcode => $barcode, type => 'alert', code => ref($@), msg => $@ }; } elsif ( $added ) { -- 2.11.0