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

(-)a/C4/Biblio.pm (-18 / +16 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
190
The C<$options> argument is a hashref with additional parameters:
191
to additional options.  The only defined option is C<defer_marc_save>,
191
192
which if present and mapped to a true value, causes C<AddBiblio>
192
=over 4
193
to omit the call to save the MARC in C<biblio_metadata.metadata>
193
194
This option is provided B<only>
194
=item B<defer_marc_save>: used when ModBiblioMarc is handled by the caller
195
for the use of scripts such as C<bulkmarcimport.pl> that may need
195
196
to do some manipulation of the MARC record for item parsing before
196
=item B<skip_record_index>: used when the indexing schedulling will be handled by the caller
197
saving it and which cannot afford the performance hit of saving
197
198
the MARC record twice.  Consequently, do not use that option
198
=back
199
unless you can guarantee that C<ModBiblioMarc> will be called.
200
199
201
=cut
200
=cut
202
201
203
sub AddBiblio {
202
sub AddBiblio {
204
    my $record          = shift;
203
    my ( $record, $frameworkcode, $options ) = @_;
205
    my $frameworkcode   = shift;
204
    
206
    my $options         = @_ ? shift : undef;
205
    $options //= {};
207
    my $defer_marc_save = 0;
206
    my $skip_record_index = $options->{skip_record_index} || 0;
207
    my $defer_marc_save   = $options->{defer_marc_save}   || 0;
208
208
    if (!$record) {
209
    if (!$record) {
209
        carp('AddBiblio called with undefined record');
210
        carp('AddBiblio called with undefined record');
210
        return;
211
        return;
211
    }
212
    }
212
    if ( defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'} ) {
213
        $defer_marc_save = 1;
214
    }
215
213
216
    my $schema = Koha::Database->schema;
214
    my $schema = Koha::Database->schema;
217
    my ( $biblionumber, $biblioitemnumber );
215
    my ( $biblionumber, $biblioitemnumber );
Lines 292-298 sub AddBiblio { Link Here
292
            }
290
            }
293
291
294
            # now add the record
292
            # now add the record
295
            ModBiblioMarc( $record, $biblionumber ) unless $defer_marc_save;
293
            ModBiblioMarc( $record, $biblionumber, { skip_record_index => $skip_record_index } ) unless $defer_marc_save;
296
294
297
            # update OAI-PMH sets
295
            # update OAI-PMH sets
298
            if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
296
            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 607-612 sub BatchCommitRecords { Link Here
607
    my $logged_in_patron = Koha::Patrons->find( $userenv->{number} );
609
    my $logged_in_patron = Koha::Patrons->find( $userenv->{number} );
608
610
609
    my $rec_num = 0;
611
    my $rec_num = 0;
612
    my @biblio_ids;
610
    while (my $rowref = $sth->fetchrow_hashref) {
613
    while (my $rowref = $sth->fetchrow_hashref) {
611
        $record_type = $rowref->{'record_type'};
614
        $record_type = $rowref->{'record_type'};
612
        $rec_num++;
615
        $rec_num++;
Lines 646-652 sub BatchCommitRecords { Link Here
646
            $num_added++;
649
            $num_added++;
647
            if ($record_type eq 'biblio') {
650
            if ($record_type eq 'biblio') {
648
                my $biblioitemnumber;
651
                my $biblioitemnumber;
649
                ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework);
652
                ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework, { skip_record_index => 1 });
653
                push @biblio_ids, $recordid;
650
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
654
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
651
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
655
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
652
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
656
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
Lines 685-693 sub BatchCommitRecords { Link Here
685
                    $context->{userid} = $logged_in_patron->userid;
689
                    $context->{userid} = $logged_in_patron->userid;
686
                }
690
                }
687
691
688
                ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode, {
692
                ModBiblio(
689
                    overlay_context => $context
693
                    $marc_record,
690
                });
694
                    $recordid,
695
                    $oldbiblio->frameworkcode,
696
                    {
697
                        overlay_context   => $context,
698
                        skip_record_index => 1
699
                    }
700
                );
701
                push @biblio_ids, $recordid;
691
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
702
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
692
703
693
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
704
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
Lines 715-720 sub BatchCommitRecords { Link Here
715
            $num_ignored++;
726
            $num_ignored++;
716
            if ($record_type eq 'biblio' and defined $recordid and ( $item_result eq 'create_new' || $item_result eq 'replace' ) ) {
727
            if ($record_type eq 'biblio' and defined $recordid and ( $item_result eq 'create_new' || $item_result eq 'replace' ) ) {
717
                my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
728
                my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
729
                push @biblio_ids, $recordid if $bib_items_added || $bib_items_replaced;
718
                $num_items_added += $bib_items_added;
730
                $num_items_added += $bib_items_added;
719
         $num_items_replaced += $bib_items_replaced;
731
         $num_items_replaced += $bib_items_replaced;
720
                $num_items_errored += $bib_items_errored;
732
                $num_items_errored += $bib_items_errored;
Lines 728-733 sub BatchCommitRecords { Link Here
728
        }
740
        }
729
    }
741
    }
730
    $sth->finish();
742
    $sth->finish();
743
744
    if ( @biblio_ids ) {
745
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
746
        $indexer->index_records( \@biblio_ids, "specialUpdate", "biblioserver" );
747
    }
748
731
    SetImportBatchStatus($batch_id, 'imported');
749
    SetImportBatchStatus($batch_id, 'imported');
732
    return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored);
750
    return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored);
733
}
751
}
Lines 773-779 sub BatchCommitItems { Link Here
773
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
791
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
774
        if ( $action eq "replace" && $duplicate_itemnumber ) {
792
        if ( $action eq "replace" && $duplicate_itemnumber ) {
775
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
793
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
776
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} );
794
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber}, { skip_record_index => 1 } );
777
            $updsth->bind_param( 1, 'imported' );
