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

(-)a/C4/Biblio.pm (-19 / +25 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
189
The C<$options> argument is a hashref with additional parameters:
190
to additional options.  The only defined option is C<defer_marc_save>,
190
191
which if present and mapped to a true value, causes C<AddBiblio>
191
=over 4
192
to omit the call to save the MARC in C<biblio_metadata.metadata>
192
193
This option is provided B<only>
193
=item C<defer_marc_save>
194
for the use of scripts such as C<bulkmarcimport.pl> that may need
194
195
to do some manipulation of the MARC record for item parsing before
195
Causes C<AddBiblio> to omit the call to save the MARC in C<biblio_metadata.metadata>
196
saving it and which cannot afford the performance hit of saving
196
This option is provided B<only> for the use of scripts such as C<bulkmarcimport.pl>
197
the MARC record twice.  Consequently, do not use that option
197
that may need to do some manipulation of the MARC record for item parsing before
198
unless you can guarantee that C<ModBiblioMarc> will be called.
198
saving it and which cannot afford the performance hit of saving the MARC record twice.
199
Consequently, do not use that option unless you can guarantee that C<ModBiblioMarc>
200
will be called.
201
202
=item C<disable_autolink>
203
204
Unless C<disable_autolink> is passed AddBiblio will link record headings
205
to authorities based on settings in the system preferences. This flag allows
206
us to not link records when the authority linker is saving modifications.
207
208
=back
199
209
200
=cut
210
=cut
201
211
202
sub AddBiblio {
212
sub AddBiblio {
203
    my $record          = shift;
213
    my ($record, $frameworkcode, $options) = @_;
204
    my $frameworkcode   = shift;
214
    $options //= {};
205
    my $options         = @_ ? shift : undef;
206
    my $defer_marc_save = 0;
207
    if (!$record) {
215
    if (!$record) {
208
        carp('AddBiblio called with undefined record');
216
        carp('AddBiblio called with undefined record');
209
        return;
217
        return;
210
    }
218
    }
211
    if ( defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'} ) {
212
        $defer_marc_save = 1;
213
    }
214
219
215
    my $schema = Koha::Database->schema;
220
    my $schema = Koha::Database->schema;
216
    my ( $biblionumber, $biblioitemnumber );
221
    my ( $biblionumber, $biblioitemnumber );
Lines 286-297 sub AddBiblio { Link Here
286
            # update MARC subfield that stores biblioitems.cn_sort
291
            # update MARC subfield that stores biblioitems.cn_sort
287
            _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
292
            _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
288
293
289
            if (C4::Context->preference('BiblioAddsAuthorities')) {
294
            if ($options->{'disable_autolink'} && C4::Context->preference('BiblioAddsAuthorities')) {
290
                BiblioAutoLink( $record, $frameworkcode );
295
                BiblioAutoLink( $record, $frameworkcode );
291
            }
296
            }
292
297
293
            # now add the record
298
            # now add the record
294
            ModBiblioMarc( $record, $biblionumber ) unless $defer_marc_save;
299
            ModBiblioMarc( $record, $biblionumber ) unless $options->{'defer_marc_save'};
295
300
296
            # update OAI-PMH sets
301
            # update OAI-PMH sets
297
            if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
302
            if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
Lines 545-550 sub BiblioAutoLink { Link Here
545
    my $record        = shift;
550
    my $record        = shift;
546
    my $frameworkcode = shift;
551
    my $frameworkcode = shift;
547
    my $verbose = shift;
552
    my $verbose = shift;
553
548
    if (!$record) {
554
    if (!$record) {
549
        carp('Undefined record passed to BiblioAutoLink');
555
        carp('Undefined record passed to BiblioAutoLink');
550
        return 0;
556
        return 0;
(-)a/misc/migration_tools/bulkmarcimport.pl (-2 / +8 lines)
Lines 19-24 use C4::Biblio qw( Link Here
19
    ModBiblioMarc
19
    ModBiblioMarc
20
    GetFrameworkCode
20
    GetFrameworkCode
21
    GetMarcBiblio
21
    GetMarcBiblio
22
    BiblioAutoLink
22
);
23
);
23
use C4::Koha;
24
use C4::Koha;
24
use C4::Charset qw( MarcToUTF8Record SetUTF8Flag );
25
use C4::Charset qw( MarcToUTF8Record SetUTF8Flag );
Lines 125-130 if ($all) { Link Here
125
126
126
my $using_elastic_search = (C4::Context->preference('SearchEngine') eq 'Elasticsearch');
127
my $using_elastic_search = (C4::Context->preference('SearchEngine') eq 'Elasticsearch');
127
my $modify_biblio_marc_options = {
128
my $modify_biblio_marc_options = {
129
    disable_autolink => $using_elastic_search,
128
    defer_search_engine_indexing => $using_elastic_search,
130
    defer_search_engine_indexing => $using_elastic_search,
129
    overlay_context => { source => 'bulkmarcimport' }
131
    overlay_context => { source => 'bulkmarcimport' }
130
};
132
};
Lines 541-547 RECORD: foreach my $record (@{$marc_records}) { Link Here
541
                }
543
                }
542
            }
544
            }
543
            elsif ($insert) {
545
            elsif ($insert) {
544
                eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework, { defer_marc_save => 1 }) };
546
                eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework, { disable_autolink => 1, defer_marc_save => 1 }) };
545
                if ($@) {
547
                if ($@) {
546
                    warn "ERROR: Insert biblio $originalid failed: $@\n";
548
                    warn "ERROR: Insert biblio $originalid failed: $@\n";
547
                    printlog( { id => $originalid, op => "insert", status => "ERROR" } ) if ($logfile);
549
                    printlog( { id => $originalid, op => "insert", status => "ERROR" } ) if ($logfile);
Lines 645-650 RECORD: foreach my $record (@{$marc_records}) { Link Here
645
            $schema->txn_begin;
647
            $schema->txn_begin;
646
            if ($indexer) {
648
            if ($indexer) {
647
                $indexer->update_index(\@search_engine_record_ids, \@search_engine_records);
649
                $indexer->update_index(\@search_engine_record_ids, \@search_engine_records);
650
                if (C4::Context->preference('BiblioAddsAuthorities')) {
651
                    foreach my $record (@search_engine_records) {
652
                        BiblioAutoLink($record, $framework);
653
                    }
654
                }
648
                @search_engine_record_ids = ();
655
                @search_engine_record_ids = ();
649
                @search_engine_records = ();
656
                @search_engine_records = ();
650
            }
657
            }
651
- 

Return to bug 29440