From d949472324b37b4484ec962bf96722c118a2bac2 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Wed, 6 Apr 2011 10:07:29 -0400 Subject: [PATCH 1/3] Add unit tests to ensure bug 5683 doesn't reappear Signed-off-by: Jared Camins-Esakov Signed-off-by: Chris Cormack Signed-off-by: Ian Walls --- t/db_dependent/Biblio.t | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t index 6012f5f80d..dd827f0c6c 100755 --- a/t/db_dependent/Biblio.t +++ b/t/db_dependent/Biblio.t @@ -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); From 5bbfb94f4399485a96c7f4478a3641da450926ca Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Wed, 6 Apr 2011 08:58:07 -0400 Subject: [PATCH 2/3] Bug 5683 follow-up: calls to ModBiblio can still fail 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. Signed-off-by: Jared Camins-Esakov Signed-off-by: Chris Cormack --- C4/Biblio.pm | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index c9590c27a7..016b53d98b 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -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 From 2468bab611e91a3e1d3477fecd8f4abc1b63a058 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Thu, 2 Jun 2011 09:05:37 +1200 Subject: [PATCH 3/3] Fixing permissions, no need for this file to be executable --- C4/Biblio.pm | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 C4/Biblio.pm diff --git a/C4/Biblio.pm b/C4/Biblio.pm old mode 100755 new mode 100644