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

(-)a/C4/Biblio.pm (-16 / +1 lines)
Lines 187-217 The first argument is a C<MARC::Record> object containing the Link Here
187
bib to add, while the second argument is the desired MARC
187
bib to add, while the second argument is the desired MARC
188
framework code.
188
framework code.
189
189
190
This function also accepts a third, optional argument: a hashref
191
to additional options.  The only defined option is C<defer_marc_save>,
192
which if present and mapped to a true value, causes C<AddBiblio>
193
to omit the call to save the MARC in C<biblio_metadata.metadata>
194
This option is provided B<only>
195
for the use of scripts such as C<bulkmarcimport.pl> that may need
196
to do some manipulation of the MARC record for item parsing before
197
saving it and which cannot afford the performance hit of saving
198
the MARC record twice.  Consequently, do not use that option
199
unless you can guarantee that C<ModBiblioMarc> will be called.
200
201
=cut
190
=cut
202
191
203
sub AddBiblio {
192
sub AddBiblio {
204
    my $record          = shift;
193
    my $record          = shift;
205
    my $frameworkcode   = shift;
194
    my $frameworkcode   = shift;
206
    my $options         = @_ ? shift : undef;
195
    my $options         = @_ ? shift : undef;
207
    my $defer_marc_save = 0;
208
    if (!$record) {
196
    if (!$record) {
209
        carp('AddBiblio called with undefined record');
197
        carp('AddBiblio called with undefined record');
210
        return;
198
        return;
211
    }
199
    }
212
    if ( defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'} ) {
213
        $defer_marc_save = 1;
214
    }
215
200
216
    my $schema = Koha::Database->schema;
201
    my $schema = Koha::Database->schema;
217
    my ( $biblionumber, $biblioitemnumber );
202
    my ( $biblionumber, $biblioitemnumber );
Lines 292-298 sub AddBiblio { Link Here
292
            }
277
            }
293
278
294
            # now add the record
279
            # now add the record
295
            ModBiblioMarc( $record, $biblionumber ) unless $defer_marc_save;
280
            ModBiblioMarc( $record, $biblionumber );
296
281
297
            # update OAI-PMH sets
282
            # update OAI-PMH sets
298
            if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
283
            if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
(-)a/misc/migration_tools/bulkmarcimport.pl (-13 / +1 lines)
Lines 548-554 RECORD: foreach my $record (@{$marc_records}) { Link Here
548
                }
548
                }
549
            }
549
            }
550
            elsif ($insert) {
550
            elsif ($insert) {
551
                eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework, { defer_marc_save => 1 }) };
551
                eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework) };
552
                if ($@) {
552
                if ($@) {
553
                    warn "ERROR: Insert biblio $originalid failed: $@\n";
553
                    warn "ERROR: Insert biblio $originalid failed: $@\n";
554
                    printlog( { id => $originalid, op => "insert", status => "ERROR" } ) if ($logfile);
554
                    printlog( { id => $originalid, op => "insert", status => "ERROR" } ) if ($logfile);
Lines 570-582 RECORD: foreach my $record (@{$marc_records}) { Link Here
570
                $record_has_added_items = @{$itemnumbers_ref};
570
                $record_has_added_items = @{$itemnumbers_ref};
571
571
572
                my $error_adding = $@;
572
                my $error_adding = $@;
573
                # Work on a clone so that if there are real errors, we can maybe
574
                # fix them up later.
575
                my $clone_record = $record->clone();
576
                C4::Biblio::_strip_item_fields($clone_record, $framework);
577
                # This sets the marc fields if there was an error, and also calls
578
                # defer_marc_save.
579
                ModBiblioMarc($clone_record, $record_id, $modify_biblio_marc_options);
580
                if ($error_adding) {
573
                if ($error_adding) {
581
                    warn "ERROR: Adding items to bib $record_id failed: $error_adding";
574
                    warn "ERROR: Adding items to bib $record_id failed: $error_adding";
582
                    printlog({ id => $record_id, op => "insert items", status => "ERROR"}) if ($logfile);
575
                    printlog({ id => $record_id, op => "insert items", status => "ERROR"}) if ($logfile);
Lines 624-633 RECORD: foreach my $record (@{$marc_records}) { Link Here
624
                        printlog({ id => $record_id, op => "insert items", status => "ERROR" }) if ($logfile);
617
                        printlog({ id => $record_id, op => "insert items", status => "ERROR" }) if ($logfile);
625
                        # if we failed because of an exception, assume that
618
                        # if we failed because of an exception, assume that
626
                        # the MARC columns in biblioitems were not set.
619
                        # the MARC columns in biblioitems were not set.
627
628
                        # @FIXME: Why do we save here without stripping items? Besides,
629
                        # save with stripped items has already been performed
630
                        ModBiblioMarc($record, $record_id, $modify_biblio_marc_options);
631
                        next RECORD;
620
                        next RECORD;
632
                    }
621
                    }
633
                    else {
622
                    else {
634
- 

Return to bug 25539