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

(-)a/C4/ImportBatch.pm (-7 / +38 lines)
Lines 399-411 sub BatchStageMarcRecords { Link Here
399
        SetImportBatchItemAction($batch_id, 'ignore');
399
        SetImportBatchItemAction($batch_id, 'ignore');
400
    }
400
    }
401
401
402
    $marc_records = Koha::Plugins::Handler->run(
403
        {
404
            class  => $to_marc_plugin,
405
            method => 'to_marc',
406
            params => { data => $marc_records }
407
        }
408
    ) if $to_marc_plugin && @$marc_records;
409
402
410
    my $marc_type = C4::Context->preference('marcflavour');
403
    my $marc_type = C4::Context->preference('marcflavour');
411
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
404
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
Lines 1556-1561 sub RecordsFromMARCXMLFile { Link Here
1556
    return (\@errors, \@marcRecords);
1549
    return (\@errors, \@marcRecords);
1557
}
1550
}
1558
1551
1552
=head2 RecordsFromMarcPlugin
1553
1554
    Converts text of input_file into array of MARC records with to_marc plugin
1555
1556
=cut
1557
1558
sub RecordsFromMarcPlugin {
1559
    my ($input_file, $plugin_class, $encoding) = @_;
1560
1561
    # Read input file
1562
    open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
1563
    my ( $text, $marc, @return );
1564
    $/ = "\035";
1565
    while (<IN>) {
1566
        s/^\s+//;
1567
        s/\s+$//;
1568
        next unless $_;
1569
        $text .= $_;
1570
    }
1571
    close IN;
1572
1573
    # Convert to large MARC blob with plugin
1574
    $text = Koha::Plugins::Handler->run({
1575
        class  => $plugin_class,
1576
        method => 'to_marc',
1577
        params => { data => $text },
1578
    });
1579
1580
    # Convert to array of MARC records
1581
    my $marc_type = C4::Context->preference('marcflavour');
1582
    foreach my $blob ( split(/\x1D/, $text) ) {
1583
        next if $blob =~ /^\s*$/;
1584
        my ($marcrecord) = MarcToUTF8Record($blob, $marc_type, $encoding);
1585
        push @return, $marcrecord;
1586
    }
1587
    return \@return;
1588
}
1589
1559
# internal functions
1590
# internal functions
1560
1591
1561
sub _create_import_record {
1592
sub _create_import_record {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt (-17 / +3 lines)
Lines 198-224 function cbUpload( status, fileid ) { Link Here
198
        <select name='format' id='format'>
198
        <select name='format' id='format'>
199
            <option value='ISO2709'>MARC</option>
199
            <option value='ISO2709'>MARC</option>
200
            <option value='MARCXML'>MARCXML</option>
200
            <option value='MARCXML'>MARCXML</option>
201
            [% FOREACH p IN plugins %]
202
                <option value="[% p.metadata.class %]">Other formats, handled by plugin [% p.metadata.name %]</option>
203
            [% END %]
201
        </select>
204
        </select>
202
    </li>
205
    </li>
203
</ol></fieldset>
206
</ol></fieldset>
204
207
205
  [% IF plugins %]
206
    <fieldset class="rows">
207
      <legend>Transform file to MARC:</legend>
208
      <ol>
209
        <li>
210
          <label for="comments">Convert file to MARC using the following plugin: </label>
211
          <select name="to_marc_plugin" id="to_marc_plugin">
212
            <option value="">Do not use.</option>
213
              [% FOREACH p IN plugins %]
214
                <option value="[% p.metadata.class %]">[% p.metadata.name %]</option>
215
              [% END %]
216
          </select>
217
        </li>
218
      </ol>
219
    </fieldset>
220
  [% END %]
221
222
  [% IF MarcModificationTemplatesLoop %]
208
  [% IF MarcModificationTemplatesLoop %]
223
    <fieldset class="rows">
209
    <fieldset class="rows">
224
      <legend>Use MARC Modification Template:</legend>
210
      <legend>Use MARC Modification Template:</legend>
(-)a/tools/stage-marc-import.pl (-5 / +9 lines)
Lines 57-64 my $item_action = $input->param('item_action'); Link Here
57
my $comments                   = $input->param('comments');
57
my $comments                   = $input->param('comments');
58
my $record_type                = $input->param('record_type');
58
my $record_type                = $input->param('record_type');
59
my $encoding                   = $input->param('encoding') || 'UTF-8';
59
my $encoding                   = $input->param('encoding') || 'UTF-8';
60
my $format                     = $input->param('format') || 'ISO2709';
60
my $format                     = $input->param('format');
61
my $to_marc_plugin             = $input->param('to_marc_plugin');
62
my $marc_modification_template = $input->param('marc_modification_template_id');
61
my $marc_modification_template = $input->param('marc_modification_template_id');
63
62
64
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 90-99 if ($completedJobID) { Link Here
90
    my $filename = $upload->filename;
89
    my $filename = $upload->filename;
91
90
92
    my ( $errors, $marcrecords );
91
    my ( $errors, $marcrecords );
92
warn "L92 $format";
93
    if( $format eq 'MARCXML' ) {
93
    if( $format eq 'MARCXML' ) {
94
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $encoding);
94
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $encoding);
95
    } else {
95
    } elsif( $format eq 'MARC' ) {
96
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding );
96
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding );
97
    } elsif( $format ) { # plugin
98
        $errors = [];
99
        $marcrecords = C4::ImportBatch::RecordsFromMarcPlugin( $file, $format, $encoding );
100
    } else {
101
        die "No format specified";
97
    }
102
    }
98
    warn "$filename: " . ( join ',', @$errors ) if @$errors;
103
    warn "$filename: " . ( join ',', @$errors ) if @$errors;
99
        # no need to exit if we have no records (or only errors) here
104
        # no need to exit if we have no records (or only errors) here
Lines 141-147 if ($completedJobID) { Link Here
141
      BatchStageMarcRecords(
146
      BatchStageMarcRecords(
142
        $record_type,    $encoding,
147
        $record_type,    $encoding,
143
        $marcrecords,    $filename,
148
        $marcrecords,    $filename,
144
        $to_marc_plugin, $marc_modification_template,
149
        undef, $marc_modification_template,
145
        $comments,       '',
150
        $comments,       '',
146
        $parse_items,    0,
151
        $parse_items,    0,
147
        50, staging_progress_callback( $job, $dbh )
152
        50, staging_progress_callback( $job, $dbh )
148
- 

Return to bug 19049