Bugzilla – Attachment 181402 Details for
Bug 39721
Remove GetSuggestion from C4/Suggestions.pm
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39721: Remove GetSuggestion from C4/Suggestions.pm
Bug-39721-Remove-GetSuggestion-from-C4Suggestionsp.patch (text/plain), 13.26 KB, created by
Baptiste Wojtkowski (bwoj)
on 2025-04-24 08:51:34 UTC
(
hide
)
Description:
Bug 39721: Remove GetSuggestion from C4/Suggestions.pm
Filename:
MIME Type:
Creator:
Baptiste Wojtkowski (bwoj)
Created:
2025-04-24 08:51:34 UTC
Size:
13.26 KB
patch
obsolete
>From b5f32a0702702b641829250582ad732150959ea4 Mon Sep 17 00:00:00 2001 >From: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >Date: Tue, 8 Apr 2025 13:16:56 +0200 >Subject: [PATCH] Bug 39721: Remove GetSuggestion from C4/Suggestions.pm > >This set of patches removes the major part of C4/Suggestions. They have >been split for sake of QA's readability but should be squashed. > >Things to test: >Create suggestion >Update status of suggestion >Create, see and receive an order containing a suggestion >Create a suggestion on an already existing record (it will need > validation) >test cronjobs purge_suggestion and notice_unprocessed_suggestions >--- > C4/Acquisition.pm | 2 +- > C4/Suggestions.pm | 27 +-------------------------- > acqui/basket.pl | 2 +- > acqui/neworderempty.pl | 4 ++-- > acqui/orderreceive.pl | 2 +- > acqui/parcel.pl | 2 +- > suggestion/suggestion.pl | 4 ++-- > t/db_dependent/Suggestions.t | 25 ++++++++++++------------- > 8 files changed, 21 insertions(+), 47 deletions(-) > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index a81a6b9a..bd418f84 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -21,7 +21,7 @@ use Modern::Perl; > use Carp qw( carp croak ); > use Text::CSV_XS; > use C4::Context; >-use C4::Suggestions qw( GetSuggestion GetSuggestionFromBiblionumber ModSuggestion ); >+use C4::Suggestions qw( GetSuggestionFromBiblionumber ModSuggestion ); > use C4::Biblio qw( GetMarcFromKohaField GetMarcStructure IsMarcStructureInternal ); > use C4::Contract qw( GetContract ); > use C4::Log qw( logaction ); >diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm >index 154b2e84..dc933274 100644 >--- a/C4/Suggestions.pm >+++ b/C4/Suggestions.pm >@@ -34,7 +34,6 @@ use base qw(Exporter); > our @EXPORT = qw( > ConnectSuggestionAndBiblio > DelSuggestion >- GetSuggestion > GetSuggestionByStatus > GetSuggestionFromBiblionumber > GetSuggestionInfoFromBiblionumber >@@ -71,30 +70,6 @@ Suggestions done by other borrowers can be seen when not "AVAILABLE" > > =head1 FUNCTIONS > >-=head2 GetSuggestion >- >-\%sth = &GetSuggestion($suggestionid) >- >-this function get the detail of the suggestion $suggestionid (input arg) >- >-return : >- the result of the SQL query as a hash : $sth->fetchrow_hashref. >- >-=cut >- >-sub GetSuggestion { >- my ($suggestionid) = @_; >- my $dbh = C4::Context->dbh; >- my $query = q{ >- SELECT * >- FROM suggestions >- WHERE suggestionid=? >- }; >- my $sth = $dbh->prepare($query); >- $sth->execute($suggestionid); >- return ( $sth->fetchrow_hashref ); >-} >- > =head2 GetSuggestionFromBiblionumber > > $ordernumber = &GetSuggestionFromBiblionumber($biblionumber) >@@ -265,7 +240,7 @@ sub ModSuggestion { > { > > # fetch the entire updated suggestion so that we can populate the letter >- my $full_suggestion = GetSuggestion( $suggestion->{suggestionid} ); >+ my $full_suggestion = Koha::Suggestions->find( $suggestion->{suggestionid} )->unblessed(); > > my $patron = Koha::Patrons->find( $full_suggestion->{suggestedby} ); > >diff --git a/acqui/basket.pl b/acqui/basket.pl >index ab194704..fad4152c 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( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo ); >+use C4::Suggestions qw( GetSuggestionInfoFromBiblionumber GetSuggestionInfo ); > use Koha::Biblios; > use Koha::Acquisition::Baskets; > use Koha::Acquisition::Booksellers; >diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl >index 4228db94..75bc59cf 100755 >--- a/acqui/neworderempty.pl >+++ b/acqui/neworderempty.pl >@@ -72,7 +72,7 @@ use C4::Budgets qw( GetBudget GetBudgetHierarchy CanUserUseBudget ); > > use C4::Acquisition qw( GetOrder GetBasket FillWithDefaultValues GetOrderUsers ); > use C4::Contract qw( GetContract ); >-use C4::Suggestions qw( GetSuggestion GetSuggestionInfo ); >+use C4::Suggestions qw( GetSuggestionInfo ); > use C4::Biblio qw( > AddBiblio > GetBiblioData >@@ -209,7 +209,7 @@ if ( not $ordernumber ) { # create order > # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists > # otherwise, retrieve suggestion information. > elsif ($suggestionid) { >- $data = GetSuggestion($suggestionid); >+ $data = Koha::Suggestions->find($suggestionid)->unblessed(); > $data->{quantitysugg} = $data->{quantity}; > undef $data->{quantity}; > $budget_id ||= $data->{'budgetid'} // 0; >diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl >index 06564c73..1874eb7e 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( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo ); >+use C4::Suggestions qw( GetSuggestionInfoFromBiblionumber GetSuggestionInfo ); > > use Koha::Acquisition::Booksellers; > use Koha::Acquisition::Currencies qw( get_active ); >diff --git a/acqui/parcel.pl b/acqui/parcel.pl >index 01e4e9ce..a53aba06 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( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo ); >+use C4::Suggestions qw( GetSuggestionInfoFromBiblionumber GetSuggestionInfo ); > > use Koha::Acquisition::Baskets; > use Koha::Acquisition::Bookseller; >diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl >index 362cac0a..84d5dcf6 100755 >--- a/suggestion/suggestion.pl >+++ b/suggestion/suggestion.pl >@@ -290,7 +290,7 @@ if ( $op =~ /cud-save/ ) { > } elsif ( $op eq 'edit_form' ) { > > #Edit suggestion >- $suggestion_ref = &GetSuggestion( $$suggestion_ref{'suggestionid'} ); >+ $suggestion_ref = Koha::Suggestions->find( $suggestion_ref->{suggestionid} )->unblessed(); > $suggestion_ref->{reasonsloop} = $reasonsloop; > my $other_reason = 1; > foreach my $reason ( @{$reasonsloop} ) { >@@ -383,7 +383,7 @@ if ( $op =~ /cud-save/ ) { > $template->param( messages => \@messages, ); > } > } elsif ( $op eq 'show' ) { >- $suggestion_ref = &GetSuggestion( $$suggestion_ref{'suggestionid'} ); >+ $suggestion_ref = Koha::Suggestions->find( $suggestion_ref->{suggestionid} )->unblessed(); > my $budget = GetBudget $$suggestion_ref{budgetid}; > $$suggestion_ref{budgetname} = $$budget{budget_name}; > Init($suggestion_ref); >diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t >index d7d289f7..87c3f6df 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 => 96; >+use Test::More tests => 95; > use Test::Warn; > > use t::lib::Mocks; >@@ -38,7 +38,7 @@ use Koha::Suggestions; > BEGIN { > use_ok( > 'C4::Suggestions', >- qw( GetSuggestion ModSuggestion GetSuggestionInfo GetSuggestionFromBiblionumber GetSuggestionInfoFromBiblionumber GetSuggestionByStatus ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan ) >+ qw( ModSuggestion GetSuggestionInfo GetSuggestionFromBiblionumber GetSuggestionInfoFromBiblionumber GetSuggestionByStatus ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan ) > ); > } > >@@ -177,8 +177,7 @@ isnt( $my_suggestionid, 0, 'Suggestion is correctly saved' ); > my $my_suggestion_with_budget_object = Koha::Suggestion->new($my_suggestion_with_budget)->store; > my $my_suggestionid_with_budget = $my_suggestion_with_budget_object->id; > >-is( GetSuggestion(), undef, 'GetSuggestion without the suggestion id returns undef' ); >-my $suggestion = GetSuggestion($my_suggestionid); >+my $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); > is( $suggestion->{title}, $my_suggestion->{title}, 'Suggestion stores the title correctly' ); > is( $suggestion->{author}, $my_suggestion->{author}, 'Suggestion stores the author correctly' ); > is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'Suggestion stores the publishercode correctly' ); >@@ -203,7 +202,7 @@ is( $status, undef, 'ModSuggestion without the suggestion id returns undef' ); > $mod_suggestion1->{suggestionid} = $my_suggestionid; > $status = ModSuggestion($mod_suggestion1); > is( $status, 1, 'ModSuggestion modifies one entry' ); >-$suggestion = GetSuggestion($my_suggestionid); >+$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); > is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title correctly' ); > is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' ); > is( >@@ -247,7 +246,7 @@ my $mod_suggestion3 = { > t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 0 ); > $status = ModSuggestion($mod_suggestion3); > is( $status, 1, 'ModSuggestion modifies one entry' ); >-$suggestion = GetSuggestion($my_suggestionid); >+$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); > is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' ); > $messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } ); > is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); >@@ -438,7 +437,7 @@ is( ConnectSuggestionAndBiblio(), '0E0', 'ConnectSuggestionAndBiblio without arg > my $biblio_2 = $builder->build_object( { class => 'Koha::Biblios' } ); > my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio( $my_suggestionid, $biblio_2->biblionumber ); > is( $connect_suggestion_and_biblio, '1', 'ConnectSuggestionAndBiblio returns 1' ); >-$suggestion = GetSuggestion($my_suggestionid); >+$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); > is( > $suggestion->{biblionumber}, $biblio_2->biblionumber, > 'ConnectSuggestionAndBiblio updates the biblio number correctly' >@@ -469,12 +468,12 @@ is( $suggestions->[1]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes > $my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB > my $my_suggestionid_test_budget_object = Koha::Suggestion->new($my_suggestion)->store; > my $my_suggestionid_test_budgetid = $my_suggestionid_test_budget_object->id; >-$suggestion = GetSuggestion($my_suggestionid_test_budgetid); >+$suggestion = Koha::Suggestions->find($my_suggestionid_test_budgetid)->unblessed(); > is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' ); > > $my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB > ModSuggestion($my_suggestion); >-$suggestion = GetSuggestion($my_suggestionid_test_budgetid); >+$suggestion = Koha::Suggestions->find($my_suggestionid_test_budgetid)->unblessed(); > is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' ); > > my $suggestion2 = { >@@ -511,10 +510,10 @@ subtest 'GetUnprocessedSuggestions' => sub { > 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' > ); > my $status = ModSuggestion($mod_suggestion1); >- my $suggestion = GetSuggestion($my_suggestionid); >+ my $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); > is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' ); > ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } ); >- $suggestion = GetSuggestion($my_suggestionid); >+ $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); > is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' ); > > $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; >@@ -734,7 +733,7 @@ subtest 'ModSuggestion should work on suggestions without a suggester' => sub { > > $dbh->do(q|DELETE FROM suggestions|); > my $my_suggestionid = Koha::Suggestion->new($my_suggestion_without_suggestedby)->store()->id; >- $suggestion = GetSuggestion($my_suggestionid); >+ $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); > is( $suggestion->{suggestedby}, undef, "Suggestedby is undef" ); > > ModSuggestion( >@@ -744,7 +743,7 @@ subtest 'ModSuggestion should work on suggestions without a suggester' => sub { > note => "Test note" > } > ); >- $suggestion = GetSuggestion($my_suggestionid); >+ $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); > > is( $suggestion->{note}, "Test note", "ModSuggestion works on suggestions without a suggester" ); > }; >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39721
:
181402
|
181416