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

(-)a/C4/Biblio.pm (-18 / +16 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 B<defer_marc_save>: used when ModBiblioMarc is handled by the caller
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
=item B<skip_record_index>: used when the indexing schedulling will be handled by the caller
196
saving it and which cannot afford the performance hit of saving
196
197
the MARC record twice.  Consequently, do not use that option
197
=back
198
unless you can guarantee that C<ModBiblioMarc> will be called.
199
198
200
=cut
199
=cut
201
200
202
sub AddBiblio {
201
sub AddBiblio {
203
    my $record          = shift;
202
    my ( $record, $frameworkcode, $options ) = @_;
204
    my $frameworkcode   = shift;
203
205
    my $options         = @_ ? shift : undef;
204
    $options //= {};
206
    my $defer_marc_save = 0;
205
    my $skip_record_index = $options->{skip_record_index} || 0;
206
    my $defer_marc_save   = $options->{defer_marc_save}   || 0;
207
207
    if (!$record) {
208
    if (!$record) {
208
        carp('AddBiblio called with undefined record');
209
        carp('AddBiblio called with undefined record');
209
        return;
210
        return;
210
    }
211
    }
211
    if ( defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'} ) {
212
        $defer_marc_save = 1;
213
    }
214
212
215
    my $schema = Koha::Database->schema;
213
    my $schema = Koha::Database->schema;
216
    my ( $biblionumber, $biblioitemnumber );
214
    my ( $biblionumber, $biblioitemnumber );
Lines 291-297 sub AddBiblio { Link Here
291
            }
289
            }
292
290
293
            # now add the record
291
            # now add the record
294
            ModBiblioMarc( $record, $biblionumber ) unless $defer_marc_save;
292
            ModBiblioMarc( $record, $biblionumber, { skip_record_index => $skip_record_index } ) unless $defer_marc_save;
295
293
296
            # update OAI-PMH sets
294
            # update OAI-PMH sets
297
            if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
295
            if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
(-)a/C4/ImportBatch.pm (-8 / +25 lines)
Lines 35-40 use C4::Charset qw( MarcToUTF8Record SetUTF8Flag StripNonXmlChars ); Link Here
35
use C4::AuthoritiesMarc qw( AddAuthority GuessAuthTypeCode GetAuthorityXML ModAuthority DelAuthority );
35
use C4::AuthoritiesMarc qw( AddAuthority GuessAuthTypeCode GetAuthorityXML ModAuthority DelAuthority );
36
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate );
36
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate );
37
use Koha::Items;
37
use Koha::Items;
38
use Koha::SearchEngine;
39
use Koha::SearchEngine::Indexer;
38
use Koha::Plugins::Handler;
40
use Koha::Plugins::Handler;
39
use Koha::Logger;
41
use Koha::Logger;
40
42
Lines 578-583 sub BatchCommitRecords { Link Here
578
    my $logged_in_patron = Koha::Patrons->find( $userenv->{number} );
580
    my $logged_in_patron = Koha::Patrons->find( $userenv->{number} );
579
581
580
    my $rec_num = 0;
582
    my $rec_num = 0;
583
    my @biblio_ids;
581
    while (my $rowref = $sth->fetchrow_hashref) {
584
    while (my $rowref = $sth->fetchrow_hashref) {
582
        $record_type = $rowref->{'record_type'};
585
        $record_type = $rowref->{'record_type'};
583
        $rec_num++;
586
        $rec_num++;
Lines 617-623 sub BatchCommitRecords { Link Here
617
            $num_added++;
620
            $num_added++;
618
            if ($record_type eq 'biblio') {
621
            if ($record_type eq 'biblio') {
619
                my $biblioitemnumber;
622
                my $biblioitemnumber;
620
                ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework);
623
                ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework, { skip_record_index => 1 });
624
                push @biblio_ids, $recordid;
621
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
625
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
622
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
626
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
623
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result, $biblioitemnumber);
627
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result, $biblioitemnumber);
Lines 656-664 sub BatchCommitRecords { Link Here
656
                    $context->{userid} = $logged_in_patron->userid;
660
                    $context->{userid} = $logged_in_patron->userid;
657
                }
661
                }
658
662
659
                ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode, {
663
                ModBiblio(
660
                    overlay_context => $context
664
                    $marc_record,
661
                });
665
                    $recordid,
666
                    $oldbiblio->frameworkcode,
667
                    {
668
                        overlay_context   => $context,
669
                        skip_record_index => 1
670
                    }
671
                );
