View | Details | Raw Unified | Return to bug 12412
Collapse All | Expand All

(-)a/C4/ImportBatch.pm (-5 / +19 lines)
Lines 27-32 use C4::Items; Link Here
27
use C4::Charset;
27
use C4::Charset;
28
use C4::AuthoritiesMarc;
28
use C4::AuthoritiesMarc;
29
use C4::MarcModificationTemplates;
29
use C4::MarcModificationTemplates;
30
use Koha::Plugins::Handler;
30
31
31
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
32
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
32
33
Lines 316-326 sub ModAuthInBatch { Link Here
316
317
317
=head2 BatchStageMarcRecords
318
=head2 BatchStageMarcRecords
318
319
319
  ($batch_id, $num_records, $num_items, @invalid_records) = 
320
( $batch_id, $num_records, $num_items, @invalid_records ) =
320
    BatchStageMarcRecords($encoding, $marc_records, $file_name, $marc_modification_template,
321
  BatchStageMarcRecords(
321
                          $comments, $branch_code, $parse_items,
322
    $encoding,                   $marc_records,
322
                          $leave_as_staging, 
323
    $file_name,                  $to_marc_plugin,
323
                          $progress_interval, $progress_callback);
324
    $marc_modification_template, $comments,
325
    $branch_code,                $parse_items,
326
    $leave_as_staging,           $progress_interval,
327
    $progress_callback
328
  );
324
329
325
=cut
330
=cut
326
331
Lines 329-334 sub BatchStageMarcRecords { Link Here
329
    my $encoding = shift;
334
    my $encoding = shift;
330
    my $marc_records = shift;
335
    my $marc_records = shift;
331
    my $file_name = shift;
336
    my $file_name = shift;
337
    my $to_marc_plugin = shift;
332
    my $marc_modification_template = shift;
338
    my $marc_modification_template = shift;
333
    my $comments = shift;
339
    my $comments = shift;
334
    my $branch_code = shift;
340
    my $branch_code = shift;
Lines 360-365 sub BatchStageMarcRecords { Link Here
360
        SetImportBatchItemAction($batch_id, 'ignore');
366
        SetImportBatchItemAction($batch_id, 'ignore');
361
    }
367
    }
362
368
369
    $marc_records = Koha::Plugins::Handler->run(
370
        {
371
            class  => $to_marc_plugin,
372
            method => 'to_marc',
373
            params => { data => $marc_records }
374
        }
375
    );
376
363
    my $marc_type = C4::Context->preference('marcflavour');
377
    my $marc_type = C4::Context->preference('marcflavour');
364
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
378
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
365
    my @invalid_records = ();
379
    my @invalid_records = ();
(-)a/Koha/Plugins.pm (-1 / +1 lines)
Lines 51-57 This will return a list of all the available plugins of the passed type. Link Here
51
51
52
Usage: my @plugins = C4::Plugins::GetPlugins( $method );
52
Usage: my @plugins = C4::Plugins::GetPlugins( $method );
53
53
54
At the moment, the available types are 'report' and 'tool'.
54
At the moment, the available types are 'report', 'tool' and 'to_marc'.
55
=cut
55
=cut
56
56
57
sub GetPlugins {
57
sub GetPlugins {
(-)a/Koha/Plugins/Handler.pm (-1 / +2 lines)
Lines 56-66 sub run { Link Here
56
    my $plugin_class  = $args->{'class'};
56
    my $plugin_class  = $args->{'class'};
57
    my $plugin_method = $args->{'method'};
57
    my $plugin_method = $args->{'method'};
58
    my $cgi           = $args->{'cgi'};
58
    my $cgi           = $args->{'cgi'};
59
    my $params        = $args->{'params'};
59
60
60
    if ( can_load( modules => { $plugin_class => undef } ) ) {
61
    if ( can_load( modules => { $plugin_class => undef } ) ) {
61
        my $plugin = $plugin_class->new( { cgi => $cgi, enable_plugins => $args->{'enable_plugins'} } );
62
        my $plugin = $plugin_class->new( { cgi => $cgi, enable_plugins => $args->{'enable_plugins'} } );
62
        if ( $plugin->can($plugin_method) ) {
63
        if ( $plugin->can($plugin_method) ) {
63
            return $plugin->$plugin_method();
64
            return $plugin->$plugin_method( $params );
64
        } else {
65
        } else {
65
            warn "Plugin does not have method $plugin_method";
66
            warn "Plugin does not have method $plugin_method";
66
        }
67
        }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+7 lines)
Lines 57-62 Link Here
57
    <dt><a href="/cgi-bin/koha/admin/cities.pl">Cities and towns</a></dt>
57
    <dt><a href="/cgi-bin/koha/admin/cities.pl">Cities and towns</a></dt>
58
    <dd>Define cities and towns that your patrons live in.</dd>
58
    <dd>Define cities and towns that your patrons live in.</dd>
59
</dl>
59
</dl>
60
[% IF CAN_user_plugins %]
61
    <h3>Plugins</h3>
62
    <dl>
63
        <dt><a href="/cgi-bin/koha/plugins/plugins-home.pl">Manage plugins</a></dt>
64
        <dd>View, manage, configure and run plugins.</dd>
65
    </dl>
66
[% END %]
60
</div>
67
</div>
61
<div class="yui-u">
68
<div class="yui-u">
62
<h3>Catalog</h3>
69
<h3>Catalog</h3>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt (+18 lines)
Lines 117-122 function CheckForm(f) { Link Here
117
            <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>
117
            <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>
118
	</li>
118
	</li>
119
</ol></fieldset>
119
</ol></fieldset>
120
121
  [% IF plugins %]
122
    <fieldset class="rows">
123
      <legend>Transform file to MARC:</legend>
124
      <ol>
125
        <li>
126
          <label for="comments">Convert file to MARC using the following plugin: </label>
127
          <select name="to_marc_plugin" id="to_marc_plugin">
128
            <option value="">Do not use.</option>
129
              [% FOREACH p IN plugins %]
130
                <option value="[% p.metadata.class %]">[% p.metadata.name %]</option>
131
              [% END %]
132
          </select>
133
        </li>
134
      </ol>
135
    </fieldset>
136
  [% END %]
137
120
  [% IF MarcModificationTemplatesLoop %]
138
  [% IF MarcModificationTemplatesLoop %]
121
    <fieldset class="rows">
139
    <fieldset class="rows">
122
      <legend>Use MARC Modification Template:</legend>
140
      <legend>Use MARC Modification Template:</legend>
(-)a/misc/stage_file.pl (-1 / +2 lines)
Lines 100-107 sub process_batch { Link Here
100
    close IN;
100
    close IN;
101
101
102
    print "... staging MARC records -- please wait\n";
102
    print "... staging MARC records -- please wait\n";
103
    #FIXME: We should really allow the use of marc modification frameworks and to_marc plugins here if possible
103
    my ($batch_id, $num_valid_records, $num_items, @import_errors) =
104
    my ($batch_id, $num_valid_records, $num_items, @import_errors) =
104
        BatchStageMarcRecords($record_type, $encoding, $marc_records, $input_file, undef, $batch_comment, '', $add_items, 0,
105
        BatchStageMarcRecords($record_type, $encoding, $marc_records, $input_file, undef, undef, $batch_comment, '', $add_items, 0,
105
                              100, \&print_progress_and_commit);
106
                              100, \&print_progress_and_commit);
106
    print "... finished staging MARC records\n";
107
    print "... finished staging MARC records\n";
107
108
(-)a/t/Koha/Plugin/Test.pm (+5 lines)
Lines 37-42 sub tool { Link Here
37
    return "Koha::Plugin::Test::tool";
37
    return "Koha::Plugin::Test::tool";
38
}
38
}
39
39
40
sub to_marc {
41
    my ( $self, $args ) = @_;
42
    return "Koha::Plugin::Test::to_marc";
43
}
44
40
sub configure {
45
sub configure {
41
    my ( $self, $args ) = @_;
46
    my ( $self, $args ) = @_;
42
    return "Koha::Plugin::Test::configure";;
47
    return "Koha::Plugin::Test::configure";;
(-)a/t/db_dependent/Plugins.t (-1 / +2 lines)
Lines 3-9 Link Here
3
use strict;
3
use strict;
4
use warnings;
4
use warnings;
5
5
6
use Test::More tests => 20;
6
use Test::More tests => 21;
7
use File::Basename;
7
use File::Basename;
8
use FindBin qw($Bin);
8
use FindBin qw($Bin);
9
use Archive::Extract;
9
use Archive::Extract;
Lines 29-34 isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' ); Link Here
29
29
30
ok( $plugin->can('report'), 'Test plugin can report' );
30
ok( $plugin->can('report'), 'Test plugin can report' );
31
ok( $plugin->can('tool'), 'Test plugin can tool' );
31
ok( $plugin->can('tool'), 'Test plugin can tool' );
32
ok( $plugin->can('to_marc'), 'Test plugin can to_marc' );
32
ok( $plugin->can('configure'), 'Test plugin can configure' );
33
ok( $plugin->can('configure'), 'Test plugin can configure' );
33
ok( $plugin->can('install'), 'Test plugin can install' );
34
ok( $plugin->can('install'), 'Test plugin can install' );
34
ok( $plugin->can('uninstall'), 'Test plugin can install' );
35
ok( $plugin->can('uninstall'), 'Test plugin can install' );
(-)a/tools/stage-marc-import.pl (-31 / +38 lines)
Lines 42-74 use C4::Matcher; Link Here
42
use C4::UploadedFile;
42
use C4::UploadedFile;
43
use C4::BackgroundJob;
43
use C4::BackgroundJob;
44
use C4::MarcModificationTemplates;
44
use C4::MarcModificationTemplates;
45
use Koha::Plugins;
45
46
46
my $input = new CGI;
47
my $input = new CGI;
47
48
48
my $fileID=$input->param('uploadedfileid');
49
my $fileID                     = $input->param('uploadedfileid');
49
my $runinbackground = $input->param('runinbackground');
50
my $runinbackground            = $input->param('runinbackground');
50
my $completedJobID = $input->param('completedJobID');
51
my $completedJobID             = $input->param('completedJobID');
51
my $matcher_id = $input->param('matcher');
52
my $matcher_id                 = $input->param('matcher');
52
my $overlay_action = $input->param('overlay_action');
53
my $overlay_action             = $input->param('overlay_action');
53
my $nomatch_action = $input->param('nomatch_action');
54
my $nomatch_action             = $input->param('nomatch_action');
54
my $parse_items = $input->param('parse_items');
55
my $parse_items                = $input->param('parse_items');
55
my $item_action = $input->param('item_action');
56
my $item_action                = $input->param('item_action');
56
my $comments = $input->param('comments');
57
my $comments                   = $input->param('comments');
57
my $record_type = $input->param('record_type');
58
my $record_type                = $input->param('record_type');
58
my $encoding = $input->param('encoding');
59
my $encoding                   = $input->param('encoding');
60
my $to_marc_plugin             = $input->param('to_marc_plugin');
59
my $marc_modification_template = $input->param('marc_modification_template_id');
61
my $marc_modification_template = $input->param('marc_modification_template_id');
60
62
61
my ($template, $loggedinuser, $cookie)
63
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62
	= get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
64
    {
63
					query => $input,
65
        template_name   => "tools/stage-marc-import.tmpl",
64
					type => "intranet",
66
        query           => $input,
65
					authnotrequired => 0,
67
        type            => "intranet",
66
					flagsrequired => {tools => 'stage_marc_import'},
68
        authnotrequired => 0,
67
					debug => 1,
69
        flagsrequired   => { tools => 'stage_marc_import' },
68
					});
70
        debug           => 1,
71
    }
72
);
69
73
70
$template->param(SCRIPT_NAME => $ENV{'SCRIPT_NAME'},
74
$template->param(
71
						uploadmarc => $fileID);
75
    SCRIPT_NAME => $ENV{'SCRIPT_NAME'},
76
    uploadmarc  => $fileID
77
);
72
78
73
my %cookies = parse CGI::Cookie($cookie);
79
my %cookies = parse CGI::Cookie($cookie);
74
my $sessionID = $cookies{'CGISESSID'}->value;
80
my $sessionID = $cookies{'CGISESSID'}->value;
Lines 128-139 if ($completedJobID) { Link Here
128
    # FIXME branch code
134
    # FIXME branch code
129
    my ( $batch_id, $num_valid, $num_items, @import_errors ) =
135
    my ( $batch_id, $num_valid, $num_items, @import_errors ) =
130
      BatchStageMarcRecords(
136
      BatchStageMarcRecords(
131
        $record_type,                $encoding,
137
        $record_type,    $encoding,
132
        $marcrecord,                 $filename,
138
        $marcrecord,     $filename,
133
        $marc_modification_template, $comments,
139
        $to_marc_plugin, $marc_modification_template,
134
        '',                          $parse_items,
140
        $comments,       '',
135
        0,                           50,
141
        $parse_items,    0,
136
        staging_progress_callback( $job, $dbh )
142
        50, staging_progress_callback( $job, $dbh )
137
      );
143
      );
138
144
139
    my $num_with_matches = 0;
145
    my $num_with_matches = 0;
Lines 186-200 if ($completedJobID) { Link Here
186
192
187
} else {
193
} else {
188
    # initial form
194
    # initial form
189
    if (C4::Context->preference("marcflavour") eq "UNIMARC") {
195
    if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) {
190
        $template->param("UNIMARC" => 1);
196
        $template->param( "UNIMARC" => 1 );
191
    }
197
    }
192
    my @matchers = C4::Matcher::GetMatcherList();
198
    my @matchers = C4::Matcher::GetMatcherList();
193
    $template->param(available_matchers => \@matchers);
199
    $template->param( available_matchers => \@matchers );
194
200
195
    my @templates = GetModificationTemplates();
201
    my @templates = GetModificationTemplates();
196
    $template->param( MarcModificationTemplatesLoop => \@templates );
202
    $template->param( MarcModificationTemplatesLoop => \@templates );
197
203
204
    my @plugins = Koha::Plugins->new()->GetPlugins('to_marc');
205
    $template->param( plugins => \@plugins );
198
}
206
}
199
207
200
output_html_with_http_headers $input, $cookie, $template->output;
208
output_html_with_http_headers $input, $cookie, $template->output;
201
- 

Return to bug 12412