Bug 20176

Summary: Set biblio.datecreated to NOW if not defined
Product: Koha Reporter: Julian Maurice <julian.maurice>
Component: Test SuiteAssignee: Jonathan Druart <jonathan.druart>
Status: CLOSED FIXED QA Contact: Julian Maurice <julian.maurice>
Severity: normal    
Priority: P5 - low    
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20144
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on:    
Bug Blocks: 17258    
Attachments: Bug 20176: [sql_modes] Set biblio.datecreated to NOW if not defined
Bug 20176: [sql_modes] Set biblio.datecreated to NOW if not defined
Bug 20176: [sql_modes] Set biblio.datecreated to NOW if not defined
Bug 20176: [sql_modes] Set biblio.datecreated to NOW if not defined

Description Julian Maurice 2018-02-12 13:33:24 UTC
This bug is a continuation of bug 20144
Comment 1 Julian Maurice 2018-02-12 13:34:44 UTC
Created attachment 71466 [details] [review]
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 <josef.moravec@gmail.com>
Comment 2 Julian Maurice 2018-02-12 13:38:10 UTC
There are other places where the default values are enforced in 'store' subroutine (Koha::Patron::Category for example). Why does this patch enforce a default value in 'new' subroutine ?
Comment 3 Jonathan Druart 2018-02-14 17:37:58 UTC
(In reply to Julian Maurice from comment #2)
> There are other places where the default values are enforced in 'store'
> subroutine (Koha::Patron::Category for example). Why does this patch enforce
> a default value in 'new' subroutine ?

There is no default value defined at DB level (and cannot) so ->new will explode:
DBIx::Class::Storage::DBI::_dbh_execute(): Field 'datecreated' doesn't have a default value at /home/vagrant/kohaclone/Koha/Object.pm line 124
Comment 4 Julian Maurice 2018-02-15 08:05:00 UTC
/home/vagrant/kohaclone/Koha/Object.pm line 124 is in "store" subroutine, so it is "store" that explodes, not "new", which is why I ask: why not override "store" to set default values (like it is done in others "Koha::Object"s) ?

$ perl -MKoha::Biblio -E 'Koha::Biblio->new'
# No errors

$ perl -MKoha::Biblio -E 'Koha::Biblio->new->store'
DBD::mysql::st execute failed: Field 'datecreated' doesn't have a default value [for Statement "INSERT INTO `biblio` () VALUES ()"] at /usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1836.
DBIx::Class::Storage::DBI::_dbh_execute(): Field 'datecreated' doesn't have a default value at /home/koha/koha/Koha/Object.pm line 124
Comment 5 Jonathan Druart 2018-02-16 14:26:13 UTC
Created attachment 71778 [details] [review]
Bug 20176: [sql_modes] Set biblio.datecreated to NOW if not defined

Fix at ->store level, this issue appears in lot of places.

Fix for:
Field 'datecreated' doesn't have a default value
Comment 6 Jonathan Druart 2018-02-16 14:27:12 UTC
Yes sorry Julian, I have just re-read the commit I wrote locally yesterday to test and it did not make any senses.
Comment 7 Julian Maurice 2018-02-16 14:47:31 UTC
Created attachment 71814 [details] [review]
Bug 20176: [sql_modes] Set biblio.datecreated to NOW if not defined

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>
Comment 8 Nick Clemens (kidclamp) 2018-02-16 15:25:54 UTC
Created attachment 71818 [details] [review]
Bug 20176: [sql_modes] Set biblio.datecreated to NOW if not defined

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>
Comment 9 Jonathan Druart 2018-02-16 17:07:00 UTC
Pushed to master for 18.05, thanks to everybody involved!