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

(-)a/C4/ImportBatch.pm (-10 / +40 lines)
Lines 352-359 sub ModAuthInBatch { Link Here
352
352
353
( $batch_id, $num_records, $num_items, @invalid_records ) =
353
( $batch_id, $num_records, $num_items, @invalid_records ) =
354
  BatchStageMarcRecords(
354
  BatchStageMarcRecords(
355
    $encoding,                   $marc_records,
355
    $record_type,                $encoding,
356
    $file_name,                  $to_marc_plugin,
356
    $marc_records,               $file_name,
357
    $marc_modification_template, $comments,
357
    $marc_modification_template, $comments,
358
    $branch_code,                $parse_items,
358
    $branch_code,                $parse_items,
359
    $leave_as_staging,           $progress_interval,
359
    $leave_as_staging,           $progress_interval,
Lines 367-373 sub BatchStageMarcRecords { Link Here
367
    my $encoding = shift;
367
    my $encoding = shift;
368
    my $marc_records = shift;
368
    my $marc_records = shift;
369
    my $file_name = shift;
369
    my $file_name = shift;
370
    my $to_marc_plugin = shift;
371
    my $marc_modification_template = shift;
370
    my $marc_modification_template = shift;
372
    my $comments = shift;
371
    my $comments = shift;
373
    my $branch_code = shift;
372
    my $branch_code = shift;
Lines 399-411 sub BatchStageMarcRecords { Link Here
399
        SetImportBatchItemAction($batch_id, 'ignore');
398
        SetImportBatchItemAction($batch_id, 'ignore');
400
    }
399
    }
401
400
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
401
410
    my $marc_type = C4::Context->preference('marcflavour');
402
    my $marc_type = C4::Context->preference('marcflavour');
411
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
403
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
Lines 1556-1561 sub RecordsFromMARCXMLFile { Link Here
1556
    return (\@errors, \@marcRecords);
1548
    return (\@errors, \@marcRecords);
1557
}
1549
}
1558
1550
1551
=head2 RecordsFromMarcPlugin
1552
1553
    Converts text of input_file into array of MARC records with to_marc plugin
1554
1555
=cut
1556
1557
sub RecordsFromMarcPlugin {
1558
    my ($input_file, $plugin_class, $encoding) = @_;
1559
1560
    # Read input file
1561
    open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
1562
    my ( $text, $marc, @return );
1563
    $/ = "\035";
1564
    while (<IN>) {
1565
        s/^\s+//;
1566
        s/\s+$//;
1567
        next unless $_;
1568
        $text .= $_;
1569
    }
1570
    close IN;
1571
1572
    # Convert to large MARC blob with plugin
1573
    $text = Koha::Plugins::Handler->run({
1574
        class  => $plugin_class,
1575
        method => 'to_marc',
1576
        params => { data => $text },
1577
    });
1578
1579
    # Convert to array of MARC records
1580
    my $marc_type = C4::Context->preference('marcflavour');
1581
    foreach my $blob ( split(/\x1D/, $text) ) {
1582
        next if $blob =~ /^\s*$/;
1583
        my ($marcrecord) = MarcToUTF8Record($blob, $marc_type, $encoding);
1584
        push @return, $marcrecord;
1585
    }
1586
    return \@return;
1587
}
1588
1559
# internal functions
1589
# internal functions
1560
1590
1561
sub _create_import_record {
1591
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/misc/stage_file.pl (-1 / +1 lines)
Lines 116-122 sub process_batch { Link Here
116
    print "... staging MARC records -- please wait\n";
116
    print "... staging MARC records -- please wait\n";
117
    #FIXME: We should really allow the use of marc modification frameworks and to_marc plugins here if possible
117
    #FIXME: We should really allow the use of marc modification frameworks and to_marc plugins here if possible
118
    my ($batch_id, $num_valid_records, $num_items, @import_errors) =
118
    my ($batch_id, $num_valid_records, $num_items, @import_errors) =
119
        BatchStageMarcRecords($record_type, $params->{encoding}, $marc_records, $params->{input_file}, undef, undef, $params->{batch_comment}, '', $params->{add_items}, 0,
119
        BatchStageMarcRecords($record_type, $params->{encoding}, $marc_records, $params->{input_file}, undef, $params->{batch_comment}, '', $params->{add_items}, 0,
120
                              100, \&print_progress_and_commit);
120
                              100, \&print_progress_and_commit);
121
    print "... finished staging MARC records\n";
121
    print "... finished staging MARC records\n";
122
122
(-)a/tools/stage-marc-import.pl (-5 / +8 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 92-99 if ($completedJobID) { Link Here
92
    my ( $errors, $marcrecords );
91
    my ( $errors, $marcrecords );
93
    if( $format eq 'MARCXML' ) {
92
    if( $format eq 'MARCXML' ) {
94
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $encoding);
93
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $encoding);
95
    } else {
94
    } elsif( $format eq 'MARC' ) {
96
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding );
95
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding );
96
    } elsif( $format ) { # plugin
97
        $errors = [];
98
        $marcrecords = C4::ImportBatch::RecordsFromMarcPlugin( $file, $format, $encoding );
99
    } else {
100
        die "No format specified";
97
    }
101
    }
98
    warn "$filename: " . ( join ',', @$errors ) if @$errors;
102
    warn "$filename: " . ( join ',', @$errors ) if @$errors;
99
        # no need to exit if we have no records (or only errors) here
103
        # no need to exit if we have no records (or only errors) here
Lines 141-147 if ($completedJobID) { Link Here
141
      BatchStageMarcRecords(
145
      BatchStageMarcRecords(
142
        $record_type,    $encoding,
146
        $record_type,    $encoding,
143
        $marcrecords,    $filename,
147
        $marcrecords,    $filename,
144
        $to_marc_plugin, $marc_modification_template,
148
        $marc_modification_template,
145
        $comments,       '',
149
        $comments,       '',
146
        $parse_items,    0,
150
        $parse_items,    0,
147
        50, staging_progress_callback( $job, $dbh )
151
        50, staging_progress_callback( $job, $dbh )
148
- 

Return to bug 19049