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

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

Return to bug 25539