Bugzilla – Attachment 65655 Details for
Bug 19049
Fix regression on stage-marc-import with to_marc plugin
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19049: Restore import with to_marc plugin
Bug-19049-Restore-import-with-tomarc-plugin.patch (text/plain), 5.63 KB, created by
Marcel de Rooy
on 2017-08-08 15:50:40 UTC
(
hide
)
Description:
Bug 19049: Restore import with to_marc plugin
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2017-08-08 15:50:40 UTC
Size:
5.63 KB
patch
obsolete
>From f5e6ed53e16cb624ed7a54cba7fff3786e9864d0 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Mon, 7 Aug 2017 21:24:48 +0200 >Subject: [PATCH] Bug 19049: Restore import with to_marc plugin >Content-Type: text/plain; charset=utf-8 > >Still needs some polishing and testing. >--- > C4/ImportBatch.pm | 45 ++++++++++++++++++---- > .../prog/en/modules/tools/stage-marc-import.tt | 20 ++-------- > tools/stage-marc-import.pl | 13 +++++-- > 3 files changed, 50 insertions(+), 28 deletions(-) > >diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm >index c4550eb..5a3fa41 100644 >--- a/C4/ImportBatch.pm >+++ b/C4/ImportBatch.pm >@@ -399,13 +399,6 @@ sub BatchStageMarcRecords { > SetImportBatchItemAction($batch_id, 'ignore'); > } > >- $marc_records = Koha::Plugins::Handler->run( >- { >- class => $to_marc_plugin, >- method => 'to_marc', >- params => { data => $marc_records } >- } >- ) if $to_marc_plugin && @$marc_records; > > my $marc_type = C4::Context->preference('marcflavour'); > $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth'); >@@ -1556,6 +1549,44 @@ sub RecordsFromMARCXMLFile { > return (\@errors, \@marcRecords); > } > >+=head2 RecordsFromMarcPlugin >+ >+ Converts text of input_file into array of MARC records with to_marc plugin >+ >+=cut >+ >+sub RecordsFromMarcPlugin { >+ my ($input_file, $plugin_class, $encoding) = @_; >+ >+ # 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+//; >+ s/\s+$//; >+ next unless $_; >+ $text .= $_; >+ } >+ close IN; >+ >+ # Convert to large MARC blob with plugin >+ $text = Koha::Plugins::Handler->run({ >+ class => $plugin_class, >+ method => 'to_marc', >+ params => { data => $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; >+ } >+ return \@return; >+} >+ > # internal functions > > sub _create_import_record { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt >index 2383451..4f23ce7 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt >@@ -198,27 +198,13 @@ function cbUpload( status, fileid ) { > <select name='format' id='format'> > <option value='ISO2709'>MARC</option> > <option value='MARCXML'>MARCXML</option> >+ [% FOREACH p IN plugins %] >+ <option value="[% p.metadata.class %]">Other formats, handled by plugin [% p.metadata.name %]</option> >+ [% END %] > </select> > </li> > </ol></fieldset> > >- [% IF plugins %] >- <fieldset class="rows"> >- <legend>Transform file to MARC:</legend> >- <ol> >- <li> >- <label for="comments">Convert file to MARC using the following plugin: </label> >- <select name="to_marc_plugin" id="to_marc_plugin"> >- <option value="">Do not use.</option> >- [% FOREACH p IN plugins %] >- <option value="[% p.metadata.class %]">[% p.metadata.name %]</option> >- [% END %] >- </select> >- </li> >- </ol> >- </fieldset> >- [% END %] >- > [% IF MarcModificationTemplatesLoop %] > <fieldset class="rows"> > <legend>Use MARC Modification Template:</legend> >diff --git a/tools/stage-marc-import.pl b/tools/stage-marc-import.pl >index 63dd4e5..b334ddf 100755 >--- a/tools/stage-marc-import.pl >+++ b/tools/stage-marc-import.pl >@@ -57,8 +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') || 'ISO2709'; >-my $to_marc_plugin = $input->param('to_marc_plugin'); >+my $format = $input->param('format'); > my $marc_modification_template = $input->param('marc_modification_template_id'); > > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >@@ -90,10 +89,16 @@ if ($completedJobID) { > my $filename = $upload->filename; > > my ( $errors, $marcrecords ); >+warn "L92 $format"; > if( $format eq 'MARCXML' ) { > ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $encoding); >- } else { >+ } elsif( $format eq 'MARC' ) { > ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding ); >+ } elsif( $format ) { # plugin >+ $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 >@@ -141,7 +146,7 @@ if ($completedJobID) { > BatchStageMarcRecords( > $record_type, $encoding, > $marcrecords, $filename, >- $to_marc_plugin, $marc_modification_template, >+ undef, $marc_modification_template, > $comments, '', > $parse_items, 0, > 50, staging_progress_callback( $job, $dbh ) >-- >2.1.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 19049
:
65595
|
65655
|
65656
|
65707
|
65708
|
65797
|
65802
|
65803
|
65804
|
65807
|
65808
|
65809
|
65810
|
65876
|
65877