From cee92b42a2eda2676f6c04efe512726dd2960422 Mon Sep 17 00:00:00 2001 From: Yohann Dufour Date: Wed, 23 Jul 2014 09:34:36 +0200 Subject: [PATCH] [SIGNED-OFF] Bug 12627: SQLHelper replacement - C4::Suggestions With this patch, the subroutines NewSuggestion and ModSuggestion uses DBIx::Class instead of C4::SQLHelper. Moreover, the tests has been adapted to the values returned by DBIx::Class. Test plan: 1) Apply the patch 12445 in order to get the last unit tests for Suggestions 2) Apply the patch 3) Execute the unit tests by launching : prove t/db_dependent/Suggestions.t 4) The result has to be a success without error or warning : t/db_dependent/Suggestions.t .. ok All tests successful. Files=1, Tests=91, 2 wallclock secs ( 0.05 usr 0.01 sys + 1.65 cusr 0.09 csys = 1.80 CPU) Result: PASS Signed-off-by: Kyle M Hall --- C4/Suggestions.pm | 21 +++++++++++++++++---- t/db_dependent/Suggestions.t | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index b543293..82475db 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -26,7 +26,6 @@ use CGI; use C4::Context; use C4::Output; use C4::Dates qw(format_date format_date_in_iso); -use C4::SQLHelper qw(:all); use C4::Debug; use C4::Letters; use List::MoreUtils qw(any); @@ -426,8 +425,14 @@ Insert a new suggestion on database with value given on input arg. sub NewSuggestion { my ($suggestion) = @_; + + my $new_suggestion = { %$suggestion }; $suggestion->{STATUS} = "ASKED" unless $suggestion->{STATUS}; - return InsertInTable( "suggestions", $suggestion ); + $new_suggestion->{status} = $suggestion->{STATUS}; + delete $new_suggestion->{STATUS}; + + my $rs = Koha::Database->new->schema->resultset('Suggestion'); + return $rs->create($new_suggestion)->id; } =head2 ModSuggestion @@ -445,9 +450,17 @@ Note that there is no function to modify a suggestion. sub ModSuggestion { my ($suggestion) = @_; - my $status_update_table = UpdateInTable( "suggestions", $suggestion ); + return unless( $suggestion and defined($suggestion->{suggestionid}) ); + + my $mod_suggestion = { %$suggestion }; + my $status = $suggestion->{STATUS}; + delete $mod_suggestion->{STATUS}; + $mod_suggestion->{status} = $status; + + my $rs = Koha::Database->new->schema->resultset('Suggestion'); + my $status_update_table = $rs->update($suggestion); - if ( $suggestion->{STATUS} ) { + if ( $status ) { # fetch the entire updated suggestion so that we can populate the letter my $full_suggestion = GetSuggestion( $suggestion->{suggestionid} ); diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t index 299bdf6..e3bc26c 100644 --- a/t/db_dependent/Suggestions.t +++ b/t/db_dependent/Suggestions.t @@ -89,7 +89,7 @@ my $mod_suggestion1 = { publishercode => 'my modified publishercode', }; my $status = ModSuggestion($mod_suggestion1); -is( $status, '0E0', 'ModSuggestion without the suggestion id returns 0E0' ); +is( $status, undef, 'ModSuggestion without the suggestion id returns undef' ); $mod_suggestion1->{suggestionid} = $my_suggestionid; $status = ModSuggestion($mod_suggestion1); -- 1.7.2.5