Bugzilla – Attachment 53165 Details for
Bug 10407
Allow MARCXML records to be imported with Tools/Stage MARC records for import
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10407: Add marcxml import to stage-marc-import script
Bug-10407-Add-marcxml-import-to-stage-marc-import-.patch (text/plain), 4.49 KB, created by
Marcel de Rooy
on 2016-07-07 13:24:02 UTC
(
hide
)
Description:
Bug 10407: Add marcxml import to stage-marc-import script
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2016-07-07 13:24:02 UTC
Size:
4.49 KB
patch
obsolete
>From a96c3c6f3a60b9494a539633955a5f9385c5110c Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 7 Jul 2016 14:13:16 +0200 >Subject: [PATCH] Bug 10407: Add marcxml import to stage-marc-import script >Content-Type: text/plain; charset=utf-8 > >The previous patch did the groundwork, but did not yet add the call to >RecordsFromMARCXMLFile. >I will open a new report to add this to the interface, but in the >meantime this patch just looks for a .xml extension in the filename. > >Also changed: >[2] The errors of RecordsFromISO2709File are now returned to in array. >--- > C4/ImportBatch.pm | 24 ++++++++++++------------ > misc/stage_file.pl | 4 ++-- > tools/stage-marc-import.pl | 8 ++++++-- > 3 files changed, 20 insertions(+), 16 deletions(-) > >diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm >index ec9d7c2..78604a0 100644 >--- a/C4/ImportBatch.pm >+++ b/C4/ImportBatch.pm >@@ -1473,11 +1473,13 @@ Reads ISO2709 binary porridge from the given file and creates MARC::Record-objec > @PARAM2, String, see stage_file.pl > @PARAM3, String, should be utf8 > >+Returns two array refs. >+ > =cut > > sub RecordsFromISO2709File { > my ($input_file, $record_type, $encoding) = @_; >- my $errors; >+ my @errors; > > my $marc_type = C4::Context->preference('marcflavour'); > $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth'); >@@ -1493,40 +1495,38 @@ sub RecordsFromISO2709File { > my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding); > push @marc_records, $marc_record; > if ($charset_guessed ne $encoding) { >- $errors = '' unless $errors; >- $errors .= "Unexpected charset $charset_guessed, expecting $encoding\n"; >+ push @errors, >+ "Unexpected charset $charset_guessed, expecting $encoding\n"; > } > } > close IN; >- return ($errors, \@marc_records); >+ return ( \@errors, \@marc_records ); > } > > =head RecordsFromMARCXMLFile > > my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding); > >- >- > Creates MARC::Record-objects out of the given MARCXML-file. > > @PARAM1, String, absolute path to the ISO2709 file. > @PARAM2, String, should be utf8 > >+Returns two array refs. >+ > =cut > > sub RecordsFromMARCXMLFile { > my ( $filename, $encoding ) = @_; > my $batch = MARC::File::XML->in( $filename ); >- my @marcRecords; >- my @errors; >+ my ( @marcRecords, @errors, $record ); > do { >- eval { >- my $record = $batch->next($encoding); >- push @marcRecords, $record if $record; >- }; >+ eval { $record = $batch->next( $encoding ); }; > if ($@) { > push @errors, $@; >+ last; > } >+ push @marcRecords, $record if $record; > } while( $record ); > return (\@errors, \@marcRecords); > } >diff --git a/misc/stage_file.pl b/misc/stage_file.pl >index 95ac941..4374c1d 100755 >--- a/misc/stage_file.pl >+++ b/misc/stage_file.pl >@@ -94,8 +94,8 @@ sub process_batch { > my ($format, $input_file, $record_type, $match, $add_items, $batch_comment) = @_; > > my ($errors, $marc_records) = C4::ImportBatch::RecordsFromISO2709File($input_file, $record_type, $encoding) if $format eq 'ISO2709'; >- warn $errors if $errors; >- $marc_records = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding) if $format eq 'MARCXML'; >+ warn "@$errors\n" if @$errors; >+ ( $errors, $marc_records ) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding) if $format eq 'MARCXML'; > my $num_input_records = ($marc_records) ? scalar(@$marc_records) : 0; > > print "... staging MARC records -- please wait\n"; >diff --git a/tools/stage-marc-import.pl b/tools/stage-marc-import.pl >index e7e9954..0577016 100755 >--- a/tools/stage-marc-import.pl >+++ b/tools/stage-marc-import.pl >@@ -87,8 +87,12 @@ if ($completedJobID) { > } elsif ($fileID) { > my $upload = Koha::Upload->new->get({ id => $fileID }); > my $filename = $upload->{path}; >- my $marcrecord=''; >- my ($errors, $marcrecords) = C4::ImportBatch::RecordsFromISO2709File($uploaded_file->filename(), $record_type, $encoding); >+ my ( $errors, $marcrecords ); >+ if( $filename =~ /\.[^.]*xml$/i ) { # like .xml or .marcxml >+ ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $filename, $encoding); >+ } else { >+ ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $filename, $record_type, $encoding ); >+ } > > my $job = undef; > my $dbh; >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10407
:
38101
|
38127
|
38129
|
38133
|
42831
|
53164
|
53165
|
53218
|
53219
|
53220
|
53221
|
53223
|
53306
|
53765
|
53766
|
53767
|
53768
|
53769
|
53937
|
53938
|
53939
|
53940
|
53941