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

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

Return to bug 25539