Bugzilla – Attachment 33244 Details for
Bug 12627
SQLHelper replacement - C4::Suggestions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12627: Fix default values
Bug-12627-Fix-default-values.patch (text/plain), 6.32 KB, created by
Jonathan Druart
on 2014-11-05 12:06:34 UTC
(
hide
)
Description:
Bug 12627: Fix default values
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-11-05 12:06:34 UTC
Size:
6.32 KB
patch
obsolete
>From 0fc4e2dce50828274556886107c8b266a34cd87f Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 30 Sep 2014 12:19:21 +0200 >Subject: [PATCH] Bug 12627: Fix default values > >The default value for *by and *date fields is NULL. >But without this patch, the values are 0 or 0000-00-00. >It comes from the fact that the form set to an empty string the values >and DBIX::Class does not consider them as undefined. > >This patch is very ugly, not sure how we can fix that. >--- > C4/Suggestions.pm | 33 +++++++++++++++++++++++++++++++++ > suggestion/suggestion.pl | 5 ++++- > t/db_dependent/Suggestions.t | 19 ++++++++++++++++--- > 3 files changed, 53 insertions(+), 4 deletions(-) > >diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm >index bbaebdc..8c9db85 100644 >--- a/C4/Suggestions.pm >+++ b/C4/Suggestions.pm >@@ -28,6 +28,8 @@ use C4::Output; > use C4::Dates qw(format_date format_date_in_iso); > use C4::Debug; > use C4::Letters; >+use Koha::DateUtils qw( dt_from_string ); >+ > use List::MoreUtils qw(any); > use C4::Dates qw(format_date_in_iso); > use base qw(Exporter); >@@ -426,8 +428,23 @@ Insert a new suggestion on database with value given on input arg. > sub NewSuggestion { > my ($suggestion) = @_; > >+ for my $field ( qw( >+ suggestedby >+ managedby >+ manageddate >+ acceptedby >+ accepteddate >+ rejectedby >+ rejecteddate >+ ) ) { >+ # Set the fields to NULL if not given. >+ $suggestion->{$field} ||= undef; >+ } >+ > $suggestion->{STATUS} = "ASKED" unless $suggestion->{STATUS}; > >+ $suggestion->{suggesteddate} = dt_from_string unless $suggestion->{suggesteddate}; >+ > my $rs = Koha::Database->new->schema->resultset('Suggestion'); > return $rs->create($suggestion)->id; > } >@@ -449,6 +466,22 @@ sub ModSuggestion { > my ($suggestion) = @_; > return unless( $suggestion and defined($suggestion->{suggestionid}) ); > >+ for my $field ( qw( >+ suggestedby >+ managedby >+ manageddate >+ acceptedby >+ accepteddate >+ rejectedby >+ rejecteddate >+ ) ) { >+ # Set the fields to NULL if not given. >+ $suggestion->{$field} = undef >+ if exists $suggestion->{$field} >+ and ($suggestion->{$field} eq '0' >+ or $suggestion->{$field} eq '' ); >+ } >+ > my $rs = Koha::Database->new->schema->resultset('Suggestion')->find($suggestion->{suggestionid}); > my $status_update_table = 1; > eval { >diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl >index 14e6ac2..b146aad 100755 >--- a/suggestion/suggestion.pl >+++ b/suggestion/suggestion.pl >@@ -115,7 +115,10 @@ $template->param('borrowernumber' => $borrowernumber); > ## Operations > ## > if ( $op =~ /save/i ) { >- if ( $suggestion_only->{"STATUS"} ) { >+ $suggestion_only->{suggesteddate} = dt_from_string( $suggestion_only->{suggesteddate} ) >+ if $suggestion_only->{suggesteddate}; >+ >+ if ( $suggestion_only->{"STATUS"} ) { > if ( my $tmpstatus = lc( $suggestion_only->{"STATUS"} ) =~ /ACCEPTED|REJECTED/i ) { > $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "date" } = dt_from_string; > $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "by" } = C4::Context->userenv->{number}; >diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t >index e3bc26c..1584301 100644 >--- a/t/db_dependent/Suggestions.t >+++ b/t/db_dependent/Suggestions.t >@@ -21,7 +21,9 @@ use C4::Context; > use C4::Members; > use C4::Letters; > >-use Test::More tests => 91; >+use Koha::DateUtils qw( dt_from_string ); >+ >+use Test::More tests => 97; > use Test::Warn; > > BEGIN { >@@ -57,6 +59,10 @@ my $my_suggestion = { > publishercode => 'my publishercode', > suggestedby => $borrowernumber, > biblionumber => $biblionumber1, >+ managedby => '', >+ manageddate => '', >+ accepteddate => dt_from_string, >+ note => 'my note', > }; > > >@@ -66,7 +72,6 @@ is( CountSuggestion('CHECKED'), 0, 'CountSuggestion returns the correct number o > is( CountSuggestion('ACCEPTED'), 0, 'CountSuggestion returns the correct number of suggestions' ); > is( CountSuggestion('REJECTED'), 0, 'CountSuggestion returns the correct number of suggestions' ); > >- > my $my_suggestionid = NewSuggestion($my_suggestion); > isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' ); > >@@ -78,7 +83,8 @@ is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'NewSuggestio > is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'NewSuggestion stores the borrower number correctly' ); > is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion stores the biblio number correctly' ); > is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' ); >- >+is( $suggestion->{managedby}, undef, 'NewSuggestion stores empty string as undef for non existent foreign key (integer)' ); >+is( $suggestion->{manageddate}, undef, 'NewSuggestion stores empty string as undef for date' ); > is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); > > >@@ -87,6 +93,8 @@ my $mod_suggestion1 = { > title => 'my modified title', > author => 'my modified author', > publishercode => 'my modified publishercode', >+ managedby => '', >+ manageddate => '', > }; > my $status = ModSuggestion($mod_suggestion1); > is( $status, undef, 'ModSuggestion without the suggestion id returns undef' ); >@@ -98,6 +106,11 @@ $suggestion = GetSuggestion($my_suggestionid); > is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title correctly' ); > is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' ); > is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'ModSuggestion modifies the publishercode correctly' ); >+is( $suggestion->{managedby}, undef, 'ModSuggestion stores empty string as undef for non existent foreign key (integer)' ); >+is( $suggestion->{manageddate}, undef, 'ModSuggestion stores empty string as undef for date' ); >+isnt( $suggestion->{accepteddate}, undef, 'ModSuggestion does not update a non given date value' ); >+is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not given' ); >+ > my $messages = C4::Letters::GetQueuedMessages({ > borrowernumber => $borrowernumber, > }); >-- >2.1.0
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 12627
:
29963
|
30095
|
30237
|
30269
|
30624
|
30635
|
30892
|
31916
|
31917
|
31937
|
31939
|
31940
|
31941
|
31942
|
31944
|
31948
|
31953
|
33244
|
33276
|
33277
|
33278
|
33279
|
33280
|
33281