@@ -, +, @@ to split undef if somehow plugin was not found, etc. If the routine returns an empty arrayref, stage-marc-import will do fine. --- C4/ImportBatch.pm | 16 +++++++++------- t/db_dependent/ImportBatch.t | 1 + tools/stage-marc-import.pl | 6 ++---- 3 files changed, 12 insertions(+), 11 deletions(-) --- a/C4/ImportBatch.pm +++ a/C4/ImportBatch.pm @@ -1559,7 +1559,7 @@ sub RecordsFromMarcPlugin { # Read input file open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n"; - my ( $text, $marc, @return ); + my ( $text, @return ); $/ = "\035"; while () { s/^\s+//; @@ -1574,14 +1574,16 @@ sub RecordsFromMarcPlugin { class => $plugin_class, method => 'to_marc', params => { data => $text }, - }); + }) if $plugin_class && $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; } --- a/t/db_dependent/ImportBatch.t +++ a/t/db_dependent/ImportBatch.t @@ -187,6 +187,7 @@ subtest "RecordsFromMarcPlugin" => sub { 245,a = Noise in the library|; close $fh; + t::lib::Mocks::mock_config( 'enable_plugins', 1 ); my ( $plugin ) = Koha::Plugins->new->GetPlugins({ metadata => { name => 'MarcFieldValues' } }); isnt( $plugin, undef, "Plugin found" ); my $records = C4::ImportBatch::RecordsFromMarcPlugin( $name, ref $plugin, 'UTF-8' ); --- a/tools/stage-marc-import.pl +++ a/tools/stage-marc-import.pl @@ -57,7 +57,7 @@ my $item_action = $input->param('item_action'); my $comments = $input->param('comments'); my $record_type = $input->param('record_type'); my $encoding = $input->param('encoding') || 'UTF-8'; -my $format = $input->param('format'); +my $format = $input->param('format') || 'MARC'; my $marc_modification_template = $input->param('marc_modification_template_id'); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -93,11 +93,9 @@ if ($completedJobID) { ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $encoding); } elsif( $format eq 'MARC' ) { ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding ); - } elsif( $format ) { # plugin + } else { # plugin based $errors = []; $marcrecords = C4::ImportBatch::RecordsFromMarcPlugin( $file, $format, $encoding ); - } else { - die "No format specified"; } warn "$filename: " . ( join ',', @$errors ) if @$errors; # no need to exit if we have no records (or only errors) here --