From b5c7abd52ed83c5a21e73e0f9b924424d7ce1774 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 20 Mar 2024 11:34:20 -0300 Subject: [PATCH] Bug 31791: (follow-up) Tidy AddBiblio Signed-off-by: Tomas Cohen Arazi --- C4/Biblio.pm | 178 ++++++++++++++++++++++++++------------------------- 1 file changed, 91 insertions(+), 87 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 5a0b665547e..f4b9d645cee 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -212,7 +212,7 @@ sub AddBiblio { my $skip_record_index = $options->{'skip_record_index'} // 0; my $disable_autolink = $options->{disable_autolink} // 0; - if (!$record) { + if ( !$record ) { carp('AddBiblio called with undefined record'); return; } @@ -220,102 +220,106 @@ sub AddBiblio { my $schema = Koha::Database->schema; my ( $biblionumber, $biblioitemnumber ); try { - $schema->txn_do(sub { - - # transform the data into koha-table style data - SetUTF8Flag($record); - my $olddata = TransformMarcToKoha({ record => $record, limit_table => 'no_items' }); - - my $biblio = Koha::Biblio->new( - { - frameworkcode => $frameworkcode, - author => $olddata->{author}, - title => $olddata->{title}, - subtitle => $olddata->{subtitle}, - medium => $olddata->{medium}, - part_number => $olddata->{part_number}, - part_name => $olddata->{part_name}, - unititle => $olddata->{unititle}, - notes => $olddata->{notes}, - serial => $olddata->{serial}, - seriestitle => $olddata->{seriestitle}, - copyrightdate => $olddata->{copyrightdate}, - datecreated => \'NOW()', - abstract => $olddata->{abstract}, - } - )->store; - $biblionumber = $biblio->biblionumber; - Koha::Exceptions::ObjectNotCreated->throw unless $biblio; - - my ($cn_sort) = GetClassSort( $olddata->{'biblioitems.cn_source'}, $olddata->{'cn_class'}, $olddata->{'cn_item'} ); - my $biblioitem = Koha::Biblioitem->new( - { - biblionumber => $biblionumber, - volume => $olddata->{volume}, - number => $olddata->{number}, - itemtype => $olddata->{itemtype}, - isbn => $olddata->{isbn}, - issn => $olddata->{issn}, - publicationyear => $olddata->{publicationyear}, - publishercode => $olddata->{publishercode}, - volumedate => $olddata->{volumedate}, - volumedesc => $olddata->{volumedesc}, - collectiontitle => $olddata->{collectiontitle}, - collectionissn => $olddata->{collectionissn}, - collectionvolume => $olddata->{collectionvolume}, - editionstatement => $olddata->{editionstatement}, - editionresponsibility => $olddata->{editionresponsibility}, - illus => $olddata->{illus}, - pages => $olddata->{pages}, - notes => $olddata->{bnotes}, - size => $olddata->{size}, - place => $olddata->{place}, - lccn => $olddata->{lccn}, - url => $olddata->{url}, - cn_source => $olddata->{'biblioitems.cn_source'}, - cn_class => $olddata->{cn_class}, - cn_item => $olddata->{cn_item}, - cn_suffix => $olddata->{cn_suff}, - cn_sort => $cn_sort, - totalissues => $olddata->{totalissues}, - ean => $olddata->{ean}, - agerestriction => $olddata->{agerestriction}, - } - )->store; - Koha::Exceptions::ObjectNotCreated->throw unless $biblioitem; - $biblioitemnumber = $biblioitem->biblioitemnumber; + $schema->txn_do( + sub { + + # transform the data into koha-table style data + SetUTF8Flag($record); + my $olddata = TransformMarcToKoha( { record => $record, limit_table => 'no_items' } ); - _koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, $biblioitemnumber ); + my $biblio = Koha::Biblio->new( + { + frameworkcode => $frameworkcode, + author => $olddata->{author}, + title => $olddata->{title}, + subtitle => $olddata->{subtitle}, + medium => $olddata->{medium}, + part_number => $olddata->{part_number}, + part_name => $olddata->{part_name}, + unititle => $olddata->{unititle}, + notes => $olddata->{notes}, + serial => $olddata->{serial}, + seriestitle => $olddata->{seriestitle}, + copyrightdate => $olddata->{copyrightdate}, + datecreated => \'NOW()', + abstract => $olddata->{abstract}, + } + )->store; + $biblionumber = $biblio->biblionumber; + Koha::Exceptions::ObjectNotCreated->throw unless $biblio; - # update MARC subfield that stores biblioitems.cn_sort - _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode ); + my ($cn_sort) = + GetClassSort( $olddata->{'biblioitems.cn_source'}, $olddata->{'cn_class'}, $olddata->{'cn_item'} ); + my $biblioitem = Koha::Biblioitem->new( + { + biblionumber => $biblionumber, + volume => $olddata->{volume}, + number => $olddata->{number}, + itemtype => $olddata->{itemtype}, + isbn => $olddata->{isbn}, + issn => $olddata->{issn}, + publicationyear => $olddata->{publicationyear}, + publishercode => $olddata->{publishercode}, + volumedate => $olddata->{volumedate}, + volumedesc => $olddata->{volumedesc}, + collectiontitle => $olddata->{collectiontitle}, + collectionissn => $olddata->{collectionissn}, + collectionvolume => $olddata->{collectionvolume}, + editionstatement => $olddata->{editionstatement}, + editionresponsibility => $olddata->{editionresponsibility}, + illus => $olddata->{illus}, + pages => $olddata->{pages}, + notes => $olddata->{bnotes}, + size => $olddata->{size}, + place => $olddata->{place}, + lccn => $olddata->{lccn}, + url => $olddata->{url}, + cn_source => $olddata->{'biblioitems.cn_source'}, + cn_class => $olddata->{cn_class}, + cn_item => $olddata->{cn_item}, + cn_suffix => $olddata->{cn_suff}, + cn_sort => $cn_sort, + totalissues => $olddata->{totalissues}, + ean => $olddata->{ean}, + agerestriction => $olddata->{agerestriction}, + } + )->store; + Koha::Exceptions::ObjectNotCreated->throw unless $biblioitem; + $biblioitemnumber = $biblioitem->biblioitemnumber; - if (!$disable_autolink && C4::Context->preference('AutoLinkBiblios')) { - BiblioAutoLink( $record, $frameworkcode ); - } + _koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, $biblioitemnumber ); - # now add the record, don't index while we are in the transaction though - ModBiblioMarc( - $record, $biblionumber, - { - skip_record_index => 1, - record_source_id => $options->{record_source_id}, + # update MARC subfield that stores biblioitems.cn_sort + _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode ); + + if ( !$disable_autolink && C4::Context->preference('AutoLinkBiblios') ) { + BiblioAutoLink( $record, $frameworkcode ); } - ); - # update OAI-PMH sets - if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) { - C4::OAI::Sets::UpdateOAISetsBiblio($biblionumber, $record); - } + # now add the record, don't index while we are in the transaction though + ModBiblioMarc( + $record, $biblionumber, + { + skip_record_index => 1, + record_source_id => $options->{record_source_id}, + } + ); - _after_biblio_action_hooks({ action => 'create', biblio_id => $biblionumber }); + # update OAI-PMH sets + if ( C4::Context->preference("OAI-PMH:AutoUpdateSets") ) { + C4::OAI::Sets::UpdateOAISetsBiblio( $biblionumber, $record ); + } + + _after_biblio_action_hooks( { action => 'create', biblio_id => $biblionumber } ); + + logaction( "CATALOGUING", "ADD", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog"); - logaction( "CATALOGUING", "ADD", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog"); + } + ); - }); # We index now, after the transaction is committed - unless ( $skip_record_index ) { - my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); + unless ($skip_record_index) { + my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" ); } } catch { -- 2.44.0