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

(-)a/C4/ImportBatch.pm (-13 / +12 lines)
Lines 404-410 sub BatchStageMarcRecords { Link Here
404
            method => 'to_marc',
404
            method => 'to_marc',
405
            params => { data => $marc_records }
405
            params => { data => $marc_records }
406
        }
406
        }
407
    ) if $to_marc_plugin;
407
    ) if $to_marc_plugin && @$marc_records;
408
408
409
    my $marc_type = C4::Context->preference('marcflavour');
409
    my $marc_type = C4::Context->preference('marcflavour');
410
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
410
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
Lines 1473-1483 Reads ISO2709 binary porridge from the given file and creates MARC::Record-objec Link Here
1473
@PARAM2, String, see stage_file.pl
1473
@PARAM2, String, see stage_file.pl
1474
@PARAM3, String, should be utf8
1474
@PARAM3, String, should be utf8
1475
1475
1476
Returns two array refs.
1477
1476
=cut
1478
=cut
1477
1479
1478
sub RecordsFromISO2709File {
1480
sub RecordsFromISO2709File {
1479
    my ($input_file, $record_type, $encoding) = @_;
1481
    my ($input_file, $record_type, $encoding) = @_;
1480
    my $errors;
1482
    my @errors;
1481
1483
1482
    my $marc_type = C4::Context->preference('marcflavour');
1484
    my $marc_type = C4::Context->preference('marcflavour');
1483
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
1485
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
Lines 1493-1532 sub RecordsFromISO2709File { Link Here
1493
        my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding);
1495
        my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding);
1494
        push @marc_records, $marc_record;
1496
        push @marc_records, $marc_record;
1495
        if ($charset_guessed ne $encoding) {
1497
        if ($charset_guessed ne $encoding) {
1496
            $errors = '' unless $errors;
1498
            push @errors,
1497
            $errors .= "Unexpected charset $charset_guessed, expecting $encoding\n";
1499
                "Unexpected charset $charset_guessed, expecting $encoding";
1498
        }
1500
        }
1499
    }
1501
    }
1500
    close IN;
1502
    close IN;
1501
    return ($errors, \@marc_records);
1503
    return ( \@errors, \@marc_records );
1502
}
1504
}
1503
1505
1504
=head2 RecordsFromMARCXMLFile
1506
=head2 RecordsFromMARCXMLFile
1505
1507
1506
    my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding);
1508
    my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding);