672
                push @biblio_ids, $recordid;
662
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
673
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
663
674
664
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
675
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
Lines 686-691 sub BatchCommitRecords { Link Here
686
            $num_ignored++;
697
            $num_ignored++;
687
            if ($record_type eq 'biblio' and defined $recordid and ( $item_result eq 'create_new' || $item_result eq 'replace' ) ) {
698
            if ($record_type eq 'biblio' and defined $recordid and ( $item_result eq 'create_new' || $item_result eq 'replace' ) ) {
688
                my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
699
                my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
700
                push @biblio_ids, $recordid if $bib_items_added || $bib_items_replaced;
689
                $num_items_added += $bib_items_added;
701
                $num_items_added += $bib_items_added;
690
         $num_items_replaced += $bib_items_replaced;
702
         $num_items_replaced += $bib_items_replaced;
691
                $num_items_errored += $bib_items_errored;
703
                $num_items_errored += $bib_items_errored;
Lines 699-704 sub BatchCommitRecords { Link Here
699
        }
711
        }
700
    }
712
    }
701
    $sth->finish();
713
    $sth->finish();
714
715
    if ( @biblio_ids ) {
716
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
717
        $indexer->index_records( \@biblio_ids, "specialUpdate", "biblioserver" );
718
    }
719
702
    SetImportBatchStatus($batch_id, 'imported');
720
    SetImportBatchStatus($batch_id, 'imported');
703
    return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored);
721
    return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored);
704
}
722
}
Lines 744-750 sub BatchCommitItems { Link Here
744
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?");
762
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?");
745
        if ( $action eq "replace" && $duplicate_itemnumber ) {
763
        if ( $action eq "replace" && $duplicate_itemnumber ) {
746
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
764
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
747
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} );
765
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber}, { skip_record_index => 1 } );
748
            $updsth->bind_param( 1, 'imported' );
766
            $updsth->bind_param( 1, 'imported' );
749
            $updsth->bind_param( 2, $item->{itemnumber} );
767
            $updsth->bind_param( 2, $item->{itemnumber} );
750
            $updsth->bind_param( 3, undef );
768
            $updsth->bind_param( 3, undef );
Lines 754-760 sub BatchCommitItems { Link Here
754
            $num_items_replaced++;
772
            $num_items_replaced++;
755
        } elsif ( $action eq "replace" && $duplicate_barcode ) {
773
        } elsif ( $action eq "replace" && $duplicate_barcode ) {
756
            my $itemnumber = $duplicate_barcode->itemnumber;
774
            my $itemnumber = $duplicate_barcode->itemnumber;
757
            ModItemFromMarc( $item_marc, $biblionumber, $itemnumber );
775
            ModItemFromMarc( $item_marc, $biblionumber, $itemnumber, { skip_record_index => 1 } );
758
            $updsth->bind_param( 1, 'imported' );
776
            $updsth->bind_param( 1, 'imported' );
759
            $updsth->bind_param( 2, $item->{itemnumber} );
777
            $updsth->bind_param( 2, $item->{itemnumber} );
760
            $updsth->bind_param( 3, undef );
778
            $updsth->bind_param( 3, undef );
Lines 774-780 sub BatchCommitItems { Link Here
774
            my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
792
            my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
775
            $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield );
793
            $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield );
776
794
777
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber, {biblioitemnumber => $biblioitemnumber} );
795
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber, { biblioitemnumber => $biblioitemnumber, skip_record_index => 1 } );
778
            if( $itemnumber ) {
796
            if( $itemnumber ) {
779
                $updsth->bind_param( 1, 'imported' );
797
                $updsth->bind_param( 1, 'imported' );
780
                $updsth->bind_param( 2, $itemnumber );
798
                $updsth->bind_param( 2, $itemnumber );
781
- 

Return to bug 30822