View | Details | Raw Unified | Return to bug 25539
Collapse All | Expand All

(-)a/C4/Biblio.pm (-16 / +5 lines)
Lines 181-195 bib to add, while the second argument is the desired MARC Link Here
181
framework code.
181
framework code.
182
182
183
This function also accepts a third, optional argument: a hashref
183
This function also accepts a third, optional argument: a hashref
184
to additional options.  The only defined option is C<defer_marc_save>,
184
to additional options.
185
which if present and mapped to a true value, causes C<AddBiblio>
186
to omit the call to save the MARC in C<biblio_metadata.metadata>
187
This option is provided B<only>
188
for the use of scripts such as C<bulkmarcimport.pl> that may need
189
to do some manipulation of the MARC record for item parsing before
190
saving it and which cannot afford the performance hit of saving
191
the MARC record twice.  Consequently, do not use that option
192
unless you can guarantee that C<ModBiblioMarc> will be called.
193
185
194
=cut
186
=cut
195
187
Lines 197-210 sub AddBiblio { Link Here
197
    my $record          = shift;
189
    my $record          = shift;
198
    my $frameworkcode   = shift;
190
    my $frameworkcode   = shift;
199
    my $options         = @_ ? shift : undef;
191
    my $options         = @_ ? shift : undef;
200
    my $defer_marc_save = 0;
201
    if (!$record) {
192
    if (!$record) {
202
        carp('AddBiblio called with undefined record');
193
        carp('AddBiblio called with undefined record');
203
        return;
194
        return;
204
    }
195
    }
205
    if ( defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'} ) {
206
        $defer_marc_save = 1;
207
    }
208
196
209
    if (C4::Context->preference('BiblioAddsAuthorities')) {
197
    if (C4::Context->preference('BiblioAddsAuthorities')) {
210
        BiblioAutoLink( $record, $frameworkcode );
198
        BiblioAutoLink( $record, $frameworkcode );
Lines 225-232 sub AddBiblio { Link Here
225
    # update MARC subfield that stores biblioitems.cn_sort
213
    # update MARC subfield that stores biblioitems.cn_sort
226
    _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
214
    _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
227
215
216
228
    # now add the record
217
    # now add the record
229
    ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save;
218
    ModBiblioMarc( $record, $biblionumber, $frameworkcode );
230
219
231
    # update OAI-PMH sets
220
    # update OAI-PMH sets
232
    if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
221
    if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
Lines 273-280 sub ModBiblio { Link Here
273
    }
262
    }
274
263
275
    if ( C4::Context->preference("CataloguingLog") ) {
264
    if ( C4::Context->preference("CataloguingLog") ) {
276
        my $newrecord = GetMarcBiblio({ biblionumber => $biblionumber });
265
        my $oldrecord = GetMarcBiblio({ biblionumber => $biblionumber });
277
        logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $newrecord->as_formatted );
266
        logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $oldrecord->as_formatted );
278
    }
267
    }
279
268
280
    if ( !$disable_autolink && C4::Context->preference('BiblioAddsAuthorities') ) {
269
    if ( !$disable_autolink && C4::Context->preference('BiblioAddsAuthorities') ) {
(-)a/C4/Items.pm (-3 lines)
Lines 276-284 sub AddItemBatchFromMarc { Link Here
276
        $record->delete_field($item_field);
276
        $record->delete_field($item_field);
277
    }
277
    }
278
278
279
    # update the MARC biblio
280
 #   $biblionumber = ModBiblioMarc( $record, $biblionumber, $frameworkcode );
281
282
    return (\@itemnumbers, \@errors);
279
    return (\@itemnumbers, \@errors);
283
}
280
}
284
281
(-)a/misc/migration_tools/bulkmarcimport.pl (-16 / +6 lines)
Lines 286-292 RECORD: while ( ) { Link Here
286
         ($record, $guessed_charset, $charset_errors) = MarcToUTF8Record($record, $marcFlavour.(($authorities and $marcFlavour ne "MARC21")?'AUTH':''));
286
         ($record, $guessed_charset, $charset_errors) = MarcToUTF8Record($record, $marcFlavour.(($authorities and $marcFlavour ne "MARC21")?'AUTH':''));
287
        if ($guessed_charset eq 'failed') {
287
        if ($guessed_charset eq 'failed') {
288
            warn "ERROR: failed to perform character conversion for record $i\n";
288
            warn "ERROR: failed to perform character conversion for record $i\n";
289
            next RECORD;            
289
            next RECORD;
290
        }
290
        }
291
    }
291
    }
292
    SetUTF8Flag($record);
292
    SetUTF8Flag($record);
