From 2731d38c8784d1c9b8cec391fcb94f9a524eb3d2 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Sun, 9 Sep 2012 18:24:36 -0400 Subject: [PATCH] Bug 8523 follow-up: correctly handle leaves Content-Type: text/plain; charset="UTF-8" --- C4/AuthoritiesMarc.pm | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 64863ea..1c5a439 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -1248,7 +1248,7 @@ sub BuildAuthHierarchy{ $cell{"children"}=\@loopchildren; $cell{"class"}=$class; $cell{"authid"}=$authid; - $cell{"current_value"} =1 if $authid eq $authid_constructed; + $cell{"current_value"} =1 if ($authid eq $authid_constructed); $cell{"value"}=C4::Context->preference('marcflavour') eq 'UNIMARC' ? $record->subfield('2..',"a") : $record->subfield('1..', 'a'); return \%cell; } @@ -1275,7 +1275,18 @@ sub BuildAuthHierarchyBranch { if (scalar @$tree > 0) { my $nextBranch = BuildAuthHierarchyBranch($tree, $authid, ++$cnt); my $nextAuthid = $nextBranch->{authid}; - push @{$branch->{children}}, $nextBranch unless grep {$_->{authid} == $nextAuthid} @{$branch->{children}}; + my $found; + # If we already have the next branch listed as a child, let's + # replace the old listing with the new one. If not, we will add + # the branch at the end. + foreach my $cell (@{$branch->{children}}) { + if ($cell->{authid} eq $nextAuthid) { + $cell = $nextBranch; + $found = 1; + last; + } + } + push @{$branch->{children}}, $nextBranch unless $found; } return $branch; } -- 1.7.2.5