Bug 39721: Remove GetSuggestion from C4/Suggestions.pm

1 - Create suggestion
2 - Display a suggestion
3 - Amend a suggestion
To do with and without patch

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk>

Amended-by: Jonathan Druart
tidy

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Baptiste Wojtkowski 2025-04-08 13:16:56 +02:00 committed by Lucas Gass
parent 3b149f0f50
commit 1a5bb27e8a
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
8 changed files with 21 additions and 46 deletions

View File

@ -69,7 +69,7 @@ BEGIN {
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 );

View File

@ -73,30 +73,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)
@ -267,7 +243,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} );

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -302,7 +302,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} ) {
@ -395,7 +395,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);

View File

@ -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" );
};