X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FImportBatch.pm;h=99bc4287019e41b15bef59841aeacce3e1d2b75b;hb=26a779eded6fe24abe0be904da64e0186c3d91ec;hp=82d6af2bfcb6af8c4e40c16725ee317a240cc619;hpb=d24568b67256fab79b42ead54302c76d1c9653d7;p=koha.git diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 82d6af2bfc..99bc428701 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -27,6 +27,7 @@ use C4::Items; use C4::Charset; use C4::AuthoritiesMarc; use C4::MarcModificationTemplates; +use Koha::Items; use Koha::Plugins::Handler; use Koha::Logger; @@ -747,7 +748,7 @@ sub BatchCommitItems { my $item = TransformMarcToKoha( $item_marc ); - my $duplicate_barcode = exists( $item->{'barcode'} ) && GetItemnumberFromBarcode( $item->{'barcode'} ); + my $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} }); my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?"); @@ -761,7 +762,7 @@ sub BatchCommitItems { $updsth->finish(); $num_items_replaced++; } elsif ( $action eq "replace" && $duplicate_barcode ) { - my $itemnumber = GetItemnumberFromBarcode( $item->{'barcode'} ); + my $itemnumber = $duplicate_barcode->itemnumber; ModItemFromMarc( $item_marc, $biblionumber, $itemnumber ); $updsth->bind_param( 1, 'imported' ); $updsth->bind_param( 2, $item->{itemnumber} ); @@ -1118,7 +1119,7 @@ sub GetImportRecordsRange { ( $order_by ) = grep( /^$order_by$/, qw( import_record_id title status overlay_status ) ) ? $order_by : 'import_record_id'; my $order_by_direction = - uc( $parameters->{order_by_direction} ) eq 'DESC' ? 'DESC' : 'ASC'; + uc( $parameters->{order_by_direction} // 'ASC' ) eq 'DESC' ? 'DESC' : 'ASC'; $order_by .= " $order_by_direction, authorized_heading" if $order_by eq 'title'; @@ -1556,10 +1557,11 @@ sub RecordsFromMARCXMLFile { sub RecordsFromMarcPlugin { my ($input_file, $plugin_class, $encoding) = @_; + my ( $text, @return ); + return \@return if !$input_file || !$plugin_class; # Read input file open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n"; - my ( $text, $marc, @return ); $/ = "\035"; while () { s/^\s+//; @@ -1574,14 +1576,16 @@ sub RecordsFromMarcPlugin { class => $plugin_class, method => 'to_marc', params => { data => $text }, - }); + }) if $text; # Convert to array of MARC records - my $marc_type = C4::Context->preference('marcflavour'); - foreach my $blob ( split(/\x1D/, $text) ) { - next if $blob =~ /^\s*$/; - my ($marcrecord) = MarcToUTF8Record($blob, $marc_type, $encoding); - push @return, $marcrecord; + if( $text ) { + my $marc_type = C4::Context->preference('marcflavour'); + foreach my $blob ( split(/\x1D/, $text) ) { + next if $blob =~ /^\s*$/; + my ($marcrecord) = MarcToUTF8Record($blob, $marc_type, $encoding); + push @return, $marcrecord; + } } return \@return; } @@ -1592,10 +1596,10 @@ sub _create_import_record { my ($batch_id, $record_sequence, $marc_record, $record_type, $encoding, $z3950random, $marc_type) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("INSERT INTO import_records (import_batch_id, record_sequence, marc, marcxml, + my $sth = $dbh->prepare("INSERT INTO import_records (import_batch_id, record_sequence, marc, marcxml, marcxml_old, record_type, encoding, z3950random) - VALUES (?, ?, ?, ?, ?, ?, ?)"); - $sth->execute($batch_id, $record_sequence, $marc_record->as_usmarc(), $marc_record->as_xml($marc_type), + VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); + $sth->execute($batch_id, $record_sequence, $marc_record->as_usmarc(), $marc_record->as_xml($marc_type), '', $record_type, $encoding, $z3950random); my $import_record_id = $dbh->{'mysql_insertid'}; $sth->finish();