making mig-loadbibs a bit more defensive with marc-8 data
authorRogan Hamby <rhamby@esilibrary.com>
Thu, 19 Apr 2018 20:02:06 +0000 (16:02 -0400)
committerRogan Hamby <rhamby@esilibrary.com>
Thu, 19 Apr 2018 20:02:06 +0000 (16:02 -0400)
mig-bin/mig-loadbibs

index 1d2e4fb..d206a3e 100755 (executable)
@@ -39,6 +39,7 @@ use MARC::Record;
 use MARC::Batch;
 use MARC::File;
 use MARC::File::XML;
+use MARC::Charset 'marc8_to_utf8';
 binmode STDIN, ':bytes';
 use Env qw(
     HOME PGHOST PGPORT PGUSER PGDATABASE MIGSCHEMA
@@ -68,6 +69,12 @@ my $i = 0;
 my $batch;
 binmode STDIN, ':utf8';
 
+my $ignore = MARC::Charset->ignore_errors();    
+MARC::Charset->ignore_errors(1);
+my $setting = MARC::Charset->assume_unicode();
+MARC::Charset->assume_unicode(1); 
+MARC::Charset->ignore_errors(1);
+
 foreach my $arg (@ARGV) {
     if ($arg eq '--stage_file') {
         $next_arg_is_file = 1;
@@ -174,6 +181,7 @@ sub create_child_table {
 
 sub clean_marc {
     my $xml = shift;
+    $xml = marc8_to_utf8($xml);
     $xml =~ s/\n//sog;
     $xml =~ s/^<\?xml.+\?\s*>//go;
     $xml =~ s/>\s+</></go;