[Koha-patches] [PATCH 1/2] Bug 5683 follow-up: calls to ModBiblio can still fail

Jared Camins-Esakov jcamins at bywatersolutions.com
Wed Apr 6 16:08:43 CEST 2011


Because C4::Charset directly manipulates the MARC::Record object, bad data has
to be cleaned in ModBiblio before the call into C4::Charset. The corrupted
records can also break the Zebra index. After this fix has been applied, it
would probably be a good idea to run the misc/maintenance/touch_all_biblios.pl
script to ensure that this problem has been cleared up.
---
 C4/Biblio.pm |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index a0e06f6..44330ec 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -295,6 +295,16 @@ sub ModBiblio {
         logaction( "CATALOGUING", "MODIFY", $biblionumber, "BEFORE=>" . $newrecord->as_formatted );
     }
 
+    # Cleaning up invalid fields must be done early or SetUTF8Flag is liable to
+    # throw an exception which probably won't be handled.
+    foreach my $field ($record->fields()) {
+        if (! $field->is_control_field()) {
+            if (scalar($field->subfields()) == 0 || (scalar($field->subfields()) == 1 && $field->subfield('9'))) {
+                $record->delete_field($field);
+            }
+        }
+    }
+
     SetUTF8Flag($record);
     my $dbh = C4::Context->dbh;
 
@@ -334,14 +344,6 @@ sub ModBiblio {
         $record->append_fields($field);
     }
 
-    foreach my $field ($record->fields()) {
-        if (! $field->is_control_field()) {
-            if (scalar($field->subfields()) == 0) {
-                $record->delete_fields($field);
-            }
-        }
-    }
-
     # update biblionumber and biblioitemnumber in MARC
     # FIXME - this is assuming a 1 to 1 relationship between
     # biblios and biblioitems
-- 
1.7.2.3



More information about the Koha-patches mailing list