Bug 21610: Improve default values for dates
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 19 Oct 2018 11:22:20 +0000 (08:22 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 4 Feb 2019 11:13:50 +0000 (11:13 +0000)
This patch fixes failures on t/db_dependent/Koha/Patrons/Import.t
and keep t/Auth_with_shibboleth.t and t/db_dependent/Koha/Object.t green

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 766eaa0df45f04523737a8f04b045122b3e11b18)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/Object.pm

index 7ef2296..1c382f2 100644 (file)
@@ -141,9 +141,13 @@ sub store {
         }
         elsif ( _date_or_datetime_column_type( $columns_info->{$col}->{data_type} ) ) {
             # Set to null if an empty string (or == 0 but should not happen)
-            # Skip a default value for dates LIKE CURRENT_TIMESTAMP
-            # In DBIx represented as: default_value => \'now()'
-            $self->$col(undef) unless $self->$col || $columns_info->{$col}->{default_value};
+            if ( defined $self->$col and not $self->$col ) {
+                if ( $columns_info->{$col}->{is_nullable} ) {
+                    $self->$col(undef);
+                } else {
+                    $self->$col($columns_info->{$col}->{default_value});
+                }
+            }
         }
     }