From 843ce1bc6566b9bd49cf479e2843a121caf8d466 Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Tue, 20 Jan 2026 13:27:30 +0000 Subject: [PATCH] Bug 39723: Remove GetSuggestionInfoFromBiblionumber from C4/Suggestions.pm To test: Create, edit and receive a command from a suggestion (the lonely call of modReceiveOrder is at the receipt in acqui/finishreceive.pl) Run `prove prove t/db_dependent/Acquisition.t` Run `prove prove t/db_dependent/Suggestions.t` --- C4/Suggestions.pm | 28 -------------------- acqui/basket.pl | 10 +++---- acqui/orderreceive.pl | 2 +- acqui/parcel.pl | 10 +++---- t/db_dependent/Suggestions.t | 51 ++---------------------------------- 5 files changed, 13 insertions(+), 88 deletions(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index a458ebf6647..d1ed57fda99 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -27,7 +27,6 @@ BEGIN { DelSuggestion GetSuggestion GetSuggestionByStatus - GetSuggestionInfoFromBiblionumber GetSuggestionInfo ModStatus ModSuggestion @@ -72,33 +71,6 @@ Suggestions done by other borrowers can be seen when not "AVAILABLE" =head1 FUNCTIONS -=head2 GetSuggestionInfoFromBiblionumber - -Get a suggestion and borrower's information from it's biblionumber. - -return : -all information (suggestion and borrower) of the suggestion which is related to the biblionumber given. - -=cut - -sub GetSuggestionInfoFromBiblionumber { - my ($biblionumber) = @_; - my $query = q{ - SELECT suggestions.*, - U1.surname AS surnamesuggestedby, - U1.firstname AS firstnamesuggestedby, - U1.borrowernumber AS borrnumsuggestedby - FROM suggestions - LEFT JOIN borrowers AS U1 ON suggestedby=U1.borrowernumber - WHERE biblionumber=? - LIMIT 1 - }; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare($query); - $sth->execute($biblionumber); - return $sth->fetchrow_hashref; -} - =head2 GetSuggestionInfo Get a suggestion and borrower's information from it's suggestionid diff --git a/acqui/basket.pl b/acqui/basket.pl index 9d00d40f880..6453f2795c3 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -28,7 +28,7 @@ use C4::Acquisition qw( GetBasket CanUserManageBasket GetBasketAsCSV NewBasket NewBasketgroup ModBasket ReopenBasket ModBasketUsers GetBasketgroup GetBasketgroups GetBasketUsers GetOrders GetOrder get_rounded_price ); use C4::Budgets qw( GetBudgetHierarchy GetBudget CanUserUseBudget ); use C4::Contract qw( GetContract ); -use C4::Suggestions qw( GetSuggestionInfoFromBiblionumber GetSuggestionInfo ); +use C4::Suggestions qw( GetSuggestionInfo ); use Koha::Biblios; use Koha::Acquisition::Baskets; use Koha::Acquisition::Booksellers; @@ -658,10 +658,10 @@ sub get_order_infos { $line{deleted_biblio} = Koha::Old::Biblios->find( $order->{deleted_biblionumber} ); } - my $suggestion = GetSuggestionInfoFromBiblionumber( $line{biblionumber} ); - $line{suggestionid} = $$suggestion{suggestionid}; - $line{surnamesuggestedby} = $$suggestion{surnamesuggestedby}; - $line{firstnamesuggestedby} = $$suggestion{firstnamesuggestedby}; + my $suggestion = Koha::Suggestions->find( { biblionumber => $line{biblionumber} } ); + $line{suggestionid} = $suggestion->suggestionid; + $line{surnamesuggestedby} = $suggestion->suggester->surname; + $line{firstnamesuggestedby} = $suggestion->suggester->firstname; $line{estimated_delivery_date} = $order->{estimated_delivery_date}; diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index 4fa0ba9db27..216f5b9750e 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -67,7 +67,7 @@ use C4::Output qw( output_html_with_http_headers ); use C4::Budgets qw( GetBudget GetBudgetPeriods GetBudgetPeriod GetBudgetHierarchy CanUserUseBudget ); use C4::Members; use C4::Biblio qw( GetMarcStructure ); -use C4::Suggestions qw( GetSuggestionInfoFromBiblionumber GetSuggestionInfo ); +use C4::Suggestions qw( GetSuggestionInfo ); use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; diff --git a/acqui/parcel.pl b/acqui/parcel.pl index 2fb010459eb..fda6d8e9a1f 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -60,7 +60,7 @@ use C4::Acquisition qw( CancelReceipt GetInvoice GetInvoiceDetails get_rounded_p use C4::Budgets qw( GetBudget GetBudgetByOrderNumber GetBudgetName ); use CGI qw ( -utf8 ); use C4::Output qw( output_html_with_http_headers ); -use C4::Suggestions qw( GetSuggestionInfoFromBiblionumber GetSuggestionInfo ); +use C4::Suggestions qw( GetSuggestionInfo ); use Koha::Acquisition::Baskets; use Koha::Acquisition::Bookseller; @@ -150,10 +150,10 @@ for my $order (@orders) { $total_tax_excluded += get_rounded_price( $line{unitprice_tax_excluded} ) * $line{quantity}; $total_tax_included += get_rounded_price( $line{unitprice_tax_included} ) * $line{quantity}; - my $suggestion = GetSuggestionInfoFromBiblionumber( $line{biblionumber} ); - $line{suggestionid} = $suggestion->{suggestionid}; - $line{surnamesuggestedby} = $suggestion->{surnamesuggestedby}; - $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby}; + my $suggestion = Koha::Suggestions->find( { biblionumber => $line{biblionumber} } ); + $line{suggestionid} = $suggestion->suggestionid; + $line{surnamesuggestedby} = $suggestion->suggester->surname; + $line{firstnamesuggestedby} = $suggestion->suggester->firstname; if ( $line{parent_ordernumber} != $line{ordernumber} ) { if ( grep { $_->{ordernumber} == $line{parent_ordernumber} } @orders ) { diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t index d23edec56bc..98824879510 100755 --- a/t/db_dependent/Suggestions.t +++ b/t/db_dependent/Suggestions.t @@ -19,7 +19,7 @@ use Modern::Perl; use DateTime::Duration; use Test::NoWarnings; -use Test::More tests => 92; +use Test::More tests => 80; use Test::Warn; use t::lib::Mocks; @@ -38,7 +38,7 @@ use Koha::Suggestions; BEGIN { use_ok( 'C4::Suggestions', - qw( ModSuggestion GetSuggestionInfo GetSuggestionInfoFromBiblionumber GetSuggestionByStatus ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan ) + qw( ModSuggestion GetSuggestionInfo GetSuggestionByStatus ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan ) ); } @@ -335,53 +335,6 @@ is( 'GetSuggestionInfo returns the borrower number correctly' ); -is( - GetSuggestionInfoFromBiblionumber(), undef, - 'GetSuggestionInfoFromBiblionumber without the biblio number returns undef' -); -is( - GetSuggestionInfoFromBiblionumber(2), undef, - 'GetSuggestionInfoFromBiblionumber with an invalid biblio number returns undef' -); -$suggestion = GetSuggestionInfoFromBiblionumber( $biblio_1->biblionumber ); -is( - $suggestion->{suggestionid}, $my_suggestionid, - 'GetSuggestionInfoFromBiblionumber returns the suggestion id correctly' -); -is( $suggestion->{title}, $mod_suggestion1->{title}, 'GetSuggestionInfoFromBiblionumber returns the title correctly' ); -is( - $suggestion->{author}, $mod_suggestion1->{author}, - 'GetSuggestionInfoFromBiblionumber returns the author correctly' -); -is( - $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, - 'GetSuggestionInfoFromBiblionumber returns the publisher code correctly' -); -is( - $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, - 'GetSuggestionInfoFromBiblionumber returns the borrower number correctly' -); -is( - $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, - 'GetSuggestionInfoFromBiblionumber returns the biblio number correctly' -); -is( - $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, - 'GetSuggestionInfoFromBiblionumber returns the status correctly' -); -is( - $suggestion->{surnamesuggestedby}, $member->{surname}, - 'GetSuggestionInfoFromBiblionumber returns the surname correctly' -); -is( - $suggestion->{firstnamesuggestedby}, $member->{firstname}, - 'GetSuggestionInfoFromBiblionumber returns the firstname correctly' -); -is( - $suggestion->{borrnumsuggestedby}, $my_suggestion->{suggestedby}, - 'GetSuggestionInfoFromBiblionumeber returns the borrower number correctly' -); - my $suggestions = GetSuggestionByStatus(); is( @$suggestions, 0, 'GetSuggestionByStatus without the status returns an empty array' ); $suggestions = GetSuggestionByStatus('CHECKED'); -- 2.43.0