From 3ba1a82c22875dd4efc2320028773f32ab9228a3 Mon Sep 17 00:00:00 2001
From: dbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Tue, 13 Jul 2010 22:09:19 +0000
Subject: [PATCH] Be more relaxed about what we receive in Vandelay (a bad
 LDR/09 need not lead to complete misery)

If MARC::File::XML->as_xml_record() receives a record with anything other
than 'a' in LDR/09 position, it will try to run a MARC8-to-UTF8 conversion
on the record - even though the source file itself was XML and clearly
couldn't have been MARC8.

This code corrects the leader on the fly so that MARC::File::XML won't
try to convert it and throw a "wide character" warning, but the fix
means that something was wrong with the leader to begin with, so we also
write a warning to the log about the situation.


git-svn-id: svn://svn.open-ils.org/ILS/trunk@16925 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm b/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm
index 7e76d8c176..cea3c08bd8 100644
--- a/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm
+++ b/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm
@@ -280,6 +280,15 @@ sub process_spool {
         $logger->info("processing record $count");
 
         try {
+            # Avoid an over-eager MARC::File::XML that may try to convert
+            # our record from MARC8 to UTF8 and break because the record
+            # is obviously already UTF8
+            my $ldr = $r->leader();
+            if (($marctype eq 'XML') && (substr($ldr, 9, 1) ne 'a')) {
+                $logger->warn("MARCXML record LDR/09 was not 'a'; record leader may be corrupt");
+                substr($ldr,9,1,'a');
+                $r->leader($ldr);
+            }
             (my $xml = $r->as_xml_record()) =~ s/\n//sog;
             $xml =~ s/^<\?xml.+\?\s*>//go;
             $xml =~ s/>\s+</></go;
-- 
2.11.0