use C4::Charset;
use C4::AuthoritiesMarc;
use C4::MarcModificationTemplates;
+use Koha::Items;
use Koha::Plugins::Handler;
use Koha::Logger;
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 = ?");
$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} );
( $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';
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 (<IN>) {
s/^\s+//;
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;
}
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();