Bug 20176: [sql_modes] Set biblio.datecreated to NOW if not defined
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 5 Feb 2018 18:59:09 +0000 (15:59 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 16 Feb 2018 16:03:58 +0000 (13:03 -0300)
Fix at ->store level, this issue appears in lot of places.

Fix for:
Field 'datecreated' doesn't have a default value

Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Biblio.pm
t/db_dependent/Koha/Biblios.t

index a35048d..d226304 100644 (file)
@@ -45,6 +45,20 @@ Koha::Biblio - Koha Biblio Object class
 
 =cut
 
+=head3 store
+
+Overloaded I<store> method to set default values
+
+=cut
+
+sub store {
+    my ( $self ) = @_;
+
+    $self->datecreated( dt_from_string ) unless $self->datecreated;
+
+    return $self->SUPER::store;
+}
+
 =head3 subtitles
 
 my @subtitles = $biblio->subtitles();
index 2f807b1..5cc286e 100644 (file)
 
 use Modern::Perl;
 
-use Test::More tests => 3;
+use Test::More tests => 4;
 
 use C4::Reserves;
 
-use Koha::DateUtils qw( dt_from_string );
+use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Biblios;
 use Koha::Patrons;
 use Koha::Subscriptions;
@@ -45,6 +45,17 @@ my $biblioitem = $schema->resultset('Biblioitem')->new(
     }
 )->insert();
 
+subtest 'store' => sub {
+    plan tests => 1;
+    is(
+        Koha::Biblios->find( $biblio->biblionumber )->datecreated,
+        output_pref(
+            { dt => dt_from_string, dateformat => 'iso', dateonly => 1 }
+        ),
+        "datecreated must be set to today if not passed to the constructor"
+    );
+};
+
 subtest 'holds + current_holds' => sub {
     plan tests => 5;
     C4::Reserves::AddReserve( $patron->branchcode, $patron->borrowernumber, $biblio->biblionumber );