From 349afe78eed0e1b6ad4d228b28e0d7cfb38a475b Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Mon, 14 Sep 2009 15:13:45 +0200 Subject: [PATCH] Bug fix : 3618 Add some error proof on BuildUnimarcHierarchies --- C4/AuthoritiesMarc.pm | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 3be5ee4b52..a4237387c5 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -1164,26 +1164,28 @@ sub BuildUnimarcHierarchies{ } else { my $record = GetAuthority($authid); my $found; - foreach my $field ($record->field('550')){ - if ($field->subfield('5') && $field->subfield('5') eq 'g'){ - my $parentrecord = GetAuthority($field->subfield('3')); - my $localresult=$hierarchies; - my $trees; - $trees = BuildUnimarcHierarchies($field->subfield('3')); - my @trees; - if ($trees=~/;/){ - @trees = split(/;/,$trees); - } else { - push @trees, $trees; - } - foreach (@trees){ - $_.= ",$authid"; - } - @globalresult = (@globalresult,@trees); - $found=1; - } - $hierarchies=join(";",@globalresult); - } + if ($record){ + foreach my $field ($record->field('550')){ + if ($field->subfield('5') && $field->subfield('5') eq 'g'){ + my $parentrecord = GetAuthority($field->subfield('3')); + my $localresult=$hierarchies; + my $trees; + $trees = BuildUnimarcHierarchies($field->subfield('3')); + my @trees; + if ($trees=~/;/){ + @trees = split(/;/,$trees); + } else { + push @trees, $trees; + } + foreach (@trees){ + $_.= ",$authid"; + } + @globalresult = (@globalresult,@trees); + $found=1; + } + $hierarchies=join(";",@globalresult); + } + } #Unless there is no ancestor, I am alone. $hierarchies="$authid" unless ($hierarchies); } @@ -1217,6 +1219,7 @@ sub BuildUnimarcHierarchy{ my $record = shift @_; my $class = shift @_; my $authid_constructed = shift @_; + return undef unless ($record); my $authid=$record->subfield('2..','3'); my %cell; my $parents=""; my $children=""; -- 2.39.5