795
            $updsth->bind_param( 1, 'imported' );
778
            $updsth->bind_param( 2, $item->{itemnumber} );
796
            $updsth->bind_param( 2, $item->{itemnumber} );
779
            $updsth->bind_param( 3, $row->{'import_items_id'} );
797
            $updsth->bind_param( 3, $row->{'import_items_id'} );
Lines 782-788 sub BatchCommitItems { Link Here
782
            $num_items_replaced++;
800
            $num_items_replaced++;
783
        } elsif ( $action eq "replace" && $duplicate_barcode ) {
801
        } elsif ( $action eq "replace" && $duplicate_barcode ) {
784
            my $itemnumber = $duplicate_barcode->itemnumber;
802
            my $itemnumber = $duplicate_barcode->itemnumber;
785
            ModItemFromMarc( $item_marc, $biblionumber, $itemnumber );
803
            ModItemFromMarc( $item_marc, $biblionumber, $itemnumber, { skip_record_index => 1 } );
786
            $updsth->bind_param( 1, 'imported' );
804
            $updsth->bind_param( 1, 'imported' );
787
            $updsth->bind_param( 2, $item->{itemnumber} );
805
            $updsth->bind_param( 2, $item->{itemnumber} );
788
            $updsth->bind_param( 3, $row->{'import_items_id'} );
806
            $updsth->bind_param( 3, $row->{'import_items_id'} );
Lines 800-806 sub BatchCommitItems { Link Here
800
            my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
818
            my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
801
            $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield );
819
            $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield );
802
820
803
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber );
821
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber, { skip_record_index => 1 } );
804
            if( $itemnumber ) {
822
            if( $itemnumber ) {
805
                $updsth->bind_param( 1, 'imported' );
823
                $updsth->bind_param( 1, 'imported' );
806
                $updsth->bind_param( 2, $itemnumber );
824
                $updsth->bind_param( 2, $itemnumber );
807
- 

Return to bug 30822