From ad1e22374e329f6f3b137a423d04b52134584929 Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Thu, 10 Apr 2025 15:29:51 +0200 Subject: [PATCH] Bug 39728: Remove GetUnprocessedSuggestions from C4/Suggestions.pm To test: Test notice_unprocessed_suggestions.pl --- C4/Suggestions.pm | 20 ------ .../notice_unprocessed_suggestions.pl | 13 +++- t/db_dependent/Suggestions.t | 64 +------------------ 3 files changed, 13 insertions(+), 84 deletions(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index e7f9abfc..cdd8d285 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -35,7 +35,6 @@ our @EXPORT = qw( DelSuggestion ModStatus ModSuggestion - GetUnprocessedSuggestions MarcRecordFromNewSuggestion ); @@ -173,25 +172,6 @@ sub DelSuggestion { } } -sub GetUnprocessedSuggestions { - my ($number_of_days_since_the_last_modification) = @_; - - $number_of_days_since_the_last_modification ||= 0; - - my $dbh = C4::Context->dbh; - - my $s = $dbh->selectall_arrayref( - q| - SELECT * - FROM suggestions - WHERE STATUS = 'ASKED' - AND budgetid IS NOT NULL - AND CAST(NOW() AS DATE) - INTERVAL ? DAY = CAST(suggesteddate AS DATE) - |, { Slice => {} }, $number_of_days_since_the_last_modification - ); - return $s; -} - =head2 MarcRecordFromNewSuggestion $record = MarcRecordFromNewSuggestion ( $suggestion ) diff --git a/misc/cronjobs/notice_unprocessed_suggestions.pl b/misc/cronjobs/notice_unprocessed_suggestions.pl index cad5fa0f..f7a794cc 100755 --- a/misc/cronjobs/notice_unprocessed_suggestions.pl +++ b/misc/cronjobs/notice_unprocessed_suggestions.pl @@ -37,8 +37,17 @@ unless ($confirm) { for my $number_of_days (@days) { say "Searching suggestions suggested $number_of_days days ago" if $verbose; - my $suggestions = C4::Suggestions::GetUnprocessedSuggestions($number_of_days); - + my $suggestions = Koha::Suggestions->search( + { + STATUS => 'ASKED', + budgetid => { '!=' => undef } + } + )->filter_by_last_update( + { + exact_days => $number_of_days, + timestamp_column_name => 'suggesteddate', + } + )->as_list; say "No suggestion found" if $verbose and not @$suggestions; for my $suggestion (@$suggestions) { diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t index 79be3836..03d6f168 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 => 51; +use Test::More tests => 50; use Test::Warn; use t::lib::Mocks; @@ -38,7 +38,7 @@ use Koha::Suggestions; BEGIN { use_ok( 'C4::Suggestions', - qw( ModSuggestion DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions ) + qw( ModSuggestion DelSuggestion MarcRecordFromNewSuggestion ) ); } @@ -369,66 +369,6 @@ is( "Record from suggestion author should be 'Catherine'" ); -subtest 'GetUnprocessedSuggestions' => sub { - plan tests => 11; - $dbh->do(q|DELETE FROM suggestions|); - my $my_suggestionid = Koha::Suggestion->new($my_suggestion)->store->id; - my $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; - is( - scalar(@$unprocessed_suggestions), 0, - 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' - ); - my $status = ModSuggestion($mod_suggestion1); - 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 = Koha::Suggestions->find($my_suggestionid)->unblessed(); - is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' ); - - $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; - is( - scalar(@$unprocessed_suggestions), 1, - 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' - ); - - warning_is { ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } ) } - 'No suggestions REJECTED letter transported by email', - 'Warning raised if no REJECTED letter by email'; - $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; - is( - scalar(@$unprocessed_suggestions), 0, - 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' - ); - - warning_is { - ModSuggestion( - { - suggestionid => $my_suggestionid, STATUS => 'ASKED', - suggesteddate => dt_from_string->add_duration( DateTime::Duration->new( days => -4 ) ) - } - ); - } - 'No suggestions ASKED letter transported by email', - 'Warning raised if no ASKED letter by email'; - $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; - is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' ); - $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4); - is( - scalar(@$unprocessed_suggestions), 1, - 'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago' - ); - $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3); - is( - scalar(@$unprocessed_suggestions), 0, - 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago' - ); - $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5); - is( - scalar(@$unprocessed_suggestions), 0, - 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' - ); -}; - subtest 'EmailPurchaseSuggestions' => sub { plan tests => 11; -- 2.30.2