From 707e971d6eb8803711b22a0f55353d37260b5481 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 5 Feb 2018 15:59:09 -0300 Subject: [PATCH] Bug 20176: [sql_modes] Set biblio.datecreated to NOW if not defined Fix at constructor level, this issue appears in lot of places. Fix for: Field 'datecreated' doesn't have a default value Signed-off-by: Josef Moravec --- Koha/Biblio.pm | 13 +++++++++++++ t/db_dependent/Koha/Biblios.t | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index f4e5e2f9e2..4a587a8538 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -45,6 +45,19 @@ Koha::Biblio - Koha Biblio Object class =cut +=head3 new + +Overloaded I method to set default values + +=cut + +sub new { + my ( $class, $params ) = @_; + + $params->{datecreated} ||= dt_from_string; + return $class->SUPER::new($params); +} + =head3 subtitles my @subtitles = $biblio->subtitles(); diff --git a/t/db_dependent/Koha/Biblios.t b/t/db_dependent/Koha/Biblios.t index 9f6a14a872..9cb481be7a 100644 --- a/t/db_dependent/Koha/Biblios.t +++ b/t/db_dependent/Koha/Biblios.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use C4::Reserves; @@ -45,6 +45,11 @@ my $biblioitem = $schema->resultset('Biblioitem')->new( } )->insert(); +subtest 'new' => sub { + plan tests => 1; + is( $biblio->datecreated, dt_from_string, "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 ); -- 2.14.2