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

(-)a/C4/ImportBatch.pm (-13 / +12 lines)
Lines 405-411 sub BatchStageMarcRecords { Link Here
405
            method => 'to_marc',
405
            method => 'to_marc',
406
            params => { data => $marc_records }
406
            params => { data => $marc_records }
407
        }
407
        }
408
    ) if $to_marc_plugin;
408
    ) if $to_marc_plugin && @$marc_records;
409
409
410
    my $marc_type = C4::Context->preference('marcflavour');
410
    my $marc_type = C4::Context->preference('marcflavour');
411
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
411
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
Lines 1492-1502 Reads ISO2709 binary porridge from the given file and creates MARC::Record-objec Link Here
1492
@PARAM2, String, see stage_file.pl
1492
@PARAM2, String, see stage_file.pl
1493
@PARAM3, String, should be utf8
1493
@PARAM3, String, should be utf8
1494
1494
1495
Returns two array refs.
1496
1495
=cut
1497
=cut
1496
1498
1497
sub RecordsFromISO2709File {
1499
sub RecordsFromISO2709File {
1498
    my ($input_file, $record_type, $encoding) = @_;
1500
    my ($input_file, $record_type, $encoding) = @_;
1499
    my $errors;
1501
    my @errors;
1500
1502
1501
    my $marc_type = C4::Context->preference('marcflavour');
1503
    my $marc_type = C4::Context->preference('marcflavour');
1502
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
1504
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
Lines 1512-1551 sub RecordsFromISO2709File { Link Here
1512
        my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding);
1514
        my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding);
1513
        push @marc_records, $marc_record;
1515
        push @marc_records, $marc_record;
1514
        if ($charset_guessed ne $encoding) {
1516
        if ($charset_guessed ne $encoding) {
1515
            $errors = '' unless $errors;
1517
            push @errors,
1516
            $errors .= "Unexpected charset $charset_guessed, expecting $encoding\n";
1518
                "Unexpected charset $charset_guessed, expecting $encoding";
1517
        }
1519
        }
1518
    }
1520
    }
1519
    close IN;
1521
    close IN;
1520
    return ($errors, \@marc_records);
1522
    return ( \@errors, \@marc_records );
1521
}
1523
}
1522
1524
1523
=head2 RecordsFromMARCXMLFile
1525
=head2 RecordsFromMARCXMLFile
1524
1526
1525
    my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding);
1527
    my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding);
1526
1528
1527
1528
1529
Creates MARC::Record-objects out of the given MARCXML-file.
1529
Creates MARC::Record-objects out of the given MARCXML-file.
1530
1530
1531
@PARAM1, String, absolute path to the ISO2709 file.
1531
@PARAM1, String, absolute path to the ISO2709 file.
1532
@PARAM2, String, should be utf8
1532
@PARAM2, String, should be utf8
1533
1533
1534
Returns two array refs.
1535
1534
=cut
1536
=cut
1535
1537
1536
sub RecordsFromMARCXMLFile {
1538
sub RecordsFromMARCXMLFile {
1537
    my ( $filename, $encoding ) = @_;
1539
    my ( $filename, $encoding ) = @_;
1538
    my $batch = MARC::File::XML->in( $filename );
1540
    my $batch = MARC::File::XML->in( $filename );
1539
    my @marcRecords;
1541
    my ( @marcRecords, @errors, $record );
1540
    my @errors;
1541
    do {
1542
    do {
1542
        eval {
1543
        eval { $record = $batch->next( $encoding ); };
1543
            my $record = $batch->next($encoding);
1544
            push @marcRecords, $record if $record;
1545
        };
1546
        if ($@) {
1544
        if ($@) {
1547
            push @errors, $@;
1545
            push @errors, $@;
1548
        }
1546
        }
1547
        push @marcRecords, $record if $record;
1549
    } while( $record );
1548
    } while( $record );
1550
    return (\@errors, \@marcRecords);
1549
    return (\@errors, \@marcRecords);
1551
}
1550
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt (-1 / +12 lines)
Lines 66-71 function cbUpload( status, fileid ) { Link Here
66
        $('#fileuploadbutton').prop('disabled',true);
66
        $('#fileuploadbutton').prop('disabled',true);
67
        $('#fileuploadbutton').show();
67
        $('#fileuploadbutton').show();
68
        $("#fileuploadcancel").hide();
68
        $("#fileuploadcancel").hide();
69
        var filename=$('#fileToUpload').prop('files')[0].name;
70
        if( filename.match( new RegExp(/\.[^.]+xml$/) ) ) {
71
            $('#format').val('MARCXML');
72
        }
69
        $("#processfile").show();
73
        $("#processfile").show();
70
    } else {
74
    } else {
71
        $('#fileuploadbutton').show();
75
        $('#fileuploadbutton').show();
Lines 181-187 function cbUpload( status, fileid ) { Link Here
181
	<li>
185
	<li>
182
		<label for="encoding">Character encoding: </label>
186
		<label for="encoding">Character encoding: </label>
183
            <select name="encoding" id="encoding">
187
            <select name="encoding" id="encoding">
184
                <option value="utf8" selected="selected">UTF-8 (Default)</option>
188
                <option value="UTF-8" selected="selected">UTF-8 (Default)</option>
185
                <option value="MARC-8">MARC 8</option>
189
                <option value="MARC-8">MARC 8</option>
186
                <option value="ISO_5426">ISO 5426</option>
190
                <option value="ISO_5426">ISO 5426</option>
187
                <option value="ISO_6937">ISO 6937</option>
191
                <option value="ISO_6937">ISO 6937</option>
Lines 189-194 function cbUpload( status, fileid ) { Link Here
189
                <option value="EUC-KR">EUC-KR</option>
193
                <option value="EUC-KR">EUC-KR</option>
190
            </select>
194
            </select>
191
	</li>
195
	</li>
196
    <li>
197
        <label for='format'>Format:</label>
198
        <select name='format' id='format'>
199
            <option value='ISO2709'>MARC</option>
200
            <option value='MARCXML'>MARCXML</option>
201
        </select>
202
    </li>
192
</ol></fieldset>
203
</ol></fieldset>
193
204
194
  [% IF plugins %]
205
  [% 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