From 706a881b7fc12a0700affd55c289eeffe415a49a Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Tue, 5 Apr 2011 10:50:42 +0200 Subject: [PATCH] Bug 5914 : BuildUnimarchierarchies can go into an infinite loop Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit commit 58e18dfa4109fcdde3c71675ff07ed6aae86b258 Author: Henri-Damien LAURENT Date: Tue May 18 16:54:49 2010 +0200 Bug 5914 : followup BuildUnimarchierarchies fixing infinite loop commit bbbcb7fcb0ff36eb8a072d9b0442996e71ebb247 Author: Henri-Damien LAURENT Date: Tue May 18 13:11:44 2010 +0200 Bug 5914 : BuildUnimarcHierarchies : Fixing infinite loop When referenced authority in 5XX$3 would be the same as the current authid, the script would get into infinite loop Conflicts solved: C4/AuthoritiesMarc.pm commit 3581021997bc8965af807738c47d5fd27f2fd97f Author: Henri-Damien LAURENT Date: Wed Apr 7 15:15:59 2010 +0200 Bug 5914 : BuildUnimarcHierarchies : Fixing infinite loop When referenced authority in 5XX$3 would be the same as the current authid, the script would get into infinite loop Signed-off-by: Stéphane Delaune Signed-off-by: Jonathan Druart Signed-off-by: Chris Cormack --- C4/AuthoritiesMarc.pm | 66 ++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 0122ca88b3..d06ffc423a 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -1125,33 +1125,34 @@ sub BuildUnimarcHierarchies{ my $data = GetHeaderAuthority($authid); if ($data->{'authtrees'} and not $force){ return $data->{'authtrees'}; - } elsif ($data->{'authtrees'}){ - $hierarchies=$data->{'authtrees'}; +# } elsif ($data->{'authtrees'}){ +# $hierarchies=$data->{'authtrees'}; } else { my $record = GetAuthority($authid); my $found; - 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); - } - } + return unless $record; + foreach my $field ($record->field('5..')){ + if ($field->subfield('5') && $field->subfield('5') eq 'g'){ + my $subfauthid=_get_authid_subfield($field); + next if ($subfauthid eq $authid); + my $parentrecord = GetAuthority($subfauthid); + my $localresult=$hierarchies; + my $trees; + $trees = BuildUnimarcHierarchies($subfauthid); + 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); } @@ -1188,15 +1189,16 @@ sub BuildUnimarcHierarchy{ my $parents=""; my $children=""; my (@loopparents,@loopchildren); foreach my $field ($record->field('5..')){ - my $subfauthid=_get_authid_subfield($field); - if ($field->subfield('5') && $field->subfield('a')){ - if ($field->subfield('5') eq 'h'){ - push @loopchildren, { "childauthid"=>$subfauthid,"childvalue"=>$field->subfield('a')}; - }elsif ($field->subfield('5') eq 'g'){ - push @loopparents, { "parentauthid"=>$subfauthid,"parentvalue"=>$field->subfield('a')}; - } + my $subfauthid=_get_authid_subfield($field); + if ($subfauthid && $field->subfield('5') && $field->subfield('a')){ + if ($field->subfield('5') eq 'h'){ + push @loopchildren, { "childauthid"=>$field->subfield('3'),"childvalue"=>$field->subfield('a')}; + } + elsif ($field->subfield('5') eq 'g'){ + push @loopparents, { "parentauthid"=>$field->subfield('3'),"parentvalue"=>$field->subfield('a')}; + } # brothers could get in there with an else - } + } } $cell{"ifparents"}=1 if (scalar(@loopparents)>0); $cell{"ifchildren"}=1 if (scalar(@loopchildren)>0); -- 2.39.5