- my $uploaded_file = C4::UploadedFile->fetch($sessionID, $fileID);
- my $fh = $uploaded_file->fh();
- my $marcrecord='';
- $/ = "\035";
- while (<$fh>) {
- s/^\s+//;
- s/\s+$//;
- $marcrecord.=$_;
- }
-
- my $filename = $uploaded_file->name();
+ my $upload = Koha::UploadedFiles->find( $fileID );
+ my $file = $upload->full_path;
+ my $filename = $upload->filename;
+
+ my ( $errors, $marcrecords );
+ if( $format eq 'MARCXML' ) {
+ ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $encoding);
+ } elsif( $format eq 'ISO2709' ) {
+ ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding );
+ } else { # plugin based
+ $errors = [];
+ $marcrecords = C4::ImportBatch::RecordsFromMarcPlugin( $file, $format, $encoding );
+ }
+ warn "$filename: " . ( join ',', @$errors ) if @$errors;
+ # no need to exit if we have no records (or only errors) here
+ # BatchStageMarcRecords can handle that
+