From 415ea18007f58ee5d616de41cdef437d49568cc9 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Sun, 17 Apr 2011 18:15:51 -0400 Subject: [PATCH] Bug 5859: Allow user to set encoding for import Rather than having options for MARC21 and UNIMARC in the "Character encoding" dropdown, the user should be able to select the appropriate character encoding. The default retains the current behavior, which is to allow the system to guess which character encoding is in use. However, it should be noticed that this is almost always wrong for non-UTF8 records with non-ASCII characters. Specifying a character set is much more reliable if you're not using UTF-8. Rebased to use Template::Toolkit instead of HTML::Template::Pro. Signed-off-by: Jared Camins-Esakov Signed-off-by: Nicole C. Engard Signed-off-by: Chris Cormack --- C4/ImportBatch.pm | 11 +++++++---- .../prog/en/modules/tools/stage-marc-import.tt | 9 ++------- tools/stage-marc-import.pl | 8 ++++---- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 145e5d90a4..b6db4067c6 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -210,7 +210,7 @@ sub ModBiblioInBatch { =head2 BatchStageMarcRecords ($batch_id, $num_records, $num_items, @invalid_records) = - BatchStageMarcRecords($marc_flavor, $marc_records, $file_name, + BatchStageMarcRecords($encoding, $marc_records, $file_name, $comments, $branch_code, $parse_items, $leave_as_staging, $progress_interval, $progress_callback); @@ -218,7 +218,7 @@ sub ModBiblioInBatch { =cut sub BatchStageMarcRecords { - my $marc_flavor = shift; + my $encoding = shift; my $marc_records = shift; my $file_name = shift; my $comments = shift; @@ -258,13 +258,16 @@ sub BatchStageMarcRecords { &$progress_callback($rec_num); } my ($marc_record, $charset_guessed, $char_errors) = - MarcToUTF8Record($marc_blob, C4::Context->preference("marcflavour")); + MarcToUTF8Record($marc_blob, C4::Context->preference("marcflavour"), $encoding); + + $encoding = $charset_guessed unless $encoding; + my $import_record_id; if (scalar($marc_record->fields()) == 0) { push @invalid_records, $marc_blob; } else { $num_valid++; - $import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $marc_flavor, int(rand(99999)), 0); + $import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0); if ($parse_items) { my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 0); $num_items += scalar(@import_items_ids); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt index f44181ee9f..fc6db51f20 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt @@ -93,13 +93,8 @@ function CheckForm(f) {
  • - - [% IF ( UNIMARC ) %] - - [% ELSE %] - - [% END %] - + +
  • diff --git a/tools/stage-marc-import.pl b/tools/stage-marc-import.pl index b113332375..745a36adb8 100755 --- a/tools/stage-marc-import.pl +++ b/tools/stage-marc-import.pl @@ -55,7 +55,7 @@ my $nomatch_action = $input->param('nomatch_action'); my $parse_items = $input->param('parse_items'); my $item_action = $input->param('item_action'); my $comments = $input->param('comments'); -my $syntax = $input->param('syntax'); +my $encoding = $input->param('encoding'); my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "tools/stage-marc-import.tmpl", query => $input, @@ -130,10 +130,10 @@ if ($completedJobID) { } # FIXME branch code - my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($syntax, $marcrecord, $filename, - $comments, '', $parse_items, 0, - 50, staging_progress_callback($job, $dbh)); + my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($encoding, $marcrecord, $filename, $comments, '', $parse_items, 0, 50, staging_progress_callback($job, $dbh)); + $dbh->commit(); + my $num_with_matches = 0; my $checked_matches = 0; my $matcher_failed = 0; -- 2.39.5