From 107e8db720c8cae0e5b291980aa7c339c950c070 Mon Sep 17 00:00:00 2001 From: Jonathan Druart 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 | 30 ++++++++++++++++++++++++++++++ suggestion/suggestion.pl | 5 ++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index eae80a0..9226cea 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -428,6 +428,21 @@ sub NewSuggestion { $suggestion->{STATUS} = "ASKED" unless $suggestion->{STATUS}; + for my $field ( qw( + suggestedby + suggesteddate + managedby + manageddate + acceptedby + accepteddate + rejectedby + rejecteddate + ) ) { + # Set the fields to NULL if not given. + # Be careful, the following should *not* be //= + $suggestion->{$field} ||= undef; + } + my $rs = Koha::Database->new->schema->resultset('Suggestion'); return $rs->create($suggestion)->id; } @@ -456,6 +471,21 @@ sub ModSuggestion { }; $status_update_table = 0 if( $@ ); + for my $field ( qw( + suggestedby + suggesteddate + managedby + manageddate + acceptedby + accepteddate + rejectedby + rejecteddate + ) ) { + # Set the fields to NULL if not given. + # Be careful, the following should *not* be //= + $suggestion->{$field} ||= undef; + } + if ( $suggestion->{STATUS} ) { # fetch the entire updated suggestion so that we can populate the letter diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index 14c90bd..f45d294 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -124,7 +124,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}; -- 2.1.0