From 50d917dbfcfaf113e4bc479c33ea18de97414bfa Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 29 Mar 2022 00:59:18 +1300 Subject: [PATCH] Bug 30291: Changes to controller scripts Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- C4/Circulation.pm | 40 ++++++++++++------------- C4/Letters.pm | 2 +- C4/Overdues.pm | 4 +-- C4/Reserves.pm | 2 +- C4/Search.pm | 2 +- C4/XSLT.pm | 2 +- Koha/Biblio.pm | 2 +- Koha/Item.pm | 18 ++++++------ Koha/Patron.pm | 2 +- Koha/Recall.pm | 54 +++++++++++++++++----------------- Koha/Recalls.pm | 36 +++++++++++------------ Koha/Template/Plugin/Biblio.pm | 2 +- 12 files changed, 83 insertions(+), 83 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 46f538dd8d..2ae081d6b1 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -384,10 +384,10 @@ sub transferbook { # find recall if ( C4::Context->preference('UseRecalls') ) { - my $recall = Koha::Recalls->find({ itemnumber => $itemnumber, status => 'in_transit' }); + my $recall = Koha::Recalls->find({ item_id => $itemnumber, status => 'in_transit' }); if ( defined $recall ) { # do a transfer if the recall branch is different to the item holding branch - if ( $recall->branchcode eq $fbr ) { + if ( $recall->pickup_library_id eq $fbr ) { $dotransfer = 0; $messages->{'RecallPlacedAtHoldingBranch'} = 1; } else { @@ -1137,35 +1137,35 @@ sub CanBookBeIssued { # Only bother doing this if UseRecalls is enabled and the item is recallable # Don't look at recalls that are in transit if ( C4::Context->preference('UseRecalls') and $item_object->can_be_waiting_recall ) { - my @recalls = $biblio->recalls({},{ order_by => { -asc => 'recalldate' } })->filter_by_current->as_list; + my @recalls = $biblio->recalls({},{ order_by => { -asc => 'created_date' } })->filter_by_current->as_list; foreach my $r ( @recalls ) { - if ( $r->itemnumber and - $r->itemnumber == $item_object->itemnumber and - $r->borrowernumber == $patron->borrowernumber and + if ( $r->item_id and + $r->item_id == $item_object->itemnumber and + $r->patron_id == $patron->borrowernumber and ( $r->waiting or $r->requested ) ) { - $messages{RECALLED} = $r->recall_id; + $messages{RECALLED} = $r->id; $recall = $r; # this item is recalled by or already waiting for this borrower and the recall can be fulfilled last; } - elsif ( $r->itemnumber and - $r->itemnumber == $item_object->itemnumber and + elsif ( $r->item_id and + $r->item_id == $item_object->itemnumber and $r->in_transit ) { # recalled item is in transit - $issuingimpossible{RECALLED_INTRANSIT} = $r->branchcode; + $issuingimpossible{RECALLED_INTRANSIT} = $r->pickup_library_id; } - elsif ( $r->item_level_recall and - $r->itemnumber == $item_object->itemnumber and - $r->borrowernumber != $patron->borrowernumber and + elsif ( $r->item_level and + $r->item_id == $item_object->itemnumber and + $r->patron_id != $patron->borrowernumber and !$r->in_transit ) { # this specific item has been recalled by a different patron $needsconfirmation{RECALLED} = $r; $recall = $r; last; } - elsif ( !$r->item_level_recall and - $r->borrowernumber != $patron->borrowernumber and + elsif ( !$r->item_level and + $r->patron_id != $patron->borrowernumber and !$r->in_transit ) { # a different patron has placed a biblio-level recall and this item is eligible to fill it $needsconfirmation{RECALLED} = $r; @@ -2318,7 +2318,7 @@ sub AddReturn { $recall = $item->check_recalls if $item->can_be_waiting_recall; if ( defined $recall ) { $messages->{RecallFound} = $recall; - if ( $recall->branchcode ne $branch ) { + if ( $recall->pickup_library_id ne $branch ) { $messages->{RecallNeedsTransfer} = $branch; } } @@ -2385,8 +2385,8 @@ sub AddReturn { if ( C4::Context->preference('UseRecalls') ) { # all recalls that have triggered a transfer will have an allocated itemnumber - my $transfer_recall = Koha::Recalls->find({ itemnumber => $item->itemnumber, status => 'in_transit' }); - if ( $transfer_recall and $transfer_recall->branchcode eq $branch ) { + my $transfer_recall = Koha::Recalls->find({ item_id => $item->itemnumber, status => 'in_transit' }); + if ( $transfer_recall and $transfer_recall->pickup_library_id eq $branch ) { $messages->{TransferredRecall} = $transfer_recall; } } @@ -2928,9 +2928,9 @@ sub CanBookBeRenewed { my $recall = undef; $recall = $item->check_recalls if $item->can_be_waiting_recall; if ( defined $recall ) { - if ( $recall->item_level_recall ) { + if ( $recall->item_level ) { # item-level recall. check if this item is the recalled item, otherwise renewal will be allowed - return ( 0, 'recalled' ) if ( $recall->itemnumber == $item->itemnumber ); + return ( 0, 'recalled' ) if ( $recall->item_id == $item->itemnumber ); } else { # biblio-level recall, so only disallow renewal if the biblio-level recall has been fulfilled by a different item return ( 0, 'recalled' ) unless ( $recall->waiting ); diff --git a/C4/Letters.pm b/C4/Letters.pm index 7c63b23d8e..ddb43568fc 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -751,7 +751,7 @@ sub _parseletter_sth { ($table eq 'serial') ? "SELECT * FROM $table WHERE serialid = ?" : ($table eq 'problem_reports') ? "SELECT * FROM $table WHERE reportid = ?" : ($table eq 'additional_contents' || $table eq 'opac_news') ? "SELECT * FROM additional_contents WHERE idnew = ?" : - ($table eq 'recalls') ? "SELECT * FROM $table WHERE recall_id = ?" : + ($table eq 'recalls') ? "SELECT * FROM $table WHERE id = ?" : undef ; unless ($query) { warn "ERROR: No _parseletter_sth query for table '$table'"; diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 09d6724ff3..5db9c22041 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -260,11 +260,11 @@ sub CalcFine { # check if item has been recalled. recall should have been marked Overdue by cronjob, so only look at overdue recalls # only charge using recall_overdue_fine if there is an item-level recall for this particular item, OR a biblio-level recall - my @recalls = Koha::Recalls->search({ biblionumber => $item->{biblionumber}, status => 'overdue' })->as_list; + my @recalls = Koha::Recalls->search({ biblio_id => $item->{biblionumber}, status => 'overdue' })->as_list; my $bib_level_recall = 0; $bib_level_recall = 1 if scalar @recalls > 0; foreach my $recall ( @recalls ) { - if ( $recall->item_level_recall and $recall->itemnumber == $item->{itemnumber} and $issuing_rule->{recall_overdue_fine} ) { + if ( $recall->item_level and $recall->item_id == $item->{itemnumber} and $issuing_rule->{recall_overdue_fine} ) { $bib_level_recall = 0; $amount = $charge_periods * $issuing_rule->{recall_overdue_fine}; last; diff --git a/C4/Reserves.pm b/C4/Reserves.pm index a86a063906..81fecaebe0 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -440,7 +440,7 @@ sub CanItemBeReserved { # check if a recall exists on this item from this borrower return { status => 'recall' } - if $patron->recalls->filter_by_current->search({ itemnumber => $item->itemnumber })->count; + if $patron->recalls->filter_by_current->search({ item_id => $item->itemnumber })->count; my $controlbranch = C4::Context->preference('ReservesControlBranch'); diff --git a/C4/Search.pm b/C4/Search.pm index 85a02bf5a2..5842b0e6cc 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1904,7 +1904,7 @@ sub searchResults { ($transfertwhen, $transfertfrom, $transfertto) = C4::Circulation::GetTransfers($item->{itemnumber}); $reservestatus = C4::Reserves::GetReserveStatus( $item->{itemnumber} ); if ( C4::Context->preference('UseRecalls') ) { - if ( Koha::Recalls->search({ itemnumber => $item->{itemnumber}, status => 'waiting' })->count ) { + if ( Koha::Recalls->search({ item_id => $item->{itemnumber}, status => 'waiting' })->count ) { $recallstatus = 'Waiting'; } } diff --git a/C4/XSLT.pm b/C4/XSLT.pm index ca25d0db30..0fb7be0d6c 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -357,7 +357,7 @@ sub buildKohaItemsNamespace { my $recalls_count; if ( C4::Context->preference('UseRecalls') ) { - $recalls_count = Koha::Recalls->search({ itemnumber => $item->itemnumber, status => 'waiting' })->count; + $recalls_count = Koha::Recalls->search({ item_id => $item->itemnumber, status => 'waiting' })->count; } if ($recalls_count) { diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 4022819e9c..087efc78a6 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -1250,7 +1250,7 @@ sub can_be_recalled { return 0 if ( $patron->recalls->filter_by_current->count >= $recalls_allowed ); # check borrower has not reached open recalls allowed per record limit - return 0 if ( $patron->recalls->filter_by_current->search({ biblionumber => $self->biblionumber })->count >= $recalls_per_record ); + return 0 if ( $patron->recalls->filter_by_current->search({ biblio_id => $self->biblionumber })->count >= $recalls_per_record ); # check if any of the items under this biblio are already checked out by this borrower return 0 if ( Koha::Checkouts->search({ itemnumber => [ @all_itemnumbers ], borrowernumber => $patron->borrowernumber })->count > 0 ); diff --git a/Koha/Item.pm b/Koha/Item.pm index e4e71c5beb..312b2b4de6 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1476,13 +1476,13 @@ sub recall { my ( $self ) = @_; my @recalls = Koha::Recalls->search( { - biblionumber => $self->biblionumber, - old => 0, + biblio_id => $self->biblionumber, + completed => 0, }, - { order_by => { -asc => 'recalldate' } } + { order_by => { -asc => 'created_date' } } )->as_list; foreach my $recall (@recalls) { - if ( $recall->item_level_recall and $recall->itemnumber == $self->itemnumber ){ + if ( $recall->item_level and $recall->item_id == $self->itemnumber ){ return $recall; } } @@ -1539,10 +1539,10 @@ sub can_be_recalled { return 0 if ( $patron->recalls->filter_by_current->count >= $rule->{recalls_allowed} ); # check borrower has not reach open recalls allowed per record limit - return 0 if ( $patron->recalls->filter_by_current->search({ biblionumber => $self->biblionumber })->count >= $rule->{recalls_per_record} ); + return 0 if ( $patron->recalls->filter_by_current->search({ biblio_id => $self->biblionumber })->count >= $rule->{recalls_per_record} ); # check if this patron has already recalled this item - return 0 if ( Koha::Recalls->search({ itemnumber => $self->itemnumber, borrowernumber => $patron->borrowernumber })->filter_by_current->count > 0 ); + return 0 if ( Koha::Recalls->search({ item_id => $self->itemnumber, patron_id => $patron->borrowernumber })->filter_by_current->count > 0 ); # check if this patron has already checked out this item return 0 if ( Koha::Checkouts->search({ itemnumber => $self->itemnumber, borrowernumber => $patron->borrowernumber })->count > 0 ); @@ -1628,10 +1628,10 @@ sub check_recalls { my ( $self ) = @_; my @recalls = Koha::Recalls->search( - { biblionumber => $self->biblionumber, - itemnumber => [ $self->itemnumber, undef ] + { biblio_id => $self->biblionumber, + item_id => [ $self->itemnumber, undef ] }, - { order_by => { -asc => 'recalldate' } } + { order_by => { -asc => 'created_date' } } )->filter_by_current->as_list; my $recall; diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 80d5c2b5f3..f2d731d541 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -2072,7 +2072,7 @@ Return the patron's recalls. sub recalls { my ( $self ) = @_; - return Koha::Recalls->search({ borrowernumber => $self->borrowernumber }); + return Koha::Recalls->search({ patron_id => $self->borrowernumber }); } =head3 account_balance diff --git a/Koha/Recall.pm b/Koha/Recall.pm index b5d0c2c5c4..ebe2037c93 100644 --- a/Koha/Recall.pm +++ b/Koha/Recall.pm @@ -108,11 +108,11 @@ Returns the related Koha::Checkout object for this recall. sub checkout { my ( $self ) = @_; - $self->{_checkout} ||= Koha::Checkouts->find({ itemnumber => $self->itemnumber }); + $self->{_checkout} ||= Koha::Checkouts->find({ itemnumber => $self->item_id }); - unless ( $self->item_level_recall ) { + unless ( $self->item_level ) { # Only look at checkouts of items that are allowed to be recalled, and get the oldest one - my @items = Koha::Items->search({ biblionumber => $self->biblionumber })->as_list; + my @items = Koha::Items->search({ biblionumber => $self->biblio_id })->as_list; my @itemnumbers; foreach (@items) { my $recalls_allowed = Koha::CirculationRules->get_effective_rule({ @@ -250,7 +250,7 @@ sub calc_expirationdate { my ( $self ) = @_; my $item; - if ( $self->item_level_recall ) { + if ( $self->item_level ) { $item = $self->item; } elsif ( $self->checkout ) { $item = $self->checkout->item; @@ -285,15 +285,15 @@ Set the recall as in transit. sub start_transfer { my ( $self, $params ) = @_; - if ( $self->item_level_recall ) { + if ( $self->item_level ) { # already has an itemnumber $self->update({ status => 'in_transit' }); } else { my $itemnumber = $params->{item}->itemnumber; - $self->update({ status => 'in_transit', itemnumber => $itemnumber }); + $self->update({ status => 'in_transit', item_id => $itemnumber }); } - my ( $dotransfer, $messages ) = C4::Circulation::transferbook({ to_branch => $self->branchcode, from_branch => $self->item->holdingbranch, barcode => $self->item->barcode, trigger => 'Recall' }); + my ( $dotransfer, $messages ) = C4::Circulation::transferbook({ to_branch => $self->pickup_library_id, from_branch => $self->item->holdingbranch, barcode => $self->item->barcode, trigger => 'Recall' }); return ( $self, $dotransfer, $messages ); } @@ -309,10 +309,10 @@ If a transfer is cancelled, revert the recall to requested. sub revert_transfer { my ( $self ) = @_; - if ( $self->item_level_recall ) { + if ( $self->item_level ) { $self->update({ status => 'requested' }); } else { - $self->update({ status => 'requested', itemnumber => undef }); + $self->update({ status => 'requested', item_id => undef }); } return $self; @@ -335,26 +335,26 @@ sub set_waiting { my ( $self, $params ) = @_; my $itemnumber; - if ( $self->item_level_recall ) { - $itemnumber = $self->itemnumber; - $self->update({ status => 'waiting', waitingdate => dt_from_string, expirationdate => $params->{expirationdate} }); + if ( $self->item_level ) { + $itemnumber = $self->item_id; + $self->update({ status => 'waiting', waiting_date => dt_from_string, expiration_date => $params->{expirationdate} }); } else { # biblio-level recall with no itemnumber. need to set itemnumber $itemnumber = $params->{item}->itemnumber; - $self->update({ status => 'waiting', waitingdate => dt_from_string, expirationdate => $params->{expirationdate}, itemnumber => $itemnumber }); + $self->update({ status => 'waiting', waiting_date => dt_from_string, expiration_date => $params->{expirationdate}, item_id => $itemnumber }); } # send notice to recaller to pick up item my $letter = C4::Letters::GetPreparedLetter( module => 'circulation', letter_code => 'PICKUP_RECALLED_ITEM', - branchcode => $self->branchcode, + branchcode => $self->pickup_library_id, want_librarian => 0, tables => { - biblio => $self->biblionumber, - borrowers => $self->borrowernumber, + biblio => $self->biblio_id, + borrowers => $self->patron_id, items => $itemnumber, - recalls => $self->recall_id, + recalls => $self->id, }, ); @@ -373,10 +373,10 @@ Revert recall waiting status. sub revert_waiting { my ( $self ) = @_; - if ( $self->item_level_recall ){ - $self->update({ status => 'requested', waitingdate => undef }); + if ( $self->item_level ){ + $self->update({ status => 'requested', waiting_date => undef }); } else { - $self->update({ status => 'requested', waitingdate => undef, itemnumber => undef }); + $self->update({ status => 'requested', waiting_date => undef, item_id => undef }); } return $self; } @@ -411,7 +411,7 @@ sub set_overdue { my ( $self, $params ) = @_; my $interface = $params->{interface} || 'COMMANDLINE'; $self->update({ status => 'overdue' }); - C4::Log::logaction( 'RECALLS', 'OVERDUE', $self->recall_id, "Recall status set to overdue", $interface ) if ( C4::Context->preference('RecallsLog') ); + C4::Log::logaction( 'RECALLS', 'OVERDUE', $self->id, "Recall status set to overdue", $interface ) if ( C4::Context->preference('RecallsLog') ); return $self; } @@ -426,8 +426,8 @@ Set a recall as expired. This may be done manually or by a cronjob, either when sub set_expired { my ( $self, $params ) = @_; my $interface = $params->{interface} || 'COMMANDLINE'; - $self->update({ status => 'expired', old => 1, expirationdate => dt_from_string }); - C4::Log::logaction( 'RECALLS', 'EXPIRE', $self->recall_id, "Recall expired", $interface ) if ( C4::Context->preference('RecallsLog') ); + $self->update({ status => 'expired', completed => 1, completed_date => dt_from_string }); + C4::Log::logaction( 'RECALLS', 'EXPIRE', $self->id, "Recall expired", $interface ) if ( C4::Context->preference('RecallsLog') ); return $self; } @@ -441,8 +441,8 @@ Set a recall as cancelled. This may be done manually, either by the borrower tha sub set_cancelled { my ( $self ) = @_; - $self->update({ status => 'cancelled', old => 1, cancellationdate => dt_from_string }); - C4::Log::logaction( 'RECALLS', 'CANCEL', $self->recall_id, "Recall cancelled", 'INTRANET' ) if ( C4::Context->preference('RecallsLog') ); + $self->update({ status => 'cancelled', completed => 1, completed_date => dt_from_string }); + C4::Log::logaction( 'RECALLS', 'CANCEL', $self->id, "Recall cancelled", 'INTRANET' ) if ( C4::Context->preference('RecallsLog') ); return $self; } @@ -456,8 +456,8 @@ Set a recall as finished. This should only be called when the item allocated to sub set_fulfilled { my ( $self ) = @_; - $self->update({ status => 'fulfilled', old => 1 }); - C4::Log::logaction( 'RECALLS', 'FULFILL', $self->recall_id, "Recall fulfilled", 'INTRANET' ) if ( C4::Context->preference('RecallsLog') ); + $self->update({ status => 'fulfilled', completed => 1, completed_date => dt_from_string }); + C4::Log::logaction( 'RECALLS', 'FULFILL', $self->id, "Recall fulfilled", 'INTRANET' ) if ( C4::Context->preference('RecallsLog') ); return $self; } diff --git a/Koha/Recalls.pm b/Koha/Recalls.pm index ca6bf1090f..ef73bf9917 100644 --- a/Koha/Recalls.pm +++ b/Koha/Recalls.pm @@ -118,18 +118,18 @@ sub add_recall { } my $recall_request = Koha::Recall->new({ - borrowernumber => $patron->borrowernumber, - recalldate => dt_from_string(), - biblionumber => $biblio->biblionumber, - branchcode => $branchcode, + patron_id => $patron->borrowernumber, + created_date => dt_from_string(), + biblio_id => $biblio->biblionumber, + pickup_library_id => $branchcode, status => 'requested', - itemnumber => defined $itemnumber ? $itemnumber : undef, - expirationdate => $expirationdate, - item_level_recall => defined $itemnumber ? 1 : 0, + item_id => defined $itemnumber ? $itemnumber : undef, + expiration_date => $expirationdate, + item_level => defined $itemnumber ? 1 : 0, })->store; - if (defined $recall_request->recall_id){ # successful recall - my $recall = Koha::Recalls->find( $recall_request->recall_id ); + if (defined $recall_request->id){ # successful recall + my $recall = Koha::Recalls->find( $recall_request->id ); # get checkout and adjust due date based on circulation rules my $checkout = $recall->checkout; @@ -145,13 +145,13 @@ sub add_recall { $checkout->update({ date_due => $due_date }); # get itemnumber of most relevant checkout if a biblio-level recall - unless ( $recall->item_level_recall ) { $itemnumber = $checkout->itemnumber; } + unless ( $recall->item_level ) { $itemnumber = $checkout->itemnumber; } # send notice to user with recalled item checked out my $letter = C4::Letters::GetPreparedLetter ( module => 'circulation', letter_code => 'RETURN_RECALLED_ITEM', - branchcode => $recall->branchcode, + branchcode => $recall->pickup_library_id, tables => { biblio => $biblio->biblionumber, borrowers => $checkout->borrowernumber, @@ -168,13 +168,13 @@ sub add_recall { branch => C4::Context->userenv->{'branch'}, type => 'recall', itemnumber => $itemnumber, - borrowernumber => $recall->borrowernumber, + borrowernumber => $recall->patron_id, itemtype => $item->effective_itemtype, ccode => $item->ccode, }); # add action log - C4::Log::logaction( 'RECALLS', 'CREATE', $recall->recall_id, "Recall requested by borrower #" . $recall->borrowernumber, $interface ) if ( C4::Context->preference('RecallsLog') ); + C4::Log::logaction( 'RECALLS', 'CREATE', $recall->id, "Recall requested by borrower #" . $recall->patron_id, $interface ) if ( C4::Context->preference('RecallsLog') ); return ( $recall, $due_interval, $due_date ); } @@ -230,12 +230,12 @@ sub move_recall { # move_recall was not called to revert or cancel, but was called to fulfill my $recall = Koha::Recalls->search( { - borrowernumber => $borrowernumber, - biblionumber => $item->biblionumber, - itemnumber => [ $item->itemnumber, undef ], - old => 0, + patron_id => $borrowernumber, + biblio_id => $item->biblionumber, + item_id => [ $item->itemnumber, undef ], + completed => 0, }, - { order_by => { -asc => 'recalldate' } } + { order_by => { -asc => 'created_date' } } )->next; if ( $recall ) { $recall->set_fulfilled; diff --git a/Koha/Template/Plugin/Biblio.pm b/Koha/Template/Plugin/Biblio.pm index 19e10163fc..92b130ac10 100644 --- a/Koha/Template/Plugin/Biblio.pm +++ b/Koha/Template/Plugin/Biblio.pm @@ -60,7 +60,7 @@ sub CanArticleRequest { sub RecallsCount { my ( $self, $biblionumber ) = @_; - my $recalls = Koha::Recalls->search({ biblionumber => $biblionumber, old => 0 }); + my $recalls = Koha::Recalls->search({ biblio_id => $biblionumber, completed => 0 }); return $recalls->count; } -- 2.39.5