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

(-)a/C4/Biblio.pm (-9 / +32 lines)
Lines 181-187 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.  The defined options are:
185
186
C<defer_marc_save>,
185
which if present and mapped to a true value, causes C<AddBiblio>
187
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>
188
to omit the call to save the MARC in C<biblio_metadata.metadata>
187
This option is provided B<only>
189
This option is provided B<only>
Lines 191-196 saving it and which cannot afford the performance hit of saving Link Here
191
the MARC record twice.  Consequently, do not use that option
193
the MARC record twice.  Consequently, do not use that option
192
unless you can guarantee that C<ModBiblioMarc> will be called.
194
unless you can guarantee that C<ModBiblioMarc> will be called.
193
195
196
C<skip_record_index>
197
This prevents calling of index_records to add the record to the search engine(s)
198
If the caller is performing more actions to the record, or acting on a batch of records
199
this prevents multiple indexing calls.
200
194
=cut
201
=cut
195
202
196
sub AddBiblio {
203
sub AddBiblio {
Lines 198-203 sub AddBiblio { Link Here
198
    my $frameworkcode   = shift;
205
    my $frameworkcode   = shift;
199
    my $options         = @_ ? shift : undef;
206
    my $options         = @_ ? shift : undef;
200
    my $defer_marc_save = 0;
207
    my $defer_marc_save = 0;
208
    my $skip_record_index = 0;
201
    if (!$record) {
209
    if (!$record) {
202
        carp('AddBiblio called with undefined record');
210
        carp('AddBiblio called with undefined record');
203
        return;
211
        return;
Lines 205-210 sub AddBiblio { Link Here
205
    if ( defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'} ) {
213
    if ( defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'} ) {
206
        $defer_marc_save = 1;
214
        $defer_marc_save = 1;
207
    }
215
    }
216
    if ( defined $options and exists $options->{'skip_record_index'} and $options->{'skip_record_index'} ) {
217
        $skip_record_index = 1;
218
    }
208
219
209
    if (C4::Context->preference('BiblioAddsAuthorities')) {
220
    if (C4::Context->preference('BiblioAddsAuthorities')) {
210
        BiblioAutoLink( $record, $frameworkcode );
221
        BiblioAutoLink( $record, $frameworkcode );
Lines 226-232 sub AddBiblio { Link Here
226
    _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
237
    _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
227
238
228
    # now add the record
239
    # now add the record
229
    ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save;
240
    ModBiblioMarc( $record, $biblionumber, $frameworkcode, { skip_record_index => $skip_record_index } ) unless $defer_marc_save;
230
241
231
    # update OAI-PMH sets
242
    # update OAI-PMH sets
232
    if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
243
    if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
Lines 241-247 sub AddBiblio { Link Here
241
252
242
=head2 ModBiblio
253
=head2 ModBiblio
243
254
244
  ModBiblio( $record,$biblionumber,$frameworkcode, $disable_autolink);
255
  ModBiblio( $record,$biblionumber,$frameworkcode, $disable_autolink,[$params]);
245
256
246
Replace an existing bib record identified by C<$biblionumber>
257
Replace an existing bib record identified by C<$biblionumber>
247
with one supplied by the MARC::Record object C<$record>.  The embedded
258
with one supplied by the MARC::Record object C<$record>.  The embedded
Lines 263-272 us to not relink records when the authority linker is saving modifications. Link Here
263
274
264
Returns 1 on success 0 on failure
275
Returns 1 on success 0 on failure
265
276
277
The final optional parameter, C<$params>, expected to contain
278
'skip_record_index' key, which prevents calling of index_records.
279
If the caller is performing more actions to the record, or acting on a batch of records
280
this prevents multiple indexing calls.
281
266
=cut
282
=cut
267
283
268
sub ModBiblio {
284
sub ModBiblio {
269
    my ( $record, $biblionumber, $frameworkcode, $disable_autolink ) = @_;
285
    my ( $record, $biblionumber, $frameworkcode, $disable_autolink, $params ) = @_;
270
    if (!$record) {
286
    if (!$record) {
271
        carp 'No record passed to ModBiblio';
287
        carp 'No record passed to ModBiblio';
272
        return 0;
288
        return 0;
Lines 314-320 sub ModBiblio { Link Here
314
    _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode );
330
    _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode );
315
331
316
    # update the MARC record (that now contains biblio and items) with the new record data
332
    # update the MARC record (that now contains biblio and items) with the new record data
317
    &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
333
    &ModBiblioMarc( $record, $biblionumber, $frameworkcode, { skip_record_index => $params->{skip_record_index } } );
318
334
319
    # modify the other koha tables
335
    # modify the other koha tables
320
    _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );
336
    _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );
Lines 3035-3052 sub _koha_delete_biblio_metadata { Link Here
3035
3051
3036
=head2 ModBiblioMarc
3052
=head2 ModBiblioMarc
3037
3053
3038
  &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
3054
  &ModBiblioMarc($newrec,$biblionumber,$frameworkcode, [$params]);
3039
3055
3040
Add MARC XML data for a biblio to koha
3056
Add MARC XML data for a biblio to koha
3041
3057
3042
Function exported, but should NOT be used, unless you really know what you're doing
3058
Function exported, but should NOT be used, unless you really know what you're doing
3043
3059
3060
The final optional parameter, C<$params>, expected to contain
3061
'skip_record_index' key, which prevents calling of index_records.
3062
If the caller is performing more actions to the record, or acting on a batch of records
3063
this prevents multiple indexing calls.
3064
3044
=cut
3065
=cut
3045
3066
3046
sub ModBiblioMarc {
3067
sub ModBiblioMarc {
3047
    # pass the MARC::Record to this function, and it will create the records in
3068
    # pass the MARC::Record to this function, and it will create the records in
3048
    # the marcxml field
3069
    # the marcxml field
3049
    my ( $record, $biblionumber, $frameworkcode ) = @_;
3070
    my ( $record, $biblionumber, $frameworkcode, $params ) = @_;
3050
    if ( !$record ) {
3071
    if ( !$record ) {
3051
        carp 'ModBiblioMarc passed an undefined record';
3072
        carp 'ModBiblioMarc passed an undefined record';
3052
        return;
3073
        return;
Lines 3117-3124 sub ModBiblioMarc { Link Here
3117
    $m_rs->metadata( $record->as_xml_record($encoding) );
3138
    $m_rs->metadata( $record->as_xml_record($encoding) );
3118
    $m_rs->store;
3139
    $m_rs->store;
3119
3140
3120
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
3141
    unless( $params->{skip_record_index} ){
3121
    $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
3142
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
3143
        $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
3144
    }
3122
3145
3123
    return $biblionumber;
3146
    return $biblionumber;
3124
}
3147
}
(-)a/C4/ImportBatch.pm (-13 / +20 lines)
Lines 577-585 sub BatchCommitRecords { Link Here
577
    my $num_ignored = 0;
577
    my $num_ignored = 0;
578
    # commit (i.e., save, all records in the batch)
578
    # commit (i.e., save, all records in the batch)
579
    SetImportBatchStatus('importing');
579
    SetImportBatchStatus('importing');
580
    my $overlay_action = GetImportBatchOverlayAction($batch_id);
580
    my $batch = GetImportBatch( $batch_id );
581
    my $nomatch_action = GetImportBatchNoMatchAction($batch_id);
581
    my $overlay_action = $batch->{overlay_action};
582
    my $item_action = GetImportBatchItemAction($batch_id);
582
    my $nomatch_action = $batch->{nomatch_action};
583
    my $item_action = $batch->{item_action};
583
    my $item_tag;
584
    my $item_tag;
584
    my $item_subfield;
585
    my $item_subfield;
585
    my $dbh = C4::Context->dbh;
586
    my $dbh = C4::Context->dbh;
Lines 591-596 sub BatchCommitRecords { Link Here
591
    $sth->execute($batch_id);
592
    $sth->execute($batch_id);
592
    my $marcflavour = C4::Context->preference('marcflavour');
593
    my $marcflavour = C4::Context->preference('marcflavour');
593
    my $rec_num = 0;
594
    my $rec_num = 0;
595
    my $index;
596
    $index = $batch->{record_type} eq 'biblio' ?
597
        $Koha::SearchEngine::BIBLIOS_INDEX : $Koha::SearchEngine::AUTHORITIES_INDEX;
598
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $index });
594
    while (my $rowref = $sth->fetchrow_hashref) {
599
    while (my $rowref = $sth->fetchrow_hashref) {
595
        $record_type = $rowref->{'record_type'};
600
        $record_type = $rowref->{'record_type'};
596
        $rec_num++;
601
        $rec_num++;
Lines 630-643 sub BatchCommitRecords { Link Here
630
            $num_added++;
635
            $num_added++;
631
            if ($record_type eq 'biblio') {
636
            if ($record_type eq 'biblio') {
632
                my $biblioitemnumber;
637
                my $biblioitemnumber;
633
                ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework);
638
                ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework, { skip_record_index => 1 });
634
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
639
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
635
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
640
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
636
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
641
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result, { skip_record_index => 1 });
637
                    $num_items_added += $bib_items_added;
642
                    $num_items_added += $bib_items_added;
638
                    $num_items_replaced += $bib_items_replaced;
643
                    $num_items_replaced += $bib_items_replaced;
639
                    $num_items_errored += $bib_items_errored;
644
                    $num_items_errored += $bib_items_errored;
640
                }
645
                }
646
                $indexer->index_records( $recordid, "specialUpdate", "biblioserver" );
641
            } else {
647
            } else {
642
                $recordid = AddAuthority($marc_record, undef, GuessAuthTypeCode($marc_record));
648
                $recordid = AddAuthority($marc_record, undef, GuessAuthTypeCode($marc_record));
643
                $query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?";
649
                $query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?";
Lines 663-681 sub BatchCommitRecords { Link Here
663
                }
669
                }
664
                $oldxml = $old_marc->as_xml($marc_type);
670
                $oldxml = $old_marc->as_xml($marc_type);
665
671
666
                ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode);
672
                ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode, { skip_record_index => 1 });
667
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
673
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
668
674
669
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
675
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
670
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
676
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result, { skip_record_index => 1});
671
                    $num_items_added += $bib_items_added;
677
                    $num_items_added += $bib_items_added;
672
                    $num_items_replaced += $bib_items_replaced;
678
                    $num_items_replaced += $bib_items_replaced;
673
                    $num_items_errored += $bib_items_errored;
679
                    $num_items_errored += $bib_items_errored;
674
                }
680
                }
681
                $indexer->index_records( $recordid, "specialUpdate", "biblioserver" );
675
            } else {
682
            } else {
676
                $oldxml = GetAuthorityXML($recordid);
683
                $oldxml = GetAuthorityXML($recordid);
677
684
678
                ModAuthority($recordid, $marc_record, GuessAuthTypeCode($marc_record));
685
                ModAuthority($recordid, $marc_record, GuessAuthTypeCode($marc_record) );
679
                $query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?";
686
                $query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?";
680
            }
687
            }
681
            my $sth = $dbh->prepare_cached("UPDATE import_records SET marcxml_old = ? WHERE import_record_id = ?");
688
            my $sth = $dbh->prepare_cached("UPDATE import_records SET marcxml_old = ? WHERE import_record_id = ?");
Lines 691-697 sub BatchCommitRecords { Link Here
691
            $num_ignored++;
698
            $num_ignored++;
692
            $recordid = $record_match;
699
            $recordid = $record_match;
693
            if ($record_type eq 'biblio' and defined $recordid and ( $item_result eq 'create_new' || $item_result eq 'replace' ) ) {
700
            if ($record_type eq 'biblio' and defined $recordid and ( $item_result eq 'create_new' || $item_result eq 'replace' ) ) {
694
                my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
701
                my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result, { skip_record_index =>1 });
695
                $num_items_added += $bib_items_added;
702
                $num_items_added += $bib_items_added;
696
         $num_items_replaced += $bib_items_replaced;
703
         $num_items_replaced += $bib_items_replaced;
697
                $num_items_errored += $bib_items_errored;
704
                $num_items_errored += $bib_items_errored;
Lines 700-705 sub BatchCommitRecords { Link Here
700
                my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?");
707
                my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?");
701
                $sth2->execute($recordid, $rowref->{'import_record_id'});
708
                $sth2->execute($recordid, $rowref->{'import_record_id'});
702
                SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
709
                SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
710
                $indexer->index_records( $recordid, "specialUpdate", "biblioserver" );
703
            }
711
            }
704
            SetImportRecordStatus($rowref->{'import_record_id'}, 'ignored');
712
            SetImportRecordStatus($rowref->{'import_record_id'}, 'ignored');
705
        }
713
        }
Lines 750-756 sub BatchCommitItems { Link Here
750
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
758
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
751
        if ( $action eq "replace" && $duplicate_itemnumber ) {
759
        if ( $action eq "replace" && $duplicate_itemnumber ) {
752
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
760
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
753
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} );
761
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber},{ skip_record_index => 1 } );
754
            $updsth->bind_param( 1, 'imported' );
762
            $updsth->bind_param( 1, 'imported' );
755
            $updsth->bind_param( 2, $item->{itemnumber} );
763
            $updsth->bind_param( 2, $item->{itemnumber} );
756
            $updsth->bind_param( 3, $row->{'import_items_id'} );
764
            $updsth->bind_param( 3, $row->{'import_items_id'} );
Lines 759-765 sub BatchCommitItems { Link Here
759
            $num_items_replaced++;
767
            $num_items_replaced++;
760
        } elsif ( $action eq "replace" && $duplicate_barcode ) {
768
        } elsif ( $action eq "replace" && $duplicate_barcode ) {
761
            my $itemnumber = $duplicate_barcode->itemnumber;
769
            my $itemnumber = $duplicate_barcode->itemnumber;
762
            ModItemFromMarc( $item_marc, $biblionumber, $itemnumber );
770
            ModItemFromMarc( $item_marc, $biblionumber, $itemnumber, { skip_record_index => 1} );
763
            $updsth->bind_param( 1, 'imported' );
771
            $updsth->bind_param( 1, 'imported' );
764
            $updsth->bind_param( 2, $item->{itemnumber} );
772
            $updsth->bind_param( 2, $item->{itemnumber} );
765
            $updsth->bind_param( 3, $row->{'import_items_id'} );
773
            $updsth->bind_param( 3, $row->{'import_items_id'} );
Lines 773-779 sub BatchCommitItems { Link Here
773
            $updsth->execute();
781
            $updsth->execute();
774
            $num_items_errored++;
782
            $num_items_errored++;
775
        } else {
783
        } else {
776
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber );
784
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber, { skip_record_index => 1 } );
777
            if( $itemnumber ) {
785
            if( $itemnumber ) {
778
                $updsth->bind_param( 1, 'imported' );
786
                $updsth->bind_param( 1, 'imported' );
779
                $updsth->bind_param( 2, $itemnumber );
787
                $updsth->bind_param( 2, $itemnumber );
780
- 

Return to bug 26543