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;
}
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' );
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(
( $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