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

(-)a/C4/Biblio.pm (-16 / +4 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 226-232 sub AddBiblio { Link Here
226
    _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
214
    _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
227
215
228
    # now add the record
216
    # now add the record
229
    ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save;
217
    ModBiblioMarc( $record, $biblionumber, $frameworkcode );
230
218
231
    # update OAI-PMH sets
219
    # update OAI-PMH sets
232
    if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
220
    if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
Lines 273-280 sub ModBiblio { Link Here
273
    }
261
    }
274
262
275
    if ( C4::Context->preference("CataloguingLog") ) {
263
    if ( C4::Context->preference("CataloguingLog") ) {
276
        my $newrecord = GetMarcBiblio({ biblionumber => $biblionumber });
264
        my $oldrecord = GetMarcBiblio({ biblionumber => $biblionumber });
277
        logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $newrecord->as_formatted );
265
        logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $oldrecord->as_formatted );
278
    }
266
    }
279
267
280
    if ( !$disable_autolink && C4::Context->preference('BiblioAddsAuthorities') ) {
268
    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 / +5 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 395-401 RECORD: while ( ) { Link Here
395
				else{
395
				else{
396
					printlog({id=>$originalid||$id||$authid, op=>"edit",status=>"ok"}) if ($logfile);
396
					printlog({id=>$originalid||$id||$authid, op=>"edit",status=>"ok"}) if ($logfile);
397
				}
397
				}
398
            }  
398
            }
399
            elsif (defined $authid) {
399
            elsif (defined $authid) {
400
            ## An authid is defined but no authority in database : add
400
            ## An authid is defined but no authority in database : add
401
                eval { ( $authid ) = AddAuthority($record,$authid, $authtypecode) };
401
                eval { ( $authid ) = AddAuthority($record,$authid, $authtypecode) };
Lines 467-473 RECORD: while ( ) { Link Here
467
                }
467
                }
468
            } else {
468
            } else {
469
                if ($insert) {
469
                if ($insert) {
470
                    eval { ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '', { defer_marc_save => 1 } ) };
470
                    eval { ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '') };
471
                    if ($@) {
471
                    if ($@) {
472
                        warn "ERROR: Adding biblio $biblionumber failed: $@\n";
472
                        warn "ERROR: Adding biblio $biblionumber failed: $@\n";
473
                        printlog( { id => $id || $originalid || $biblionumber, op => "insert", status => "ERROR" } ) if ($logfile);
473
                        printlog( { id => $id || $originalid || $biblionumber, op => "insert", status => "ERROR" } ) if ($logfile);
Lines 483-499 RECORD: while ( ) { Link Here
483
            }
483
            }
484
            eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
484
            eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
485
            my $error_adding = $@;
485
            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 ) {
486
            if ( $error_adding ) {
494
                warn "ERROR: Adding items to bib $biblionumber failed: $error_adding";
487
                warn "ERROR: Adding items to bib $biblionumber failed: $error_adding";
495
				printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile);
488
				printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile);
496
                # if we failed because of an exception, assume that 
489
                # if we failed because of an exception, assume that
497
                # the MARC columns in biblioitems were not set.
490
                # the MARC columns in biblioitems were not set.
498
                next RECORD;
491
                next RECORD;
499
            }
492
            }
Lines 533-541 RECORD: while ( ) { Link Here
533
                if ( $@ ) {
526
                if ( $@ ) {
534
                    warn "ERROR: Adding items to bib $biblionumber failed: $@\n";
527
                    warn "ERROR: Adding items to bib $biblionumber failed: $@\n";
535
                    printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile);
528
                    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;
529
                    next RECORD;
540
                } else {
530
                } else {
541
                    printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ok"}) if ($logfile);
531
                    printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ok"}) if ($logfile);
Lines 584-590 sub GetRecordId{ Link Here
584
	my $id;
574
	my $id;
585
	if ($tag lt "010"){
575
	if ($tag lt "010"){
586
		return $marcrecord->field($tag)->data() if $marcrecord->field($tag);
576
		return $marcrecord->field($tag)->data() if $marcrecord->field($tag);
587
	} 
577
	}
588
	elsif ($subfield){
578
	elsif ($subfield){
589
		if ($marcrecord->field($tag)){
579
		if ($marcrecord->field($tag)){
590
			return $marcrecord->subfield($tag,$subfield);
580
			return $marcrecord->subfield($tag,$subfield);
591
- 

Return to bug 25539