Merge remote-tracking branch 'kc/new/bug_5683' into kcmaster
authorChris Cormack <chrisc@catalyst.net.nz>
Wed, 1 Jun 2011 21:12:29 +0000 (09:12 +1200)
committerChris Cormack <chrisc@catalyst.net.nz>
Wed, 1 Jun 2011 21:12:29 +0000 (09:12 +1200)
C4/Biblio.pm [changed mode: 0755->0644]
t/db_dependent/Biblio.t

old mode 100755 (executable)
new mode 100644 (file)
index c9590c2..016b53d
@@ -299,6 +299,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;
 
@@ -306,14 +316,6 @@ sub ModBiblio {
 
     _strip_item_fields($record, $frameworkcode);
 
-    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
index 6012f5f..dd827f0 100755 (executable)
@@ -5,7 +5,7 @@
 
 use strict;
 use warnings;
-use Test::More tests => 6;
+use Test::More tests => 9;
 use MARC::Record;
 use C4::Biblio;
 
@@ -34,6 +34,40 @@ my $itemdata = &GetBiblioItemData($biblioitemnumber);
 is($itemdata->{title},$title,'First test of GetBiblioItemData to get same result of previous two GetBiblioData tests.');
 is($itemdata->{isbn},$isbn,'Second test checking it returns the correct isbn.');
 
+my $success = 0;
+$field = MARC::Field->new(
+        655, ' ', ' ',
+        'a' => 'Auction catalogs',
+        '9' => '1'
+        );
+eval {
+    $marc_record->append_fields($field);
+    $success = ModBiblio($marc_record,$biblionumber,'');
+} or do {
+    diag($@);
+    $success = 0;
+};
+ok($success, "ModBiblio handles authority-linked 655");
+
+eval {
+    $field->delete_subfields('a');
+    $marc_record->append_fields($field);
+    $success = ModBiblio($marc_record,$biblionumber,'');
+} or do {
+    diag($@);
+    $success = 0;
+};
+ok($success, "ModBiblio handles 655 with authority link but no heading");
+
+eval {
+    $field->delete_subfields('9');
+    $marc_record->append_fields($field);
+    $success = ModBiblio($marc_record,$biblionumber,'');
+} or do {
+    diag($@);
+    $success = 0;
+};
+ok($success, "ModBiblio handles 655 with no subfields");
 
 # clean up after ourselves
 DelBiblio($biblionumber);