From 34c241d3fb58e2af4c54bd9d963c48ade4831093 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 18 Sep 2024 10:40:32 +0200 Subject: [PATCH] Bug 37953: (bug 35138 follow-up) Fix DisplayLibraryFacets - facet order Before bug 35138: DisplayLibraryFacets had priority over the settings in the mappings page. If you had DisplayLibraryFacets set to "holding library" (only) then only the holding library facet was displayed. On 231200036 we were not adjusting the facet order/appearance, but the label, which was wrong. The label must be adjusted for both facets and the order depending on DisplayLibraryFacets. Note that bug 37446 is adding a new db rev to adjust the label for installations that have been updated already. Test plan: 0. checkout c120975b783 (the commit right before 35138 has been pushed) 1. reset_all 2. holding library is set in DisplayLibraryFacets by default 3. checkout main (so without this patch) 4. updatedatabase => ES search result display both facets 5. Repeat 0,1,2 and checkout main + this patch, updatedatabase => ES search result display only the holding library facet Feel free to try with another value in DisplayLibraryFacets --- installer/data/mysql/db_revs/231200036.pl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/installer/data/mysql/db_revs/231200036.pl b/installer/data/mysql/db_revs/231200036.pl index 9d0ff1af82c..a5cd3d4c6ad 100755 --- a/installer/data/mysql/db_revs/231200036.pl +++ b/installer/data/mysql/db_revs/231200036.pl @@ -30,6 +30,8 @@ return { } $sth->execute( 'Collections', 'ccode', 'collection-code' ); + $sth->execute( 'Holding libraries', 'holdingbranch', 'holdinglibrary' ); + $sth->execute( 'Home libraries', 'homebranch', 'homelibrary' ); # Deal with DisplayLibraryFacets my ($DisplayLibraryFacets) = $dbh->selectrow_array( @@ -45,9 +47,24 @@ return { $holdingbranch = 1; } elsif ( $DisplayLibraryFacets eq 'home' ) { $homebranch = 1; + + } + my $faceted_search_field = $dbh->selectall_arrayref( + q{SELECT * FROM search_field WHERE facet_order IS NOT NULL ORDER BY facet_order}, + { Slice => {} } + ); + my $facet_order = 1; + $dbh->do(q{UPDATE search_field SET facet_order = NULL}); + for my $f (@$faceted_search_field) { + next + if $f->{name} eq 'homebranch' && !$homebranch; + next + if $f->{name} eq 'holdingbranch' && !$holdingbranch; + + $dbh->do( q{UPDATE search_field SET facet_order = ? WHERE name = ?}, undef, $facet_order, $f->{name} ); + + $facet_order++; } - $sth->execute( 'Holding libraries', 'holdingbranch', 'holdinglibrary' ) if $holdingbranch; - $sth->execute( 'Home libraries', 'homebranch', 'homelibrary' ) if $homebranch; say $out "Updated DisplayLibraryFacets and search field configuration"; }, -- 2.34.1