From 4e9746946c69cae835b44a287258e7c2cf756b26 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Tue, 19 May 2020 11:59:59 +0200 Subject: [PATCH] Bug 25539: Remove AddBiblio option "defer_marc_save" Items are no longer embedded in the MARCXML and because of this the MARC data does not need to be saved once more after changing record items data. The "defer_marc_save" is no longer needed since bulkmarcimport.pl was the only place this option was utilized in order to resave MARC data after possibly changing items data. --- C4/Biblio.pm | 21 +++++---------------- C4/Items.pm | 3 --- misc/migration_tools/bulkmarcimport.pl | 21 ++++++--------------- 3 files changed, 11 insertions(+), 34 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 9eb3696a54..6c610fcb09 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -181,15 +181,7 @@ bib to add, while the second argument is the desired MARC framework code. This function also accepts a third, optional argument: a hashref -to additional options. The only defined option is C, -which if present and mapped to a true value, causes C -to omit the call to save the MARC in C -This option is provided B -for the use of scripts such as C that may need -to do some manipulation of the MARC record for item parsing before -saving it and which cannot afford the performance hit of saving -the MARC record twice. Consequently, do not use that option -unless you can guarantee that C will be called. +to additional options. =cut @@ -197,14 +189,10 @@ sub AddBiblio { my $record = shift; my $frameworkcode = shift; my $options = @_ ? shift : undef; - my $defer_marc_save = 0; if (!$record) { carp('AddBiblio called with undefined record'); return; } - if ( defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'} ) { - $defer_marc_save = 1; - } if (C4::Context->preference('BiblioAddsAuthorities')) { BiblioAutoLink( $record, $frameworkcode ); @@ -225,8 +213,9 @@ sub AddBiblio { # update MARC subfield that stores biblioitems.cn_sort _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode ); + # now add the record - ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save; + ModBiblioMarc( $record, $biblionumber, $frameworkcode ); # update OAI-PMH sets if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) { @@ -273,8 +262,8 @@ sub ModBiblio { } if ( C4::Context->preference("CataloguingLog") ) { - my $newrecord = GetMarcBiblio({ biblionumber => $biblionumber }); - logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $newrecord->as_formatted ); + my $oldrecord = GetMarcBiblio({ biblionumber => $biblionumber }); + logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $oldrecord->as_formatted ); } if ( !$disable_autolink && C4::Context->preference('BiblioAddsAuthorities') ) { diff --git a/C4/Items.pm b/C4/Items.pm index a162ac5dec..aefacc6a31 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -276,9 +276,6 @@ sub AddItemBatchFromMarc { $record->delete_field($item_field); } - # update the MARC biblio - # $biblionumber = ModBiblioMarc( $record, $biblionumber, $frameworkcode ); - return (\@itemnumbers, \@errors); } diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index 6ab4b3fcf4..cdb5fc33c0 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -286,7 +286,7 @@ RECORD: while ( ) { ($record, $guessed_charset, $charset_errors) = MarcToUTF8Record($record, $marcFlavour.(($authorities and $marcFlavour ne "MARC21")?'AUTH':'')); if ($guessed_charset eq 'failed') { warn "ERROR: failed to perform character conversion for record $i\n"; - next RECORD; + next RECORD; } } SetUTF8Flag($record); @@ -322,6 +322,7 @@ RECORD: while ( ) { printlog( { id => $id || $originalid || $match, op => "match", status => "ERROR" } ) if ($logfile); next RECORD; } + $debug && warn "$query $server : $totalhits"; if ( $results && scalar(@$results) == 1 ) { my $marcrecord = C4::Search::new_record_from_zebra( $server, $results->[0] ); @@ -395,7 +396,7 @@ RECORD: while ( ) { else{ printlog({id=>$originalid||$id||$authid, op=>"edit",status=>"ok"}) if ($logfile); } - } + } elsif (defined $authid) { ## An authid is defined but no authority in database : add eval { ( $authid ) = AddAuthority($record,$authid, $authtypecode) }; @@ -467,7 +468,7 @@ RECORD: while ( ) { } } else { if ($insert) { - eval { ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '', { defer_marc_save => 1 } ) }; + eval { ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '') }; if ($@) { warn "ERROR: Adding biblio $biblionumber failed: $@\n"; printlog( { id => $id || $originalid || $biblionumber, op => "insert", status => "ERROR" } ) if ($logfile); @@ -483,17 +484,10 @@ RECORD: while ( ) { } eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); }; my $error_adding = $@; - # Work on a clone so that if there are real errors, we can maybe - # fix them up later. - my $clone_record = $record->clone(); - C4::Biblio::_strip_item_fields($clone_record, ''); - # This sets the marc fields if there was an error, and also calls - # defer_marc_save. - ModBiblioMarc( $clone_record, $biblionumber, $framework ); if ( $error_adding ) { warn "ERROR: Adding items to bib $biblionumber failed: $error_adding"; printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile); - # if we failed because of an exception, assume that + # if we failed because of an exception, assume that # the MARC columns in biblioitems were not set. next RECORD; } @@ -533,9 +527,6 @@ RECORD: while ( ) { if ( $@ ) { warn "ERROR: Adding items to bib $biblionumber failed: $@\n"; printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile); - # if we failed because of an exception, assume that - # the MARC columns in biblioitems were not set. - ModBiblioMarc( $record, $biblionumber, $framework ); next RECORD; } else { printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ok"}) if ($logfile); @@ -584,7 +575,7 @@ sub GetRecordId{ my $id; if ($tag lt "010"){ return $marcrecord->field($tag)->data() if $marcrecord->field($tag); - } + } elsif ($subfield){ if ($marcrecord->field($tag)){ return $marcrecord->subfield($tag,$subfield); -- 2.20.1