From c9b2b6ab18830bc4fae5debea921db015897bf8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Fri, 14 Aug 2020 07:14:15 +0000 Subject: [PATCH] Bug 20447: (follow-up) Add required metadata field when creating holdings Since metadata column is mandatory in the holdings_metadata table we need to define it already when it is first created instead of creating it first and updating the column immediately after. This fixes the following error during holdings record creation: DBIx::Class::Storage::DBI::_dbh_execute(): Field 'metadata' doesn't have a default value at /kohadevbox/koha/Koha/Objects.pm line 114 https://bugs.koha-community.org/show_bug.cgi?id=22690 --- Koha/Holding.pm | 21 ++++++--------------- Koha/Objects.pm | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Koha/Holding.pm b/Koha/Holding.pm index fc062465a8..e887e6adaf 100644 --- a/Koha/Holding.pm +++ b/Koha/Holding.pm @@ -182,29 +182,20 @@ sub store { holding_id => $self->holding_id(), format => 'marcxml', schema => $marcflavour, + metadata => $marc_record->as_xml_record($marcflavour), }; - my $metadata_record = Koha::Holdings::Metadatas->find_or_create($metadata); - $metadata_record->metadata($marc_record->as_xml_record($marcflavour)); + Koha::Holdings::Metadatas->update_or_create($metadata); + $guard->commit() if defined $guard; # request that bib be reindexed so that any holdings-derived fields are updated - unless ( $params->{skip_record_index} ){ + unless ( $params->{skip_record_index} ) { my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" ); } - if ($result) { - $guard->commit() if defined $guard; - - # request that bib be reindexed so that any holdings-derived fields are updated - unless ( $params->{skip_record_index} ) { - my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); - $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" ); - } + logaction('CATALOGUING', $action, $self->holding_id(), 'holding') if C4::Context->preference('CataloguingLog'); - logaction('CATALOGUING', $action, $self->holding_id(), 'holding') if C4::Context->preference('CataloguingLog'); - } - - return $result; + return $self; } =head3 delete diff --git a/Koha/Objects.pm b/Koha/Objects.pm index 2f16b35888..102169b643 100644 --- a/Koha/Objects.pm +++ b/Koha/Objects.pm @@ -102,6 +102,24 @@ sub find { return $object; } +=head3 Koha::Objects->update_or_create(); + +my $object = Koha::Objects->update_or_create( $attrs ); + +=cut + +sub update_or_create { + my ( $self, $params ) = @_; + + my $result = $self->_resultset->update_or_create($params); + + return unless $result; + + my $object = $self->object_class->_new_from_dbic($result); + + return $object; +} + =head3 Koha::Objects->find_or_create(); my $object = Koha::Objects->find_or_create( $attrs ); -- 2.30.0