From a2e3be34626fa1f69b53c9fd285a50bc33507d55 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Mon, 21 Jan 2008 14:14:38 -0600 Subject: [PATCH] prevent AddItem death if no marcrecord is given. Signed-off-by: Joshua Ferraro --- C4/Items.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index ce01ea5619..bc5a56a07c 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1913,12 +1913,16 @@ sub _add_unlinked_marc_fields{ my $tmp_item_marc=$new_item_marc->clone; my $marcstructure=GetMarcStructure(1,$frameworkcode); foreach my $field ($item_marc_record->fields()){ - if ($new_item_marc->fields($field->tag())){ + my $tag=$field->tag(); + if ($new_item_marc->fields($tag)){ # It is assumed that item marc records only have ***one*** tag and that this tag is mandatory. # So new_item_marc MUST have $field->tag foreach my $subfield ($field->subfields()){ - if (!$marcstructure->{$field->tag}->{$subfield->[0]}->{'kohafield'} && !$tmp_item_marc->subfield($field->tag,$subfield->[0])){ - $new_item_marc->field($field->tag)->add_subfields($subfield->[0]=>$subfield->[1]); + if (!$marcstructure->{$tag}->{$subfield->[0]}->{'kohafield'} && !$tmp_item_marc->subfield($tag,$subfield->[0])){ + #$new_item_marc->field($tag)->add_subfields($subfield->[0]=>$subfield->[1]); + + my $ret= eval {$new_item_marc->field($tag)->add_subfields($subfield->[0]=>$subfield->[1])}; + if ($@ or !$ret) {warn $subfield->[0]."=>".$subfield->[1]."\n".$new_item_marc->as_formatted."\n".$item_marc_record;} } } } -- 2.39.5