1507
1509
1508
1509
1510
Creates MARC::Record-objects out of the given MARCXML-file.
1510
Creates MARC::Record-objects out of the given MARCXML-file.
1511
1511
1512
@PARAM1, String, absolute path to the ISO2709 file.
1512
@PARAM1, String, absolute path to the ISO2709 file.
1513
@PARAM2, String, should be utf8
1513
@PARAM2, String, should be utf8
1514
1514
1515
Returns two array refs.
1516
1515
=cut
1517
=cut
1516
1518
1517
sub RecordsFromMARCXMLFile {
1519
sub RecordsFromMARCXMLFile {
1518
    my ( $filename, $encoding ) = @_;
1520
    my ( $filename, $encoding ) = @_;
1519
    my $batch = MARC::File::XML->in( $filename );
1521
    my $batch = MARC::File::XML->in( $filename );
1520
    my @marcRecords;
1522
    my ( @marcRecords, @errors, $record );
1521
    my @errors;
1522
    do {
1523
    do {
1523
        eval {
1524
        eval { $record = $batch->next( $encoding ); };
1524
            my $record = $batch->next($encoding);
1525
            push @marcRecords, $record if $record;
1526
        };
1527
        if ($@) {
1525
        if ($@) {
1528
            push @errors, $@;
1526
            push @errors, $@;
1529
        }
1527
        }
1528
        push @marcRecords, $record if $record;
1530
    } while( $record );
1529
    } while( $record );
1531
    return (\@errors, \@marcRecords);
1530
    return (\@errors, \@marcRecords);
1532
}
1531
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt (-1 / +12 lines)
Lines 68-73 function cbUpload( status, fileid ) { Link Here
68
        $('#fileuploadbutton').prop('disabled',true);
68
        $('#fileuploadbutton').prop('disabled',true);
69
        $('#fileuploadbutton').show();
69
        $('#fileuploadbutton').show();
70
        $("#fileuploadcancel").hide();
70
        $("#fileuploadcancel").hide();
71
        var filename=$('#fileToUpload').prop('files')[0].name;
72
        if( filename.match( new RegExp(/\.[^.]+xml$/) ) ) {
73
            $('#format').val('MARCXML');
74
        }
71
        $("#processfile").show();
75
        $("#processfile").show();
72
    } else {
76
    } else {
73
        $('#fileuploadbutton').show();
77
        $('#fileuploadbutton').show();
Lines 183-189 function cbUpload( status, fileid ) { Link Here
183
	<li>
187
	<li>
184
		<label for="encoding">Character encoding: </label>
188
		<label for="encoding">Character encoding: </label>
185
            <select name="encoding" id="encoding">
189
            <select name="encoding" id="encoding">
186
                <option value="utf8" selected="selected">UTF-8 (Default)</option>
190
                <option value="UTF-8" selected="selected">UTF-8 (Default)</option>
187
                <option value="MARC-8">MARC 8</option>
191
                <option value="MARC-8">MARC 8</option>
188
                <option value="ISO_5426">ISO 5426</option>
192
                <option value="ISO_5426">ISO 5426</option>
189
                <option value="ISO_6937">ISO 6937</option>
193
                <option value="ISO_6937">ISO 6937</option>
Lines 191-196 function cbUpload( status, fileid ) { Link Here
191
                <option value="EUC-KR">EUC-KR</option>
195
                <option value="EUC-KR">EUC-KR</option>
192
            </select>
196
            </select>
193
	</li>
197
	</li>
198
    <li>
199
        <label for='format'>Format:</label>
200
        <select name='format' id='format'>
201
            <option value='ISO2709'>MARC</option>
202
            <option value='MARCXML'>MARCXML</option>
203
        </select>
204
    </li>
194
</ol></fieldset>
205
</ol></fieldset>
195
206
196
  [% IF plugins %]
207
  [% IF plugins %]
(-)a/misc/stage_file.pl (-9 / +6 lines)
Lines 37-43 $| = 1; Link Here
37
37
38
# command-line parameters
38
# command-line parameters
39
my $record_type = "biblio";
39
my $record_type = "biblio";
40
my $encoding = "";
40
my $encoding = "UTF-8";
41
my $authorities = 0;
41
my $authorities = 0;
42
my $match = 0;
42
my $match = 0;
43
my $add_items = 0;
43
my $add_items = 0;
Lines 65-74 my $result = GetOptions( Link Here
65
65
66
$record_type = 'auth' if ($authorities);
66
$record_type = 'auth' if ($authorities);
67
67
68
if ($encoding eq "") {
69
    $encoding = "utf8";
70
}
71
72
if (not $result or $input_file eq "" or $want_help) {
68
if (not $result or $input_file eq "" or $want_help) {
73
    print_usage();
69
    print_usage();
74
    exit 0;
70
    exit 0;
Lines 93-101 exit 0; Link Here
93
sub process_batch {
89
sub process_batch {
94
    my ($format, $input_file, $record_type, $match, $add_items, $batch_comment) = @_;
90
    my ($format, $input_file, $record_type, $match, $add_items, $batch_comment) = @_;
95
91
96
    my ($errors, $marc_records) = C4::ImportBatch::RecordsFromISO2709File($input_file, $record_type, $encoding) if $format eq 'ISO2709';
92
    my ( $errors, $marc_records );
97
    warn $errors if $errors;
93
    ( $errors, $marc_records ) = C4::ImportBatch::RecordsFromISO2709File($input_file, $record_type, $encoding) if $format eq 'ISO2709';
98
    $marc_records = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding) if $format eq 'MARCXML';
94
    ( $errors, $marc_records ) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding) if $format eq 'MARCXML';
95
    warn ( join ',', @$errors ) if @$errors;
99
    my $num_input_records = ($marc_records) ? scalar(@$marc_records) : 0;
96
    my $num_input_records = ($marc_records) ? scalar(@$marc_records) : 0;
100
97
101
    print "... staging MARC records -- please wait\n";
98
    print "... staging MARC records -- please wait\n";
Lines 176-182 records into the main Koha database. Link Here
176
Parameters:
173
Parameters:
177
    --file <file_name>      name of input MARC bib file
174
    --file <file_name>      name of input MARC bib file
178
    --authorities           stage authority records instead of bibs
175
    --authorities           stage authority records instead of bibs
179
    --encoding <encoding>   encoding of MARC records, default is utf8.
176
    --encoding <encoding>   encoding of MARC records, default is UTF-8.
180
                            Other possible options are: MARC-8,
177
                            Other possible options are: MARC-8,
181
                            ISO_5426, ISO_6937, ISO_8859-1, EUC-KR
178
                            ISO_5426, ISO_6937, ISO_8859-1, EUC-KR
182
    --format                The MARC transport format to use?
179
    --format                The MARC transport format to use?
(-)a/tools/stage-marc-import.pl (-5 / +11 lines)
Lines 56-62 my $parse_items = $input->param('parse_items'); Link Here
56
my $item_action                = $input->param('item_action');
56
my $item_action                = $input->param('item_action');
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') || 'utf8';
59
my $encoding                   = $input->param('encoding') || 'UTF-8';
60
my $format                     = $input->param('format') || 'ISO2709';
60
my $format                     = $input->param('format') || 'ISO2709';
61
my $to_marc_plugin             = $input->param('to_marc_plugin');
61
my $to_marc_plugin             = $input->param('to_marc_plugin');
62
my $marc_modification_template = $input->param('marc_modification_template_id');
62
my $marc_modification_template = $input->param('marc_modification_template_id');
Lines 86-94 if ($completedJobID) { Link Here
86
    $template->param(map { $_ => $results->{$_} } keys %{ $results });
86
    $template->param(map { $_ => $results->{$_} } keys %{ $results });
87
} elsif ($fileID) {
87
} elsif ($fileID) {
88
    my $upload = Koha::Upload->new->get({ id => $fileID });
88
    my $upload = Koha::Upload->new->get({ id => $fileID });
89
    my $filename = $upload->{path};
89
    my ( $file, $filename ) = ( $upload->{path}, $upload->{name} );
90
	my $marcrecord='';
90
    my ( $errors, $marcrecords );
91
    my ($errors, $marcrecords) = C4::ImportBatch::RecordsFromISO2709File($uploaded_file->filename(), $record_type, $encoding);
91
    if( $format eq 'MARCXML' ) {
92
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $encoding);
93
    } else {
94
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding );
95
    }
96
    warn "$filename: " . ( join ',', @$errors ) if @$errors;
97
        # no need to exit if we have no records (or only errors) here
98
        # BatchStageMarcRecords can handle that
92
99
93
    my $job = undef;
100
    my $job = undef;
94
    my $dbh;
101
    my $dbh;
95
- 

Return to bug 10407