Bugzilla – Attachment 31676 Details for
Bug 12412
Add ability for plugins to convert arbitrary files to MARC from record staging tool
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12412 - Add ability for plugins to convert arbitrary files to MARC from record staging tool
Bug-12412---Add-ability-for-plugins-to-convert-arb.patch (text/plain), 12.73 KB, created by
Kyle M Hall (khall)
on 2014-09-17 13:50:30 UTC
(
hide
)
Description:
Bug 12412 - Add ability for plugins to convert arbitrary files to MARC from record staging tool
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2014-09-17 13:50:30 UTC
Size:
12.73 KB
patch
obsolete
>From 746a5f21a32610cba498eaa05a316d7312368f29 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Thu, 12 Jun 2014 12:18:41 -0400 >Subject: [PATCH] Bug 12412 - Add ability for plugins to convert arbitrary files to MARC from record staging tool > >Many libraries would like to be able to import various types of files as >MARC records ( citations, csv files, etc ). We can add a new function to >the plugins system to allow that kind of behavior at a very custom >level. > >Test Plan: >1) Ensure you have plugins enabled and configured correctly >2) Installed the attached version 2.00 of the Kitchen Sink plugin >3) Download the attached text file >4) Browse to "Stage MARC records for import" >5) Select the downloaded text file for staging >6) After uploading, you should see a new area "Transform file to MARC:", > select "Example Kitchen-Sink Plugin" from the pulldown menu >7) Click 'Stage for import" >8) Click 'Manage staged records" >9) You should now see two new MARC records! >--- > C4/ImportBatch.pm | 24 ++++++-- > Koha/Plugins.pm | 2 +- > Koha/Plugins/Handler.pm | 3 +- > .../prog/en/modules/admin/admin-home.tt | 7 ++ > .../prog/en/modules/tools/stage-marc-import.tt | 18 +++++ > misc/stage_file.pl | 3 +- > t/Koha/Plugin/Test.pm | 5 ++ > t/db_dependent/Plugins.t | 3 +- > tools/stage-marc-import.pl | 68 +++++++++++--------- > 9 files changed, 94 insertions(+), 39 deletions(-) > >diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm >index a487cc6..516a83c 100644 >--- a/C4/ImportBatch.pm >+++ b/C4/ImportBatch.pm >@@ -27,6 +27,7 @@ use C4::Items; > use C4::Charset; > use C4::AuthoritiesMarc; > use C4::MarcModificationTemplates; >+use Koha::Plugins::Handler; > > use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); > >@@ -316,11 +317,15 @@ sub ModAuthInBatch { > > =head2 BatchStageMarcRecords > >- ($batch_id, $num_records, $num_items, @invalid_records) = >- BatchStageMarcRecords($encoding, $marc_records, $file_name, $marc_modification_template, >- $comments, $branch_code, $parse_items, >- $leave_as_staging, >- $progress_interval, $progress_callback); >+( $batch_id, $num_records, $num_items, @invalid_records ) = >+ BatchStageMarcRecords( >+ $encoding, $marc_records, >+ $file_name, $to_marc_plugin, >+ $marc_modification_template, $comments, >+ $branch_code, $parse_items, >+ $leave_as_staging, $progress_interval, >+ $progress_callback >+ ); > > =cut > >@@ -329,6 +334,7 @@ sub BatchStageMarcRecords { > my $encoding = shift; > my $marc_records = shift; > my $file_name = shift; >+ my $to_marc_plugin = shift; > my $marc_modification_template = shift; > my $comments = shift; > my $branch_code = shift; >@@ -360,6 +366,14 @@ 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; >+ > my $marc_type = C4::Context->preference('marcflavour'); > $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth'); > my @invalid_records = (); >diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm >index 3b31fc5..a66cf5a 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -51,7 +51,7 @@ This will return a list of all the available plugins of the passed type. > > Usage: my @plugins = C4::Plugins::GetPlugins( $method ); > >-At the moment, the available types are 'report' and 'tool'. >+At the moment, the available types are 'report', 'tool' and 'to_marc'. > =cut > > sub GetPlugins { >diff --git a/Koha/Plugins/Handler.pm b/Koha/Plugins/Handler.pm >index 41c242b..ba7591f 100644 >--- a/Koha/Plugins/Handler.pm >+++ b/Koha/Plugins/Handler.pm >@@ -56,11 +56,12 @@ sub run { > my $plugin_class = $args->{'class'}; > my $plugin_method = $args->{'method'}; > my $cgi = $args->{'cgi'}; >+ my $params = $args->{'params'}; > > if ( can_load( modules => { $plugin_class => undef } ) ) { > my $plugin = $plugin_class->new( { cgi => $cgi, enable_plugins => $args->{'enable_plugins'} } ); > if ( $plugin->can($plugin_method) ) { >- return $plugin->$plugin_method(); >+ return $plugin->$plugin_method( $params ); > } else { > warn "Plugin does not have method $plugin_method"; > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt >index 270cefe..ed77d09 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt >@@ -57,6 +57,13 @@ > <dt><a href="/cgi-bin/koha/admin/cities.pl">Cities and towns</a></dt> > <dd>Define cities and towns that your patrons live in.</dd> > </dl> >+[% IF CAN_user_plugins %] >+ <h3>Plugins</h3> >+ <dl> >+ <dt><a href="/cgi-bin/koha/plugins/plugins-home.pl">Manage plugins</a></dt> >+ <dd>View, manage, configure and run plugins.</dd> >+ </dl> >+[% END %] > </div> > <div class="yui-u"> > <h3>Catalog</h3> >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 b9b17f5..50d7517 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 >@@ -117,6 +117,24 @@ function CheckForm(f) { > <select name="encoding" id="encoding"><option value="utf8" selected="selected">UTF-8 (Default)</option><option value="MARC-8">MARC 8</option><option value="ISO_5426">ISO 5426</option><option value="ISO_6937">ISO 6937</option><option value=ISO_8859-1">ISO 8859-1</option><option value="EUC-KR">EUC-KR</option></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/misc/stage_file.pl b/misc/stage_file.pl >index 2e15466..3003084 100755 >--- a/misc/stage_file.pl >+++ b/misc/stage_file.pl >@@ -100,8 +100,9 @@ sub process_batch { > close IN; > > print "... staging MARC records -- please wait\n"; >+ #FIXME: We should really allow the use of marc modification frameworks and to_marc plugins here if possible > my ($batch_id, $num_valid_records, $num_items, @import_errors) = >- BatchStageMarcRecords($record_type, $encoding, $marc_records, $input_file, undef, $batch_comment, '', $add_items, 0, >+ BatchStageMarcRecords($record_type, $encoding, $marc_records, $input_file, undef, undef, $batch_comment, '', $add_items, 0, > 100, \&print_progress_and_commit); > print "... finished staging MARC records\n"; > >diff --git a/t/Koha/Plugin/Test.pm b/t/Koha/Plugin/Test.pm >index 39d2373..6a8ca78 100644 >--- a/t/Koha/Plugin/Test.pm >+++ b/t/Koha/Plugin/Test.pm >@@ -37,6 +37,11 @@ sub tool { > return "Koha::Plugin::Test::tool"; > } > >+sub to_marc { >+ my ( $self, $args ) = @_; >+ return "Koha::Plugin::Test::to_marc"; >+} >+ > sub configure { > my ( $self, $args ) = @_; > return "Koha::Plugin::Test::configure";; >diff --git a/t/db_dependent/Plugins.t b/t/db_dependent/Plugins.t >index bb7a836..3271b1a 100755 >--- a/t/db_dependent/Plugins.t >+++ b/t/db_dependent/Plugins.t >@@ -3,7 +3,7 @@ > use strict; > use warnings; > >-use Test::More tests => 20; >+use Test::More tests => 21; > use File::Basename; > use FindBin qw($Bin); > use Archive::Extract; >@@ -29,6 +29,7 @@ isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' ); > > ok( $plugin->can('report'), 'Test plugin can report' ); > ok( $plugin->can('tool'), 'Test plugin can tool' ); >+ok( $plugin->can('to_marc'), 'Test plugin can to_marc' ); > ok( $plugin->can('configure'), 'Test plugin can configure' ); > ok( $plugin->can('install'), 'Test plugin can install' ); > ok( $plugin->can('uninstall'), 'Test plugin can install' ); >diff --git a/tools/stage-marc-import.pl b/tools/stage-marc-import.pl >index a5f4d17..7b6922c 100755 >--- a/tools/stage-marc-import.pl >+++ b/tools/stage-marc-import.pl >@@ -42,33 +42,39 @@ use C4::Matcher; > use C4::UploadedFile; > use C4::BackgroundJob; > use C4::MarcModificationTemplates; >+use Koha::Plugins; > > my $input = new CGI; > >-my $fileID=$input->param('uploadedfileid'); >-my $runinbackground = $input->param('runinbackground'); >-my $completedJobID = $input->param('completedJobID'); >-my $matcher_id = $input->param('matcher'); >-my $overlay_action = $input->param('overlay_action'); >-my $nomatch_action = $input->param('nomatch_action'); >-my $parse_items = $input->param('parse_items'); >-my $item_action = $input->param('item_action'); >-my $comments = $input->param('comments'); >-my $record_type = $input->param('record_type'); >-my $encoding = $input->param('encoding'); >+my $fileID = $input->param('uploadedfileid'); >+my $runinbackground = $input->param('runinbackground'); >+my $completedJobID = $input->param('completedJobID'); >+my $matcher_id = $input->param('matcher'); >+my $overlay_action = $input->param('overlay_action'); >+my $nomatch_action = $input->param('nomatch_action'); >+my $parse_items = $input->param('parse_items'); >+my $item_action = $input->param('item_action'); >+my $comments = $input->param('comments'); >+my $record_type = $input->param('record_type'); >+my $encoding = $input->param('encoding'); >+my $to_marc_plugin = $input->param('to_marc_plugin'); > my $marc_modification_template = $input->param('marc_modification_template_id'); > >-my ($template, $loggedinuser, $cookie) >- = get_template_and_user({template_name => "tools/stage-marc-import.tt", >- query => $input, >- type => "intranet", >- authnotrequired => 0, >- flagsrequired => {tools => 'stage_marc_import'}, >- debug => 1, >- }); >+my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >+ { >+ template_name => "tools/stage-marc-import.tt", >+ query => $input, >+ type => "intranet", >+ authnotrequired => 0, >+ flagsrequired => { tools => 'stage_marc_import' }, >+ debug => 1, >+ } >+); > >-$template->param(SCRIPT_NAME => $ENV{'SCRIPT_NAME'}, >- uploadmarc => $fileID); >+$template->param( >+ SCRIPT_NAME => $ENV{'SCRIPT_NAME'}, >+ uploadmarc => $fileID >+); > > my %cookies = parse CGI::Cookie($cookie); > my $sessionID = $cookies{'CGISESSID'}->value; >@@ -128,12 +134,12 @@ if ($completedJobID) { > # FIXME branch code > my ( $batch_id, $num_valid, $num_items, @import_errors ) = > BatchStageMarcRecords( >- $record_type, $encoding, >- $marcrecord, $filename, >- $marc_modification_template, $comments, >- '', $parse_items, >- 0, 50, >- staging_progress_callback( $job, $dbh ) >+ $record_type, $encoding, >+ $marcrecord, $filename, >+ $to_marc_plugin, $marc_modification_template, >+ $comments, '', >+ $parse_items, 0, >+ 50, staging_progress_callback( $job, $dbh ) > ); > > my $num_with_matches = 0; >@@ -186,15 +192,17 @@ if ($completedJobID) { > > } else { > # initial form >- if (C4::Context->preference("marcflavour") eq "UNIMARC") { >- $template->param("UNIMARC" => 1); >+ if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) { >+ $template->param( "UNIMARC" => 1 ); > } > my @matchers = C4::Matcher::GetMatcherList(); >- $template->param(available_matchers => \@matchers); >+ $template->param( available_matchers => \@matchers ); > > my @templates = GetModificationTemplates(); > $template->param( MarcModificationTemplatesLoop => \@templates ); > >+ my @plugins = Koha::Plugins->new()->GetPlugins('to_marc'); >+ $template->param( plugins => \@plugins ); > } > > output_html_with_http_headers $input, $cookie, $template->output; >-- >1.7.2.5
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 12412
:
28825
|
28826
|
28827
|
31676
|
35483
|
36478