Lines 322-327 RECORD: while ( ) { Link Here
322
            printlog( { id => $id || $originalid || $match, op => "match", status => "ERROR" } ) if ($logfile);
322
            printlog( { id => $id || $originalid || $match, op => "match", status => "ERROR" } ) if ($logfile);
323
            next RECORD;
323
            next RECORD;
324
        }
324
        }
325
325
        $debug && warn "$query $server : $totalhits";
326
        $debug && warn "$query $server : $totalhits";
326
        if ( $results && scalar(@$results) == 1 ) {
327
        if ( $results && scalar(@$results) == 1 ) {
327
            my $marcrecord = C4::Search::new_record_from_zebra( $server, $results->[0] );
328
            my $marcrecord = C4::Search::new_record_from_zebra( $server, $results->[0] );
Lines 395-401 RECORD: while ( ) { Link Here
395
				else{
396
				else{
396
					printlog({id=>$originalid||$id||$authid, op=>"edit",status=>"ok"}) if ($logfile);
397
					printlog({id=>$originalid||$id||$authid, op=>"edit",status=>"ok"}) if ($logfile);
397
				}
398
				}
398
            }  
399
            }
399
            elsif (defined $authid) {
400
            elsif (defined $authid) {
400
            ## An authid is defined but no authority in database : add
401
            ## An authid is defined but no authority in database : add
401
                eval { ( $authid ) = AddAuthority($record,$authid, $authtypecode) };
402
                eval { ( $authid ) = AddAuthority($record,$authid, $authtypecode) };
Lines 467-473 RECORD: while ( ) { Link Here
467
                }
468
                }
468
            } else {
469
            } else {
469
                if ($insert) {
470
                if ($insert) {
470
                    eval { ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '', { defer_marc_save => 1 } ) };
471
                    eval { ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '') };
471
                    if ($@) {
472
                    if ($@) {
472
                        warn "ERROR: Adding biblio $biblionumber failed: $@\n";
473
                        warn "ERROR: Adding biblio $biblionumber failed: $@\n";
473
                        printlog( { id => $id || $originalid || $biblionumber, op => "insert", status => "ERROR" } ) if ($logfile);
474
                        printlog( { id => $id || $originalid || $biblionumber, op => "insert", status => "ERROR" } ) if ($logfile);
Lines 483-499 RECORD: while ( ) { Link Here
483
            }
484
            }
484
            eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
485
            eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
485
            my $error_adding = $@;
486
            my $error_adding = $@;
486
            # Work on a clone so that if there are real errors, we can maybe
487
            # fix them up later.
488
			my $clone_record = $record->clone();
489
            C4::Biblio::_strip_item_fields($clone_record, '');
490
            # This sets the marc fields if there was an error, and also calls
491
            # defer_marc_save.
492
            ModBiblioMarc( $clone_record, $biblionumber, $framework );
493
            if ( $error_adding ) {
487
            if ( $error_adding ) {
494
                warn "ERROR: Adding items to bib $biblionumber failed: $error_adding";
488
                warn "ERROR: Adding items to bib $biblionumber failed: $error_adding";
495
				printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile);
489
				printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile);
496
                # if we failed because of an exception, assume that 
490
                # if we failed because of an exception, assume that
497
                # the MARC columns in biblioitems were not set.
491
                # the MARC columns in biblioitems were not set.
498
                next RECORD;
492
                next RECORD;
499
            }
493
            }
Lines 533-541 RECORD: while ( ) { Link Here
533
                if ( $@ ) {
527
                if ( $@ ) {
534
                    warn "ERROR: Adding items to bib $biblionumber failed: $@\n";
528
                    warn "ERROR: Adding items to bib $biblionumber failed: $@\n";
535
                    printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile);
529
                    printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile);
536
                    # if we failed because of an exception, assume that
537
                    # the MARC columns in biblioitems were not set.
538
                    ModBiblioMarc( $record, $biblionumber, $framework );
539
                    next RECORD;
530
                    next RECORD;
540
                } else {
531
                } else {
541
                    printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ok"}) if ($logfile);
532
                    printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ok"}) if ($logfile);
Lines 584-590 sub GetRecordId{ Link Here
584
	my $id;
575
	my $id;
585
	if ($tag lt "010"){
576
	if ($tag lt "010"){
586
		return $marcrecord->field($tag)->data() if $marcrecord->field($tag);
577
		return $marcrecord->field($tag)->data() if $marcrecord->field($tag);
587
	} 
578
	}
588
	elsif ($subfield){
579
	elsif ($subfield){
589
		if ($marcrecord->field($tag)){
580
		if ($marcrecord->field($tag)){
590
			return $marcrecord->subfield($tag,$subfield);
581
			return $marcrecord->subfield($tag,$subfield);
591
- 

Return to bug 25539